aboutsummaryrefslogtreecommitdiff
path: root/src/main.js
diff options
context:
space:
mode:
authorKaran Jayachandra <mail@karanjayachandra.com>2025-11-15 20:09:51 +0100
committerKaran Jayachandra <mail@karanjayachandra.com>2025-11-15 20:09:51 +0100
commit4ff9794fa2b545134efe341ad012667c67f70d15 (patch)
tree52675a68a49928cee6e13044f1e66309a30155ce /src/main.js
parent7cec8794b6616d294b6a0e8aab3b9d8b1dcdb6db (diff)
Added the changes to include the game counting
Diffstat (limited to 'src/main.js')
-rw-r--r--src/main.js28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/main.js b/src/main.js
index 6d8f35b..3732e51 100644
--- a/src/main.js
+++ b/src/main.js
@@ -19,14 +19,17 @@ export class GameManager extends Manager {
this.render();
addGameBehaviour(this);
}
- createItem(i, description) {
+ createItem(i, description, status) {
if (typeof description === "undefined") {
description = "---";
}
+ if (typeof status === "undefined") {
+ status = true;
+ }
let player = new Regular(null, null, null, null, description, "");
console.log(player);
let team = new Team(player, player);
- return new Game(i, true, team, team);
+ return new Game(i, status, team, team);
}
loadItem(data) {
let id = Number(data.id);
@@ -37,21 +40,22 @@ export class GameManager extends Manager {
}
addBehaviour() {
let confirmedStatus = this.data[0].status;
+
let description = confirmedStatus ? "Round " + this.round : "Proposal";
- document.getElementById("Game_description").innerHTML = description;
+ document.getElementById("Game-description").innerHTML = description;
}
addBlockedGames() {
const inactiveCourts = this.courts.inactive();
console.log("Total reserved courts are " + inactiveCourts.length + ".");
for (let court of inactiveCourts) {
- this.data.push(this.createItem(court.id, "RESERVED"));
+ this.data.push(this.createItem(court.id, "RESERVED", false));
}
}
addInactiveGames(possibleMatches) {
const activeCourts = this.courts.active();
const unusedCourts = activeCourts.slice(possibleMatches + 1);
for (let court of unusedCourts) {
- this.data.push(this.createItem(court.id));
+ this.data.push(this.createItem(court.id, "---", false));
}
}
addActiveGames(possibleMatches) {
@@ -92,7 +96,7 @@ export class GameManager extends Manager {
p.print();
});
const shuffledPlayers = shuffle(activePlayers);
- shuffledPlayers.sort((a, b) => a.totalPlayed - b.totalPlayed);
+ shuffledPlayers.sort((a, b) => a.games - b.games);
const selectedPlayers = shuffledPlayers.slice(0, count);
selectedPlayers.sort((a, b) => a.level - b.level);
console.log("Selected players are:");
@@ -128,6 +132,18 @@ export class GameManager extends Manager {
this.data[i].status = true;
}
// Increment the number of games played
+ let selectedPlayers = [];
+ for (let game of this.data) {
+ console.log(game);
+ if ( game.teamOne.playerOne.name !== "RESERVED" ){
+ selectedPlayers.push(game.teamOne.playerOne.name);
+ selectedPlayers.push(game.teamOne.playerTwo.name);
+ selectedPlayers.push(game.teamTwo.playerOne.name);
+ selectedPlayers.push(game.teamTwo.playerTwo.name);
+ }
+ }
+ this.regulars.incrementGames(selectedPlayers);
+ this.guests.incrementGames(selectedPlayers);
this.store();
this.render();
document.getElementById("timer-start").click();