From d23c38e6f2a972a49a5463cc866190e341e2685e Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Tue, 11 Nov 2025 19:08:58 +0100 Subject: Lot of updates and progress --- game.mjs | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'game.mjs') diff --git a/game.mjs b/game.mjs index 75c4906..d100096 100644 --- a/game.mjs +++ b/game.mjs @@ -1,38 +1,38 @@ import { getMatchCount, shuffle } from "./utils.mjs"; class Team { - constructor(player_1, player_2) { - this.player_1 = player_1; - this.player_2 = player_2; + constructor(playerOne, playerTwo) { + this.playerOne = playerOne; + this.playerTwo = playerTwo; } print() { - console.log(this.player_1 + " and " + this.player_2); + console.log(this.playerOne + " and " + this.playerTwo); } render() { - return `${this.player_1}${this.player_2}`; + return `${this.playerOne}${this.playerTwo}`; } } export class Game { constructor(court, team_1, team_2) { - this.court_id = court.id; - this.court_status = court.status; + this.courtId = court.id; this.team_1 = team_1; this.team_2 = team_2; } print() { - let team_1 = this.team_1.player_1 + " and " + this.team_1.player_2; - let team_2 = this.team_2.player_1 + " and " + this.team_2.player_2; + let team_1 = this.team_1.playerOne + " and " + this.team_1.playerTwo; + let team_2 = this.team_2.playerOne + " and " + this.team_2.playerTwo; console.log(team_1 + " is playing against " + team_2); } render() { - let type = this.team_1.player_1 === "RESERVED" ? `class="is-danger is-light"` : ``; - return `${this.court_id + 1}${this.team_1.render()}${this.team_2.render()}`; + let type = this.team_1.playerOne === "RESERVED" ? `class="is-danger is-dark"` : ``; + // type = this.team_1.playerOne === "---" ? `class="is-warning is-dark"` : ``; + return `${this.courtId + 1}${this.team_1.render()}${this.team_2.render()}`; } } -export function generateDummyGames(courts) { - let team = new Team("---", "---"); +export function generateDummyGames(courts, description) { + let team = new Team(description, description); let games = []; for (const court of courts ) { let game = new Game(court, team, team); @@ -42,13 +42,12 @@ export function generateDummyGames(courts) { } export class Round { - constructor(number, games) { - this.number = number; + constructor(games, number) { this.games = games; + this.description = typeof number === 'undefined' ? "Proposal" : "Round " + number; } - render(description) { - let heading = typeof description !== 'undefined' ? description : "Round " + this.number; - let output = `

${heading}

`; + render() { + let output = `
CourtTeam 1Team 2
`; for (const game of this.games ) { output += game.render() } @@ -76,7 +75,8 @@ export function proposeGames(players, courts) { console.log("Selected players are:"); console.log(selectedPlayers.map((i) => {return i.name;}).join(',')); console.log("The matches are:"); - let games = []; + let games = generateDummyGames(activeCourts.slice(possibleMatches + 1), "---"); + games = games.concat(generateDummyGames(inactiveCourts, "RESERVED")); for (let index = 0; index < possibleMatches; index++) { const startIndex = 4 * index; const endIndex = startIndex + 4; @@ -87,5 +87,6 @@ export function proposeGames(players, courts) { game.print(); games.push(game); } + games.sort((a, b) => a.courtId - b.courtId); return games; } \ No newline at end of file -- cgit v1.3.1
${this.description}
CourtTeam 1Team 2