File tree Expand file tree Collapse file tree 3 files changed +37
-18
lines changed Expand file tree Collapse file tree 3 files changed +37
-18
lines changed Original file line number Diff line number Diff line change 1
1
import { Cell } from "./cell" ;
2
2
import { Pawn } from "./pieces/pawn" ;
3
+ import maps from "./maps.txt?raw" ;
3
4
4
5
export class Board {
5
6
#cells: Cell [ ] [ ] = [ ] ;
@@ -10,16 +11,22 @@ export class Board {
10
11
11
12
constructor (
12
13
HTMLTable : HTMLTableElement ,
13
- template : string ,
14
+ mapName : string ,
14
15
onCellClick : ( clickedCell : Cell ) => void ,
15
16
onCastleClick : ( clickedCell : Cell ) => void ,
16
17
) {
18
+ const map = maps
19
+ . split ( "\n\n" )
20
+ . find ( ( s ) => s . startsWith ( mapName ) )
21
+ ?. replace ( / ^ .* \n / , "" )
22
+ ?. split ( "\n" )
23
+
24
+ if ( ! map ) {
25
+ throw new Error ( "there is no map with this name" ) ;
26
+ }
27
+
17
28
const HTMLBody = HTMLTable . createTBody ( ) ;
18
- template
19
- . replace ( / / g, "" )
20
- . split ( "\n" )
21
- . filter ( ( row ) => row . length > 0 )
22
- . forEach ( ( row , y ) => {
29
+ map . forEach ( ( row , y ) => {
23
30
const HTMLRow = HTMLBody . insertRow ( ) ;
24
31
this . #cells[ y ] = [ ] ;
25
32
for ( const symbol of row . split ( "" ) ) {
@@ -32,7 +39,7 @@ export class Board {
32
39
} ;
33
40
this . #cells[ y ] . push ( cell ) ;
34
41
35
- if ( symbol === "- " ) {
42
+ if ( symbol === ". " ) {
36
43
} else if ( symbol === "1" ) {
37
44
cell . placePiece ( new Pawn ( "white" ) , true ) ;
38
45
cell . setBuilding ( "castle" ) ;
Original file line number Diff line number Diff line change @@ -13,17 +13,7 @@ export class Game {
13
13
constructor ( HTMLTable : HTMLTableElement ) {
14
14
this . #board = new Board (
15
15
HTMLTable ,
16
- `
17
- ---------
18
- -1--c--c-
19
- ----w----
20
- ---w-----
21
- -cw-c-wc-
22
- -----w---
23
- ----w----
24
- -c--c--2-
25
- ---------
26
- ` ,
16
+ "canyon" ,
27
17
( clickedCell ) => {
28
18
// place piece
29
19
if ( this . #selectedCell?. piece ) {
Original file line number Diff line number Diff line change
1
+ canyon
2
+ .........
3
+ .1..c..c.
4
+ ....w....
5
+ ...w.....
6
+ .cw.c.wc.
7
+ .....w...
8
+ ....w....
9
+ .c..c..2.
10
+ .........
11
+
12
+ trenches
13
+ .........
14
+ .1..1..1.
15
+ .w..w..w.
16
+ .........
17
+ .........
18
+ .........
19
+ .........
20
+ .w..w..w.
21
+ .2..2..2.
22
+ .........
You can’t perform that action at this time.
0 commit comments