diff options
| author | Karan Jayachandra <karan.jayachandra@nxp.com> | 2025-11-11 19:08:58 +0100 |
|---|---|---|
| committer | Karan Jayachandra <karan.jayachandra@nxp.com> | 2025-11-11 19:08:58 +0100 |
| commit | d23c38e6f2a972a49a5463cc866190e341e2685e (patch) | |
| tree | 483301cbefa46c7a9e75d65d8ba634d8381a630a /game.mjs | |
| parent | 0e9e28c2595c1ec46d8601efa6f4d377ee70cb27 (diff) | |
Lot of updates and progress
Diffstat (limited to 'game.mjs')
| -rw-r--r-- | game.mjs | 39 |
1 files changed, 20 insertions, 19 deletions
@@ -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 `<td style="width: 23%;">${this.player_1}</td><td style="width: 23%;">${this.player_2}</td>`; + return `<td style="width: 23%;">${this.playerOne}</td><td style="width: 23%;">${this.playerTwo}</td>`; } } 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 `<tr ${type}><td align="center" style="width: 8%;">${this.court_id + 1}</td>${this.team_1.render()}${this.team_2.render()}</tr>`; + let type = this.team_1.playerOne === "RESERVED" ? `class="is-danger is-dark"` : ``; + // type = this.team_1.playerOne === "---" ? `class="is-warning is-dark"` : ``; + return `<tr ${type}><td align="center" style="width: 8%;">${this.courtId + 1}</td>${this.team_1.render()}${this.team_2.render()}</tr>`; } } -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 = `<h2 class="subtitle">${heading}</h3><table class="table is-fullwidth"><thead><tr><th align="center">Court</th><th align="center" colspan='2'>Team 1</th><th colspan='2' align="center">Team 2</th></tr></thead>`; + render() { + let output = `<table class="table is-fullwidth"><thead><th colspan='5'>${this.description}</th><tr><th align="center">Court</th><th align="center" colspan='2'>Team 1</th><th colspan='2' align="center">Team 2</th></tr></thead>`; 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 |
