1- import { Rectangle } from "../JSTools" ;
1+ import { Control , Rectangle } from "../JSTools" ;
2+
3+ const canvas = ( window as any ) . globals . canvas as HTMLCanvasElement ;
4+ const ctx = canvas . getContext ( "2d" ) as CanvasRenderingContext2D ;
25
36class Place extends Rectangle {
47 type : string ;
@@ -10,4 +13,71 @@ class Place extends Rectangle {
1013 }
1114}
1215
13- export { Place } ;
16+ class Board extends Control {
17+ width : number ;
18+ height : number ;
19+ places : Place [ ] ;
20+ constructor ( x : number , y : number ) {
21+ super ( x , y ) ;
22+ this . width = 980 ;
23+ this . height = 980 ;
24+ this . places = [ ] ;
25+
26+ // Width of the board path
27+ var pathWidth = 195 * canvas . height / 1000 ;
28+ // Width of normal places
29+ var normalPlacesWidth = ( this . width - pathWidth * 2 ) / 5 ;
30+
31+ for ( let i = 0 ; i < 24 ; i ++ ) { //Creating and Moving Places
32+ switch ( true ) { //Places are 100x195
33+ //Corner Places
34+ case ( i == 0 ) :
35+ this . places [ i ] = new Place ( this . width - pathWidth , this . height - pathWidth , pathWidth , pathWidth , "start" ) ;
36+ this . places [ i ] . color = "#FF793F" ;
37+ break ;
38+ case ( i == 6 ) :
39+ this . places [ i ] = new Place ( 0 , this . height - pathWidth , pathWidth , pathWidth , "prison_visit" ) ;
40+ this . places [ i ] . color = "#FF793F" ;
41+ break ;
42+ case ( i == 12 ) :
43+ this . places [ i ] = new Place ( 0 , 0 , pathWidth , pathWidth , "free_parking" ) ;
44+ this . places [ i ] . color = "#FF793F" ;
45+ break ;
46+ case ( i == 18 ) :
47+ this . places [ i ] = new Place ( this . width - pathWidth , 0 , pathWidth , pathWidth , "police" ) ;
48+ this . places [ i ] . color = "#FF793F" ;
49+ break ;
50+ //Normal Places
51+ case ( i >= 1 && i <= 5 ) :
52+ this . places [ i ] = new Place ( this . width - pathWidth - normalPlacesWidth * ( i % 6 ) , this . height - pathWidth , normalPlacesWidth , pathWidth , "normalA" + ( i % 6 ) ) ;
53+ this . places [ i ] . color = "#95CCF9" ;
54+ break ;
55+ case ( i >= 7 && i <= 11 ) :
56+ this . places [ i ] = new Place ( 0 , this . height - pathWidth - normalPlacesWidth * ( i % 6 ) , pathWidth , normalPlacesWidth , "normalB" + ( i % 6 ) ) ;
57+ this . places [ i ] . color = "#95CCF9" ;
58+ break ;
59+ case ( i >= 13 && i <= 17 ) :
60+ this . places [ i ] = new Place ( pathWidth + normalPlacesWidth * ( ( i % 6 ) - 1 ) , 0 , normalPlacesWidth , pathWidth , "normalC" + ( i % 6 ) ) ;
61+ this . places [ i ] . color = "#95CCF9" ;
62+ break ;
63+ case ( i >= 19 && i <= 23 ) :
64+ this . places [ i ] = new Place ( this . width - pathWidth , pathWidth + normalPlacesWidth * ( ( i % 6 ) - 1 ) , pathWidth , normalPlacesWidth , "normalD" + ( i % 6 ) ) ;
65+ this . places [ i ] . color = "#95CCF9" ;
66+ break ;
67+ }
68+ this . places [ i ] . showIndex = 50 ;
69+ this . places [ i ] . outlinePosition = "center" ;
70+ }
71+ }
72+
73+ draw ( ) : void {
74+ ctx . save ( ) ;
75+ ctx . translate ( this . x , this . y ) ;
76+ for ( let i = 0 ; i < this . places . length ; i ++ ) {
77+ this . places [ i ] . draw ( ) ;
78+ }
79+ ctx . restore ( ) ;
80+ }
81+ }
82+
83+ export { Place , Board } ;
0 commit comments