-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.ts
40 lines (31 loc) · 947 Bytes
/
Player.ts
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
class Player {
//name: string; //implicitly declared in ctor
hand: Array<Card> = new Array();
discard: Array<Card> = new Array();
deck: Array<Card> = new Array();
// how many actions the player has left this turn
actionsLeft = 0;
// how many coins the player has left to spend this turn
coinsLeft = 0;
constructor(public name: string) {
}
// ***** Public functions
drawCards(n: number) {
for (var i = 0; i < n; i++) {
this._drawCard();
}
}
// ***** Private helper functions
private _drawCard(): boolean {
if (this.deck.length == 0) {
this.deck = this.discard;
this.discard = new Array;
}
if (this.deck.length == 0) {
Utilities.Message("No cards left to draw!");
return false;
}
this.hand.push(Utilities.DrawRandomCard(this.deck));
return true;
}
}