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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
class Switch {
constructor(id, description, status) {
this.id = id;
this.status = typeof status !== "undefined" ? status : false;
this.description = description;
this.name = description + " " + (id + 1);
}
toggle() {
this.status = !this.status;
this.print();
}
print() {
let status = this.status ? "active" : "inactive";
console.log(this.name + " is currently " + status);
}
render() {
let color = this.status ? "is-success" : "is-danger";
let type = `class="button ${color}"`;
let id = this.description + "_" + this.id;
return `<button id=${id} ${type}>${this.name}</button>`;
}
}
export class Court extends Switch {
constructor(id, status) {
super(id, "Court", status);
}
}
export class Player extends Switch {
constructor(id, status, level, games, name) {
super(id, "Regular", status);
this.level = typeof level !== "undefined" ? level : 1;
this.games = typeof games !== "undefined" ? games : 0;
if (typeof name !== "undefined") {
this.name = name;
}
}
}
const guestCategories = {
0: { description: "Beginner", level: 1 },
1: { description: "Novice", level: 3 },
2: { description: "Intermediate", level: 6 },
};
export class Guest extends Switch {
maxCount = 6;
categoryCount = 3;
constructor(id, status, games) {
super(id, "Guest", status);
const categoryId = Math.floor(id / this.maxCount) || 0;
this.level = guestCategories[categoryId].level;
this.games = typeof games !== "undefined" ? games : 0;
const guestNumber = (id % this.maxCount) + 1;
this.name = guestCategories[categoryId].description + " " + guestNumber;
}
}
export class Team {
constructor(playerOne, playerTwo) {
this.playerOne = playerOne;
this.playerTwo = playerTwo;
}
print() {
console.log("Team consists of:");
this.playerOne.print();
this.playerTwo.print();
}
render() {
return `<div class="card">
<div class="card-content">
<div class="content">
<p class="subtitle is-6" style="word-wrap: break-word;">${this.playerOne}</p>
<p class="subtitle is-6" style="word-wrap: break-word;">${this.playerTwo}</p>
</div>
</div>
</div>`;
}
}
export class Game extends Switch {
constructor(id, status, teamOne, teamTwo) {
super(id, "Game", status);
this.teamOne = teamOne;
this.teamTwo = teamTwo;
}
print() {
let teamOne = this.teamOne.playerOne + " and " + this.teamOne.playerTwo;
let teamTwo = this.teamTwo.playerOne + " and " + this.teamTwo.playerTwo;
console.log(
"Game " + this.id + ": " + teamOne + " is playing against " + teamTwo
);
}
render() {
let blockedState = this.teamOne.playerOne === "RESERVED";
let placeHolder = `<p class="title is-3">Reserved</p>`
let type = blockedState ? placeHolder : this.teamOne.render() + this.teamTwo.render();
return `<div class="card">
<header class="card-header">
<p class="card-header-title">Court ${this.id + 1}</p>
</header>
<div class="card-content">
${type}
</div>
</div>`;
}
}
|