This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
59 lines (45 loc) · 1.47 KB
/
game.js
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
class Game {
constructor(id) {
this.gameID = id;
this.player1 = null;
this.player2 = null;
this.set_color = null;
this.guesses = [];
this.checks = [];
this.turn = 0;
this.state = "PREP";
}
addPlayer(ws) {
if(this.player1 === null) this.player1 = ws;
else if (this.player2 === null) this.player2 = ws;
else console.log("An error has ocurred, tried to add the player to a full game!")
}
getPlayerByID(id) {
if (this.player1.id == id) return 1;
else if (this.player2.id == id) return 2;
else console.log("NO PLAYER WITH SUCH ID IN GAME: CANNOT GET PLAYER BY ID");
}
removePlayer(number) {
if (number == 1) this.player1 == "removed";
else if (number == 2) this.player2 == "removed";
else console.log("NO PLAYER WITH SUCH NUMBER IN GAME: CANNOT REMOVE");
}
closePlayerSocket(number) {
if (number == 1) this.player1.close();
else if (number == 2) this.player2.close();
else console.log("NO PLAYER WITH SUCH NUMBER IN GAME: CANNOT CLOSE WEB SOCKET");
}
checkIfOnePlayerRemoved() {
return this.player1 == "removed" ^ this.player2 == "removed" ? true : false;
}
isFull() {
return this.player1 !== null && this.player2 !== null ? true : false;
}
delete() {
delete this;
}
setStatus(status) {
this.state = status;
}
}
module.exports = Game;