-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.js
76 lines (62 loc) · 1.18 KB
/
player.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var HiddenPlayer = require('./hiddenPlayer');
class Player {
constructor(socket, handle, cards, state) {
this.socket = socket;
this.handle = handle;
this.cards = cards;
this.state = state;
}
// Socket methods
get socket() {
return this._socket;
}
set socket(value) {
this._socket = value;
}
// Handle methods
get handle() {
return this._handle;
}
set handle(value) {
this._handle = value;
}
// Cards methods
get cards() {
return this._cards;
}
set cards(value) {
this._cards = value;
}
// Get number of cards in hand
numOfCards() {
return this.cards.length;
}
// Add a card to hand
drawCard(card) {
this.cards.push(card);
}
// Remove a card from hand
discardCard(card) {
let ind = this.cards.indexOf(card);
console.log("CARD IS AT " + ind);
if(ind == -1){
return ind;
}
this.cards.splice(ind, 1);
return ind;
}
// State methods
get state() {
return this._state;
}
set state(value) {
if(value !== "in" && value !== "invun" && value !== "out")
throw "Invalid Player State";
else
this._state = value;
}
getHidden() {
return new HiddenPlayer(this, undefined, undefined, undefined);
}
}
module.exports = Player;