aboutsummaryrefslogtreecommitdiff
path: root/game.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'game.mjs')
-rw-r--r--game.mjs39
1 files changed, 20 insertions, 19 deletions
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 `<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