-
Notifications
You must be signed in to change notification settings - Fork 61
/
CheckedPositionsArray.js
52 lines (41 loc) · 1.91 KB
/
CheckedPositionsArray.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class CheckedPositionsArray{
//an array which stores whether each position and rotation of a shape has already been checked for this matrix.
constructor(blockMatrix){
this.blockMatrix = blockMatrix;
this.checkedPositions = [];
this.checkedPositionShapes = [];
this.setAllPositionsToFalse();
}
getIndexOfCoordinates(x,y,r){
return x + this.blockMatrix.width * y + this.blockMatrix.width * this.blockMatrix.height * r;
}
setAllPositionsToFalse(){
this.checkedPositions = [];
for (let i = 0; i < this.blockMatrix.width * this.blockMatrix.height * 4; i++) {
this.checkedPositions.push(false);
this.checkedPositionShapes.push(null);
}
}
resetCheckedPositions(){
this.checkedPositions = [];
for (let i = 0; i < this.blockMatrix.width * this.blockMatrix.height * 4; i++) {
this.checkedPositions.push(false);
}
}
hasPositionBeenChecked(x, y, r) {
return this.checkedPositions[this.getIndexOfCoordinates(x,y,r)];
}
setCheckedPositionsArrayValue(x, y, r, value) {
this.checkedPositions[this.getIndexOfCoordinates(x,y,r)] = value;
}
hasShapesPositionBeenChecked(shape) {
return this.checkedPositions[this.getIndexOfCoordinates(shape.currentPos.x, shape.currentPos.y, shape.currentRotationCount % 4)];
}
getShapeFromPosition(shape) {
return this.checkedPositionShapes[this.getIndexOfCoordinates(shape.currentPos.x, shape.currentPos.y, shape.currentRotationCount % 4)];
}
setCheckedPositionsArrayValueAtShapesPosition(shape, value) {
this.checkedPositions[this.getIndexOfCoordinates(shape.currentPos.x, shape.currentPos.y, shape.currentRotationCount % 4)] = value;
// this.checkedPositionShapes[this.getIndexOfCoordinates(shape.currentPos.x, shape.currentPos.y, shape.currentRotationCount % 4)] = shape;
}
}