-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.js
More file actions
38 lines (34 loc) · 902 Bytes
/
Player.js
File metadata and controls
38 lines (34 loc) · 902 Bytes
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
import Board from './Board.js';
// All players have money
// All players are added and substructed money
export default class Player {
constructor (id, position) {
this.id = id;
this.roll_count = 0;
this.position = 0;
this.token;
}
/**
* Creates an element and appends it on the provided element
* @param {Object} tile - The element on which to place the player
*/
placeOnBoard (tile) {
this.token = document.createElement('span');
this.token.id = this.id;
tile.appendChild(this.token);
this.position = parseInt(tile.dataset.position) || 0;
}
/**
* Creates the number of players provided and set them on the board
*/
static setupPlayers (number) {
for(let i=0;i<number;i++) {
// add players
const player = new this('player' + i);
// set them to 'go'
player.placeOnBoard(Board.go);
// also add them player list
Board.addPlayer(player);
}
}
}