-
Notifications
You must be signed in to change notification settings - Fork 0
/
Square.js
37 lines (32 loc) · 842 Bytes
/
Square.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
class Square {
constructor(x, y, player, pieceType, pieceFlags, squareFlags) {
this.x = x;
this.y = y;
this.pieceFlags = pieceFlags;
this.pieceType = pieceType;
this.squareFlags = squareFlags;
this.player = player;
}
in_array(squares) {
if(typeof squares === "object" ) {
for(let i=0;i<squares.length;i++) {
if(squares[i].x === this.x && squares[i].y === this.y) {
return true;
} else {
continue;
}
}
}
return false;
}
isEmpty() {
return this.pieceType === null || this.pieceType === undefined || this.pieceType === "";
}
isOpponent(square) {
return !square.isEmpty() && this.player != square.player;
}
isSamePlayer(square) {
return !square.isEmpty() && this.player == square.player;
}
}
module.exports = Square;