-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.js
34 lines (31 loc) · 851 Bytes
/
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
class Player {
constructor(name, board, size) {
this.size = size;
this.name = name;
this.board = null;
this.head = null;
this.size = 3;
this.tail = [];
}
delHead() {
this.head = null;
}
setHeadLocation(square) {
this.head = square;
}
pickRandSquare() {
let square = this.board.fetchSquare(Utilities.randinteger(this.board.width),
Utilities.randinteger(this.board.height));
if (square.snakeHere == false) {
return square;
}
// shoddy solution
else {
while (square.snakeHere == true) {
square = this.board.fetchSquare(Utilities.randinteger(this.board.width),
Utilities.randinteger(this.board.height));
}
return square;
}
}
}