-
Notifications
You must be signed in to change notification settings - Fork 6
/
player.model.ts
42 lines (35 loc) · 1002 Bytes
/
player.model.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
41
42
import { MathRandomStringService } from '../../common/randomString.service';
import { IRandomStringService } from '../../common/randomStringService.interface';
import { IHand } from '../cardCollection/hand.interface';
import { Hand } from '../cardCollection/hand.model';
import { IPlayer } from './player.interface';
/**
* Represents a Player
*/
export class Player implements IPlayer {
public id: string;
public score: number = 0;
constructor (
public name: string = '',
private hand: IHand = new Hand(),
randomStringService: IRandomStringService = new MathRandomStringService()) {
this.id = randomStringService.get(7);
}
public updateScore (score: number): this {
this.score = score;
return this;
}
public getHand (): IHand {
return this.hand;
}
public setHand (hand: IHand): this {
this.hand = hand;
return this;
}
public toString (): string {
return `${this.name}`;
}
public getIndex (): string {
return this.id;
}
}