File tree Expand file tree Collapse file tree 2 files changed +29
-7
lines changed
Expand file tree Collapse file tree 2 files changed +29
-7
lines changed Original file line number Diff line number Diff line change 1+ import { Cell } from "~/Cell"
2+
13export class Board {
2- rows : number = 100
3- cols : number = 100
4- cellSize : number = 10
4+ _board : Cell [ ] [ ] = [ ]
5+ _rows : number = 100
6+ _cols : number = 100
57 ctx : CanvasRenderingContext2D
68
79 constructor ( ctx : CanvasRenderingContext2D ) {
810 this . ctx = ctx
911 }
12+ init ( ) {
13+ this . fillBoard ( )
14+ this . drawBoard ( )
15+ }
16+
17+ get board ( ) : Cell [ ] [ ] {
18+ return this . _board
19+ }
20+
21+ fillBoard ( ) {
22+ for ( let i = 0 ; i < this . _rows ; i ++ ) {
23+ this . _board [ i ] = [ ]
24+ for ( let j = 0 ; j < this . _cols ; j ++ ) {
25+ this . _board [ i ] [ j ] = new Cell ( i , j )
26+ }
27+ }
28+ }
1029
11- draw ( ) {
30+ drawBoard ( ) {
1231 this . ctx . beginPath ( )
13- this . ctx . rect ( 0 , 0 , this . rows * this . cellSize , this . cols * this . cellSize )
14- this . ctx . stroke ( )
32+ for ( let i = 0 ; i < this . _board . length ; i ++ ) {
33+ for ( let j = 0 ; j < this . _board [ i ] . length ; j ++ ) {
34+ this . _board [ i ] [ j ] . draw ( this . ctx )
35+ }
36+ }
1537 }
1638}
Original file line number Diff line number Diff line change @@ -15,5 +15,5 @@ if (container) {
1515 container . appendChild ( canvas )
1616
1717 const board = new Board ( ctx )
18- board . draw ( )
18+ board . init ( )
1919}
You can’t perform that action at this time.
0 commit comments