aboutsummaryrefslogtreecommitdiff
path: root/game.mjs
diff options
context:
space:
mode:
authorKaran Jayachandra <mail@karanjayachandra.com>2025-11-09 15:57:07 +0100
committerKaran Jayachandra <mail@karanjayachandra.com>2025-11-09 15:57:07 +0100
commit3dc01fbb930a4eacf416a9cc7911d90da75e6c33 (patch)
treedd25d62d619d62ed7d2657e37352caaa749abfd7 /game.mjs
parent6456fae865aae8b2ba398b5f78f2589c93d0643d (diff)
Moved a lot of the functionality
Diffstat (limited to 'game.mjs')
-rw-r--r--game.mjs47
1 files changed, 47 insertions, 0 deletions
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 `<td style="width: 23%;">${this.player_1}</td><td style="width: 23%;">${this.player_2}</td>`;
+ }
+}
+
+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 `<tr ${type}><td align="center" style="width: 8%;">${this.court_id + 1}</td>${this.team_1.render()}${this.team_2.render()}</tr>`;
+ }
+}
+
+export class Round {
+ constructor(number, courts) {
+ this.number = number;
+ this.courts = courts;
+ }
+ render() {
+ let output = `<h2 class="subtitle"> Round ${this.number} </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>`;
+ let team = new Team("---", "---");
+ for (const court of this.courts ) {
+ let game = new Game(court, team, team);
+ output += game.render()
+ }
+ output += "</table>";
+ return output;
+ }
+} \ No newline at end of file