rework with stats class
This commit is contained in:
parent
c22a3e6757
commit
1c4dfdad00
22
src/gst.ts
22
src/gst.ts
@ -1,8 +1,9 @@
|
|||||||
|
import { Stats } from "./statistics.js";
|
||||||
|
|
||||||
var cpuList;
|
var cpuList;
|
||||||
var currentCpu;
|
var currentCpu;
|
||||||
|
|
||||||
var score;
|
var stats: Stats;
|
||||||
var highScore;
|
|
||||||
|
|
||||||
export async function main() {
|
export async function main() {
|
||||||
// init cpu list
|
// init cpu list
|
||||||
@ -10,8 +11,8 @@ export async function main() {
|
|||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((json) => cpuList = json));
|
.then((json) => cpuList = json));
|
||||||
|
|
||||||
highScore = localStorage.getItem("highScore_socket") ?? 0
|
stats = new Stats("highScore_socket");
|
||||||
score = 0;
|
|
||||||
updateScores();
|
updateScores();
|
||||||
|
|
||||||
nextRound();
|
nextRound();
|
||||||
@ -89,14 +90,9 @@ export async function btnClick(typ) {
|
|||||||
|
|
||||||
// Score
|
// Score
|
||||||
if (btns[typ].style.backgroundColor == "lightgreen") {
|
if (btns[typ].style.backgroundColor == "lightgreen") {
|
||||||
score++;
|
stats.incrementScore();
|
||||||
} else {
|
} else {
|
||||||
score = 0;
|
stats.resetScore();
|
||||||
}
|
|
||||||
// Highscore
|
|
||||||
if (score > highScore) {
|
|
||||||
highScore = score;
|
|
||||||
localStorage.setItem("highScore_socket", highScore);
|
|
||||||
}
|
}
|
||||||
updateScores();
|
updateScores();
|
||||||
|
|
||||||
@ -111,8 +107,8 @@ export async function btnClick(typ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateScores() {
|
function updateScores() {
|
||||||
document.getElementById("score").innerText = score;
|
document.getElementById("score").innerText = stats.score.toString();
|
||||||
document.getElementById("highScore").innerText = highScore;
|
document.getElementById("highScore").innerText = stats.highScore.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRandomInt(min, max) {
|
function getRandomInt(min, max) {
|
||||||
|
Loading…
Reference in New Issue
Block a user