From 3dc01fbb930a4eacf416a9cc7911d90da75e6c33 Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Sun, 9 Nov 2025 15:57:07 +0100 Subject: Moved a lot of the functionality --- game.mjs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 game.mjs (limited to 'game.mjs') diff --git a/game.mjs b/game.mjs new file mode 100644 index 0000000..7b5d4c9 --- /dev/null +++ b/game.mjs @@ -0,0 +1,47 @@ +class Team { + constructor(player_1, player_2) { + this.player_1 = player_1; + this.player_2 = player_2; + } + print() { + console.log(this.player_1 + " and " + this.player_2); + } + render() { + return `${this.player_1}${this.player_2}`; + } +} + +class Game { + constructor(court, team_1, team_2) { + this.court_id = court.id; + this.court_status = court.status; + 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; + 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()}`; + } +} + +export class Round { + constructor(number, courts) { + this.number = number; + this.courts = courts; + } + render() { + let output = `

Round ${this.number}

`; + let team = new Team("---", "---"); + for (const court of this.courts ) { + let game = new Game(court, team, team); + output += game.render() + } + output += "
CourtTeam 1Team 2
"; + return output; + } +} \ No newline at end of file -- cgit v1.3.1