aboutsummaryrefslogtreecommitdiff
path: root/game.mjs
blob: 7b5d4c95ef1a46eb41a11abf80e021d10923cd9a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;
    }
}