-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.js
101 lines (87 loc) · 2.16 KB
/
board.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
class Board
{
constructor(rowSize,columnSize,emptyColor,sqSize)
{
this.rowSize = rowSize/sqSize;
this.columnSize = columnSize/sqSize;
this.emptyColor = emptyColor;
this.sqSize = sqSize;
this.board = [];
for(let r = 0; r < this.rowSize; r++)
{
this.board[r] = [];
for(let c = 0; c < this.columnSize; c++)
{
this.board[r][c] = this.emptyColor;
}
}
}
DrawGridOnBoard()
{
for(let r = 0; r < this.rowSize; r++)
{
for(let c = 0; c < this.columnSize; c++)
{
this.DrawSqaure(c,r, this.board[r][c]);
}
}
}
DrawSqaure(x,y,color)
{
ctx.fillStyle = color;
ctx.fillRect(x*this.sqSize,y*this.sqSize,this.sqSize,this.sqSize);
ctx.strokeStyle = "BLACK";
ctx.strokeRect(x*this.sqSize,y*this.sqSize,this.sqSize, this.sqSize);
}
}
class Stats
{
constructor(rowSize,columnSize,emptyColor,sqSize)
{
this.rowSize = rowSize/sqSize;
this.columnSize = columnSize/sqSize;
this.emptyColor = emptyColor;
this.sqSize = sqSize;
this.board = [];
for(let r = 0; r < this.rowSize; r++)
{
this.board[r] = [];
for(let c = 0; c < this.columnSize; c++)
{
this.board[r][c] = this.emptyColor;
}
}
}
DrawGridOnBoard()
{
for(let r = 0; r < this.rowSize; r++)
{
for(let c = 0; c < this.columnSize; c++)
{
this.DrawSqaure(c,r, this.board[r][c]);
}
}
}
DrawSqaure(x,y,color)
{
ctxMini.fillStyle = color;
ctxMini.fillRect(x*this.sqSize,y*this.sqSize,this.sqSize,this.sqSize);
ctxMini.strokeStyle = "BLACK";
ctxMini.strokeRect(x*this.sqSize,y*this.sqSize,this.sqSize, this.sqSize);
}
DrawPiece(piece)
{
let color = piece.tetrimino[1] ;
for(let r = 0; r < piece.tetrimino[0][piece.type].length; r++)
{
for(let c = 0; c < piece.tetrimino[0][piece.type].length; c++)
{
if(piece.tetrimino[0][piece.type][r][c] == 1)
{
//y has -1 as index, adding +1
this.DrawSqaure(piece.x+c, piece.y+r+1, color); //x is from left, means it's the column and y is from up means the row
}
}
}
}
}