-
Notifications
You must be signed in to change notification settings - Fork 1
/
board.js
1761 lines (1501 loc) · 96.8 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Game board object - methods to initialise board and array to store current state of board
let gameBoard = {
// Array to store current state of board
// -------------------------------------
boardArray: [],
// Method to initialise boardArray
// -------------------------------
// Row and col give size of board - boardShape gives shape of board
populateBoardArray: function(row, col, boardShape) {
// Blank board array to re-initialise
this.boardArray = [];
// Create array of objects - square array of y rows of x tiles
for (var y = 0; y < col; y++) {
let rowArray = [];
for (var x = 0; x < row; x++) {
// A few random land tiles
if(Math.random() > 0.995) {
rowArray.push({xpos: + x, ypos: + y, terrain: 'land', subTerrain: 'none', activeStatus: 'inactive', pieces: {populatedSquare: false, category: '', type: 'no piece', direction: '', used: 'unused', damageStatus: 5, team: '', goods: 'none', stock: 0, production: 0}});
// But mainly sea tiles
} else {
rowArray.push({xpos: + x, ypos: + y, terrain: 'sea', subTerrain: 'none', activeStatus: 'inactive', pieces: {populatedSquare: false, category: '', type: 'no piece', direction: '', used: 'unused', damageStatus: 5, team: '', goods: 'none', stock: 0, production: 0}});
}
}
this.boardArray.push(rowArray);
}
},
// Method to overlay islands and bases and pieces
// ----------------------------------------------
// Much of this overlay code could be removed and replaced by a fixed array at a later date
// But currently it is useful to allow the board to be set dynamically in different sizes
// whilst game play is being developed
overlayBoardArray: function(row, col, boardShape) {
let boardCenter = Math.round((row-1)/2);
let octagonCorner = (row-1)/3;
// A octagon shaped board is obtained by making triangles of tiles invisible in the corners
if (boardShape == 'octagon') {
this.overlayTilesTri(0, 0, octagonCorner, 'TL', 'invis');
this.overlayTilesTri(0, col-octagonCorner, octagonCorner, 'TR', 'invis');
this.overlayTilesTri(row-octagonCorner, 0, octagonCorner, 'BL', 'invis');
this.overlayTilesTri(row-octagonCorner, col-octagonCorner, octagonCorner, 'BR', 'invis');
}
// Creation of triangle-shaped islands
this.overlayTiles((row-1)/3-3, (row-1)/3+1, (col-1)/3-3, (col-1)/3+1, 'sea');
this.overlayTilesTri((row-1)/3-2, (col-1)/3-2, 3, 'BR', 'land');
this.boardArray[(row-1)/3][(col-1)/3-1].terrain = 'sea';
this.boardArray[(row-1)/3-1][(col-1)/3].terrain = 'sea';
this.boardArray[(row-1)/3][(col-1)/3].pieces = {populatedSquare: true, category: 'Resources', type: 'desert', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0};
this.boardArray[(row-1)/3-2][(col-1)/3].pieces = {populatedSquare: true, category: 'Resources', type: 'desert', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0};
this.boardArray[(row-1)/3][(col-1)/3-2].pieces = {populatedSquare: true, category: 'Resources', type: 'desert', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0};
this.overlayTiles(2*((row-1)/3)-1, 2*((row-1)/3)+3, 2*((col-1)/3)-1, 2*((col-1)/3)+3, 'sea');
this.overlayTilesTri(2*((row-1)/3), 2*((col-1)/3), 3, 'TL', 'land');
this.boardArray[2*((row-1)/3)+1][2*((col-1)/3)].terrain = 'sea';
this.boardArray[2*((row-1)/3)][2*((col-1)/3)+1].terrain = 'sea';
this.boardArray[2*((row-1)/3)][2*((col-1)/3)].pieces = {populatedSquare: true, category: 'Resources', type: 'desert', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0};
this.boardArray[2*((row-1)/3)+2][2*((col-1)/3)].pieces = {populatedSquare: true, category: 'Resources', type: 'desert', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0};
this.boardArray[2*((row-1)/3)][2*((col-1)/3)+2].pieces = {populatedSquare: true, category: 'Resources', type: 'desert', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0};
this.overlayTiles((row-1)/3-3, (row-1)/3+1, 2*((col-1)/3)-1, 2*((col-1)/3)+3, 'sea');
this.overlayTilesTri((row-1)/3-2, 2*((row-1)/3), 3, 'BL', 'land');
this.boardArray[(row-1)/3-1][2*((col-1)/3)].terrain = 'sea';
this.boardArray[(row-1)/3][2*((col-1)/3)+1].terrain = 'sea';
this.boardArray[(row-1)/3-2][2*((row-1)/3)].pieces = {populatedSquare: true, category: 'Resources', type: 'desert', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0};
this.boardArray[(row-1)/3][2*((row-1)/3)].pieces = {populatedSquare: true, category: 'Resources', type: 'desert', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0};
this.boardArray[(row-1)/3][2*((row-1)/3)+2].pieces = {populatedSquare: true, category: 'Resources', type: 'desert', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0};
this.overlayTiles(2*((row-1)/3)-1, 2*((row-1)/3)+3, (row-1)/3-3, (row-1)/3+1, 'sea');
this.overlayTilesTri(2*((row-1)/3), (row-1)/3-2, 3, 'TR', 'land');
this.boardArray[2*((row-1)/3)][(row-1)/3-1].terrain = 'sea';
this.boardArray[2*((row-1)/3)+1][(row-1)/3].terrain = 'sea';
this.boardArray[2*((row-1)/3)][(row-1)/3-2].pieces = {populatedSquare: true, category: 'Resources', type: 'desert', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0};
this.boardArray[2*((row-1)/3)][(row-1)/3].pieces = {populatedSquare: true, category: 'Resources', type: 'desert', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0};
this.boardArray[2*((row-1)/3)+2][(row-1)/3].pieces = {populatedSquare: true, category: 'Resources', type: 'desert', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0};
// Creation of outlying islands
this.boardArray[(row-1)/3][2].terrain = 'land';
this.boardArray[2][(col-1)/3].terrain = 'land';
this.boardArray[4][6].terrain = 'land';
this.boardArray[6][4].terrain = 'land';
this.boardArray[5][6].terrain = 'sea';
this.boardArray[6][5].terrain = 'sea';
this.boardArray[row-3][2*((col-1)/3)].terrain = 'land';
this.boardArray[2*((row-1)/3)][col-3].terrain = 'land';
this.boardArray[row-7][col-5].terrain = 'land';
this.boardArray[row-5][col-7].terrain = 'land';
this.boardArray[row-6][col-7].terrain = 'sea';
this.boardArray[row-7][col-6].terrain = 'sea';
this.boardArray[2][2*((col-1)/3)].terrain = 'land';
this.boardArray[(row-1)/3][col-3].terrain = 'land';
this.boardArray[row-7][4].terrain = 'land';
this.boardArray[row-7][5].terrain = 'sea';
this.boardArray[row-5][6].terrain = 'land';
this.boardArray[row-6][6].terrain = 'sea';
this.boardArray[2*((row-1)/3)][2].terrain = 'land';
this.boardArray[row-3][(col-1)/3].terrain = 'land';
this.boardArray[4][col-7].terrain = 'land';
this.boardArray[6][col-5].terrain = 'land';
this.boardArray[6][col-6].terrain = 'sea';
this.boardArray[5][col-7].terrain = 'sea';
// Creation of central volcanic shaped island for trading post
this.overlayTiles(boardCenter-1, boardCenter+1, boardCenter-1, boardCenter+1, 'land');
this.boardArray[boardCenter-1][boardCenter+1].terrain = 'sea';
this.boardArray[boardCenter-1][boardCenter-1].terrain = 'sea';
this.boardArray[boardCenter+1][boardCenter+1].terrain = 'sea';
this.boardArray[boardCenter+1][boardCenter-1].terrain = 'sea';
// Inner circle of islands
this.boardArray[boardCenter][boardCenter+4].terrain = 'land';
this.boardArray[boardCenter][boardCenter-4].terrain = 'land';
this.boardArray[boardCenter+4][boardCenter].terrain = 'land';
this.boardArray[boardCenter-4][boardCenter].terrain = 'land';
this.boardArray[boardCenter-3][boardCenter-3].terrain = 'land';
this.boardArray[boardCenter+3][boardCenter+3].terrain = 'land';
this.boardArray[boardCenter-3][boardCenter+3].terrain = 'land';
this.boardArray[boardCenter+3][boardCenter-3].terrain = 'land';
// Creation of bay shaped islands
this.overlayTiles(boardCenter-1, boardCenter+1, 2*((row-1)/3)+4, 2*((row-1)/3)+4, 'land');
//this.overlayTiles(boardCenter-1, boardCenter+1, 2*((row-1)/3)+3, 2*((row-1)/3)+4, 'land');
//this.boardArray[boardCenter][2*((row-1)/3)+3].terrain = 'sea';
this.overlayTiles(boardCenter-1, boardCenter+1, (row-1)/3-4, (row-1)/3-4, 'land');
//this.overlayTiles(boardCenter-1, boardCenter+1, (row-1)/3-4, (row-1)/3-3, 'land');
//this.boardArray[boardCenter][(row-1)/3-3].terrain = 'sea';
this.overlayTiles(2*((row-1)/3)+4, 2*((row-1)/3)+4, boardCenter-1, boardCenter+1, 'land');
//this.overlayTiles(2*((row-1)/3)+3, 2*((row-1)/3)+4, boardCenter-1, boardCenter+1, 'land');
//this.boardArray[2*((row-1)/3)+3][boardCenter].terrain = 'sea';
this.overlayTiles((row-1)/3-4, (row-1)/3-4, boardCenter-1, boardCenter+1, 'land');
//this.overlayTiles((row-1)/3-4, (row-1)/3-3, boardCenter-1, boardCenter+1, 'land');
//this.boardArray[(row-1)/3-3][boardCenter].terrain = 'sea';
// Creation of land around bases
this.overlayTiles(row-3, row-1, boardCenter-2, boardCenter+2, 'sea');
this.overlayTiles(row-1, row-1, boardCenter, boardCenter, 'land');
this.overlayTiles(0, 2, boardCenter-2, boardCenter+2, 'sea');
this.overlayTiles(0, 0, boardCenter, boardCenter, 'land');
this.overlayTiles(boardCenter-2, boardCenter+2, col-3, col-1, 'sea');
this.overlayTiles(boardCenter, boardCenter, col-1, col-1, 'land');
this.overlayTiles(boardCenter-2, boardCenter+2, 0, 2, 'sea');
this.overlayTiles(boardCenter, boardCenter, 0, 0, 'land');
// Creation of forts
this.boardArray[boardCenter][col-1].pieces = {populatedSquare: true, category: 'Settlements', type: 'fort', direction: '270', used: 'unused', damageStatus: 5, team: 'Orange Team', goods: 'none', stock: 0, production: 0};
this.boardArray[0][boardCenter].pieces = {populatedSquare: true, category: 'Settlements', type: 'fort', direction: '180', used: 'unused', damageStatus: 5, team: 'Red Team', goods: 'none', stock: 0, production: 0};
this.boardArray[row-1][boardCenter].pieces = {populatedSquare: true, category: 'Settlements', type: 'fort', direction: '0', used: 'unused', damageStatus: 5, team: 'Green Team', goods: 'none', stock: 0, production: 0};
this.boardArray[boardCenter][0].pieces = {populatedSquare: true, category: 'Settlements', type: 'fort', direction: '90', used: 'unused', damageStatus: 5, team: 'Blue Team', goods: 'none', stock: 0, production: 0};
// Creation of Kingdom forts
this.boardArray[boardCenter][boardCenter].pieces = {populatedSquare: true, category: 'Settlements', type: 'fort', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0, production: 0};
this.boardArray[9][9].pieces = {populatedSquare: true, category: 'Settlements', type: 'fort', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0, production: 0};
tradeContracts.contractsArray[0].row = 9;
tradeContracts.contractsArray[0].col = 9;
this.boardArray[9][col-10].pieces = {populatedSquare: true, category: 'Settlements', type: 'fort', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0, production: 0};
tradeContracts.contractsArray[1].row = 9;
tradeContracts.contractsArray[1].col = col-10;
this.boardArray[row-10][9].pieces = {populatedSquare: true, category: 'Settlements', type: 'fort', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0, production: 0};
tradeContracts.contractsArray[3].row = row-10;
tradeContracts.contractsArray[3].col = 9;
this.boardArray[row-10][col-10].pieces = {populatedSquare: true, category: 'Settlements', type: 'fort', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'none', stock: 0, production: 0};
tradeContracts.contractsArray[2].row = row-10;
tradeContracts.contractsArray[2].col = col-10;
// Creation of ships
this.boardArray[boardCenter-1][col-1].pieces = {populatedSquare: true, category: 'Transport', type: 'catamaran', direction: '-90', used: 'unused', damageStatus: 5, team: 'Orange Team', goods: 'none', stock: 0, production: 0, homeRow: boardCenter-1, homeCol: col-1};
//this.boardArray[boardCenter+1][col-1].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '-90', used: 'unused', damageStatus: 5, team: 'Orange Team', goods: 'none', stock: 0, production: 0, homeRow: boardCenter+1, homeCol: col-1};
this.boardArray[0][boardCenter-1].pieces = {populatedSquare: true, category: 'Transport', type: 'catamaran', direction: '180', used: 'unused', damageStatus: 5, team: 'Red Team', goods: 'none', stock: 0, production: 0, homeRow: 0, homeCol: boardCenter-1};
//this.boardArray[0][boardCenter+1].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '180', used: 'unused', damageStatus: 5, team: 'Red Team', goods: 'none', stock: 0, production: 0, homeRow: 0, homeCol: boardCenter+1};
//this.boardArray[row-1][boardCenter-1].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '0', used: 'unused', damageStatus: 5, team: 'Green Team', goods: 'none', stock: 0, production: 0, homeRow: row-1, homeCol: boardCenter-1};
this.boardArray[row-1][boardCenter+1].pieces = {populatedSquare: true, category: 'Transport', type: 'catamaran', direction: '0', used: 'unused', damageStatus: 5, team: 'Green Team', goods: 'none', stock: 0, production: 0, homeRow: row-1, homeCol: boardCenter+1};
//this.boardArray[row-2][boardCenter].pieces = {populatedSquare: true, category: 'Transport', type: 'warship', direction: '0', used: 'unused', damageStatus: 5, team: 'Green Team', goods: 'none', stock: 0, production: 0, homeRow: row-1, homeCol: boardCenter+1};
//this.boardArray[boardCenter-1][0].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '90', used: 'unused', damageStatus: 5, team: 'Blue Team', goods: 'none', stock: 0, production: 0, homeRow: boardCenter-1, homeCol: 0};
this.boardArray[boardCenter+1][0].pieces = {populatedSquare: true, category: 'Transport', type: 'catamaran', direction: '90', used: 'unused', damageStatus: 5, team: 'Blue Team', goods: 'none', stock: 0, production: 0, homeRow: boardCenter+1, homeCol: 0};
// Creation of pirate ships and pirate harbours
this.boardArray[5][5] = {xpos: 5, ypos: 5, terrain: 'sea', subTerrain: 'pirateHarbour', activeStatus: 'inactive', pieces: {populatedSquare: true, category: 'Transport', type: 'warship', direction: '135', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0, ref: 0}};
//this.boardArray[4][6].terrain = 'sea';
//this.boardArray[4][6].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '135', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0};
this.boardArray[row-6][5] = {xpos: row-6, ypos: 5, terrain: 'sea', subTerrain: 'pirateHarbour', activeStatus: 'inactive', pieces: {populatedSquare: true, category: 'Transport', type: 'warship', direction: '45', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0, ref: 1}};
//this.boardArray[row-7][4].terrain = 'sea';
//this.boardArray[row-7][4].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '45', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0};
this.boardArray[row-6][col-6] = {xpos: row-5, ypos: col-7, terrain: 'sea', subTerrain: 'pirateHarbour', activeStatus: 'inactive', pieces: {populatedSquare: true, category: 'Transport', type: 'warship', direction: '-45', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0, ref: 2}};
//this.boardArray[row-5][col-7].terrain = 'sea';
//this.boardArray[row-5][col-7].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '-45', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0};
this.boardArray[5][col-6] = {xpos: 6, ypos: col-5, terrain: 'sea', subTerrain: 'pirateHarbour', activeStatus: 'inactive', pieces: {populatedSquare: true, category: 'Transport', type: 'warship', direction: '-135', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0, ref: 3}};
//this.boardArray[6][col-5].terrain = 'sea';
//this.boardArray[6][col-5].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '-135', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0};
// Creation of forests
this.boardArray[boardCenter-1][boardCenter].pieces = {populatedSquare: true, category: 'Resources', type: 'forest', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'wood', stock: 0, production: 2};
// Creation of ironworks
this.boardArray[boardCenter+1][boardCenter].pieces = {populatedSquare: true, category: 'Resources', type: 'ironworks', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'iron', stock: 0, production: 2};
// Creation of quarry
this.boardArray[boardCenter][boardCenter-1].pieces = {populatedSquare: true, category: 'Resources', type: 'quarry', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'stone', stock: 0, production: 2};
// Creation of plantation
this.boardArray[boardCenter][boardCenter+1].pieces = {populatedSquare: true, category: 'Resources', type: 'plantation', direction: '0', used: 'unused', damageStatus: 5, team: 'Kingdom', goods: 'coffee', stock: 0, production: 2};
/* // TEST AREA
// Clay
this.boardArray[row-3][boardCenter+1] = {xpos: row-3, ypos: boardCenter+1, terrain: 'land', subTerrain: 'none', activeStatus: 'inactive', pieces: {populatedSquare: true, category: 'Resources', type: 'clay', direction: '0', used: 'unused', damageStatus: 5, team: 'Unclaimed', goods: 'pottery', stock: 18, production: 1}};
// Flax
//this.boardArray[row-3][boardCenter] = {xpos: row-3, ypos: boardCenter, terrain: 'land', subTerrain: 'none', activeStatus: 'inactive', pieces: {populatedSquare: true, category: 'Resources', type: 'flax', direction: '0', used: 'unused', damageStatus: 5, team: 'Unclaimed', goods: 'cloth', stock: 18, production: 1}};
// Battle Royale
this.boardArray[row-4][boardCenter].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '45', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0};
this.boardArray[row-4][boardCenter + 1].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '45', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0};
this.boardArray[row-4][boardCenter - 1].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '45', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0};
this.boardArray[row-5][boardCenter + 1].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '45', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0};
this.boardArray[row-5][boardCenter].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '45', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0};
this.boardArray[row-5][boardCenter -1].pieces = {populatedSquare: true, category: 'Transport', type: 'cargo ship', direction: '45', used: 'unused', damageStatus: 5, team: 'Pirate', goods: 'none', stock: 0};
//*/
},
// Method to allocate start tiles to teams
// ---------------------------------------
// Order needs to be (1) creation of board (2) Counting of empty tiles and creation of resource deck (3) Allocation of tiles from resource deck to team bases
allocateStartTiles: function() {
let boardCenter = Math.round((row-1)/2);
let allocateArray = [ {i: boardCenter+1, j: col-1, team: 'Orange Team'},
{i: 0, j: boardCenter+1, team: 'Red Team'},
{i: row-1, j: boardCenter-1, team: 'Green Team'},
{i: boardCenter-1, j: 0, team: 'Blue Team'},
{i: boardCenter-1, j: col-1, team: 'Orange Team'},
{i: 0, j: boardCenter-1, team: 'Red Team'},
{i: row-1, j: boardCenter+1, team: 'Green Team'},
{i: boardCenter+1, j: 0, team: 'Blue Team'}]
// function picks a tile form the resource deck and checks player does not already have this Resource allocated
function completeAllocatedTile(locali, localj, localTeam) {
stockDashboard.stockTake();
//keep for debugging - console.log(stockDashboard.pieceTotals);
let pieceTotalsTeamPosition = stockDashboard.pieceTotals.findIndex(fI => fI.team == localTeam);
do {
var deckCard = resourceManagement.pickFromResourceDeck();
//keep for debugging - console.log(deckCard.type);
}
while (stockDashboard.pieceTotals[pieceTotalsTeamPosition].pieces[deckCard.type].quantity > 0)
gameBoard.boardArray[locali][localj].pieces = {populatedSquare: true, category: 'Resources', type: deckCard.type, direction: '0', used: 'unused', damageStatus: 5, team: localTeam, goods: deckCard.goods, stock: 0};
}
for (var k = 0; k < allocateArray.length; k++) {
//keep for debugging - console.log(k, allocateArray[k].team);
completeAllocatedTile(allocateArray[k].i, allocateArray[k].j, allocateArray[k].team)
}
},
// Method to create triangle shaped overlay
// ----------------------------------------
// allows specification of size, position and terrain of tiles
// TR = top right, BL = bottom left (for right angled corner)
overlayTilesTri: function(startRow, startCol, size, corner, overlayTerrain) {
for (i = startRow; i < startRow + size; i+=1) {
if (corner == "TL") {
for (j = startCol; j < startCol + size - (i - startRow); j+=1) {
this.boardArray[i][j].terrain = overlayTerrain;
}
} else if (corner == "BL") {
for (j = startCol; j < startCol + (i - startRow) + 1; j+=1) {
this.boardArray[i][j].terrain = overlayTerrain;
}
} else if (corner == 'TR') {
for (j = startCol + (i - startRow); j < startCol + size; j+=1) {
this.boardArray[i][j].terrain = overlayTerrain;
}
} else if (corner == 'BR') {
for (j = startCol + size - (i - startRow) -1; j < startCol + size; j+=1) {
this.boardArray[i][j].terrain = overlayTerrain;
}
} else {
console.log('overlayTilesTri - triangle type not found');
}
}
},
// Method to create rectangular shaped overlay
// -------------------------------------------
// allows specification of size, position and terrain of tiles
overlayTiles: function(startRow, endRow, startCol, endCol, overlayTerrain) {
for (i = startRow; i <= endRow; i++) {
for (j = startCol; j <= endCol; j++) {
this.boardArray[i][j].terrain = overlayTerrain;
}
}
},
// Method to create a single tile
// ------------------------------
// gridSize is the size of the tile, squareType is the land / sea / base of the tile
createTile: function(i, j, gridSize) {
// Creating the tile from three nested divs
let newTile = document.createElement('div');
let innerTile = document.createElement('div');
let rotatedTile = document.createElement('div');
// Adding an id for each tile - DECIDE IF NECESSARY IN NEXT STAGE
newTile.id = i*1000 + j;
// Creating the tile by dynamically allocating CSS classes
// Tile size is set as a parameter but has functionality to be varied dynamically
// (e.g. to zoom in or out of board map)
newTile.setAttribute('class', 'square' + ' ' + this.boardArray[i][j].terrain + ' ' + this.boardArray[i][j].activeStatus);
newTile.style.height = (gridSize - 2) + 'px';
newTile.style.width = (gridSize - 2) + 'px';
rotatedTile.setAttribute('class', 'rotated_square' + ' ' + this.boardArray[i][j].terrain + ' ' + this.boardArray[i][j].activeStatus);
rotatedTile.style.height = (gridSize - 6) + 'px';
rotatedTile.style.width = (gridSize - 6) + 'px';
innerTile.setAttribute('class', 'inner_square' + ' ' + this.boardArray[i][j].terrain + ' ' + this.boardArray[i][j].activeStatus);
innerTile.style.height = (gridSize - 6) + 'px';
innerTile.style.width = (gridSize - 6) + 'px';
newTile.appendChild(rotatedTile);
rotatedTile.appendChild(innerTile);
// tile is returned to drawBoard
return newTile;
},
// Method to create a single action tile
// -------------------------------------
// tileSize is the size of the tile
createActionTile: function(locali, localj, localType, localTeam, localID, localTop, localLeft, localScale, localRotation) {
let viewportSize = 25 * localScale;
// Create SVG tile of designated height and width
let actionTile = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
actionTile.setAttribute('width', gridSize + tileBorder);
actionTile.setAttribute('height', gridSize + tileBorder);
// Position tile based on coordinates passed from boardArray
actionTile.style.top = localTop + 'px';
actionTile.style.left = localLeft + 'px';
actionTile.style.transform = 'rotate(' + localRotation + 'deg)';
// Set view size, class and id
actionTile.setAttribute('viewBox', '0, 0, ' + viewportSize + ' ' + viewportSize);
actionTile.setAttribute('id', localID);
//actionTile.setAttribute('transform', 'scale(2)');
actionTile.setAttribute('class', localType);
if (localType == 'cargo ship') {
this.createCargoTile(actionTile, localTeam, 5);
} else if (localType == 'warship') {
this.createWarshipTile(actionTile, localTeam, 5);
} else if (localType == 'catamaran') {
this.createCatamaranTile(actionTile, localTeam, 5);
} else if (localType == 'fort') {
this.createFortTile(actionTile, localTeam);
} else if (localType == 'forest') {
this.createForestTile(actionTile, localTeam);
} else if (localType == 'ironworks') {
this.createIronworksTile(actionTile, localTeam);
} else if (localType == 'quarry') {
this.createQuarryTile(actionTile, localTeam);
} else if (localType == 'desert') {
this.createDesertTile(actionTile, localTeam);
} else if (localType == 'plantation') {
this.createPlantationTile(actionTile, localTeam);
} else if (localType == 'flax') {
this.createFlaxTile(actionTile, localTeam);
} else if (localType == 'clay') {
this.createClayTile(actionTile, localTeam);
}
// tile is returned to drawBoard
return actionTile;
},
// Method to create a single goods icon
// -------------------------------------
createIcon: function(localID, localScale, localGoods, localLeft, localTop) {
let viewportSize = 25 * localScale;
// Create SVG tile of designated height and width
let goodsIcon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
goodsIcon.setAttribute('width', gridSize + tileBorder);
goodsIcon.setAttribute('height', gridSize + tileBorder);
goodsIcon.style.left = localLeft + 'px';
goodsIcon.style.top = localTop + 'px';
// Set view size, class and id
goodsIcon.setAttribute('viewBox', '0, 0, ' + viewportSize + ' ' + viewportSize);
goodsIcon.setAttribute('id', localID);
goodsIcon.setAttribute('class', 'goodsGroup');
// icon method is selected
if (localGoods == 'coffee') {
this.createCoffeeIcon(goodsIcon);
} else if (localGoods == 'stone') {
this.createStoneIcon(goodsIcon);
} else if (localGoods == 'iron') {
this.createIronIcon(goodsIcon);
} else if (localGoods == 'wood') {
this.createWoodIcon(goodsIcon);
} else if (localGoods == 'cloth') {
this.createClothIcon(goodsIcon);
} else if (localGoods == 'pottery') {
this.createPotteryIcon(goodsIcon);
}
// tile is returned to drawBoard
return goodsIcon;
},
// Method to create cargo tile
// ---------------------------
createCargoTile: function(actionTile, localTeam, localDamage) {
// Removes all elements of SVG for damage / repair building
while (actionTile.lastChild) {
actionTile.removeChild(actionTile.lastChild);
}
// Cargo ship deck SVG design
let cargoDeck = document.createElementNS('http://www.w3.org/2000/svg', 'path');
cargoDeck.setAttribute('class', localTeam + ' team_fill team_stroke');
cargoDeck.setAttribute('d', 'M 12.5 1 C 8 6.2 7 11.1 7.3 15.6 Q 7.7 20.2 9.25 24 L 15.75 24 Q 17 20.2 17.5 15.6 C 17.8 11.1 16.6 6.2 12.5 1 Z');
cargoDeck.style.strokeWidth = '1px';
actionTile.appendChild(cargoDeck);
if (localDamage >= 2) {
// Cargo ship mast SVG design
let cargoMast = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
cargoMast.setAttribute('class', localTeam + ' team_stroke');
cargoMast.setAttribute('cx', '12.5');
cargoMast.setAttribute('cy', '12');
cargoMast.setAttribute('r', '1');
cargoMast.style.strokeWidth = '1px';
cargoMast.style.strokeLinecap = 'round';
actionTile.appendChild(cargoMast);
}
if (localDamage >= 3) {
// Cargo ship mast SVG design
let cargoMast2 = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
cargoMast2.setAttribute('class', localTeam + ' team_stroke');
cargoMast2.setAttribute('cx', '12.5');
cargoMast2.setAttribute('cy', '20');
cargoMast2.setAttribute('r', '1');
cargoMast2.style.strokeWidth = '1px';
cargoMast2.style.strokeLinecap = 'round';
actionTile.appendChild(cargoMast2);
}
if (localDamage >= 4) {
// Cargo ship sail SVG design
let cargoSail = document.createElementNS('http://www.w3.org/2000/svg', 'path');
cargoSail.setAttribute('d', 'M 2 11 L 23 11 C 20.5 8.5 16.5 7 12.5 7 C 7.5 7 3.5 8.5 2 11 Z');
cargoSail.setAttribute('class', localTeam + ' team_stroke');
cargoSail.setAttribute('fill', 'white');
cargoSail.style.strokeWidth = '1px';
actionTile.appendChild(cargoSail);
}
if (localDamage >= 5) {
// Cargo ship sail SVG design
let cargoSail2 = document.createElementNS('http://www.w3.org/2000/svg', 'path');
cargoSail2.setAttribute('d', 'M 2 19 L 23 19 C 20.5 16.5 16.5 15 12.5 15 C 7.5 15 3.5 16.5 2 19 Z');
cargoSail2.setAttribute('class', localTeam + ' team_stroke');
cargoSail2.setAttribute('fill', 'white');
cargoSail2.style.strokeWidth = '1px';
actionTile.appendChild(cargoSail2);
}
return actionTile;
},
// Method to create warship tile
// ---------------------------
createWarshipTile: function(actionTile, localTeam, localDamage) {
// Removes all elements of SVG for damage / repair building
while (actionTile.lastChild) {
actionTile.removeChild(actionTile.lastChild);
}
// Warship deck SVG design
let warshipDeck = document.createElementNS('http://www.w3.org/2000/svg', 'path');
warshipDeck.setAttribute('class', localTeam + ' team_fill team_stroke');
warshipDeck.setAttribute('d', 'M 12.5 1 C 8 6.2 7 11.1 7.3 15.6 Q 7.7 20.2 9.25 24 L 15.75 24 Q 17 20.2 17.5 15.6 C 17.8 11.1 16.6 6.2 12.5 1 Z');
warshipDeck.style.strokeWidth = '1px';
// Warship line SVG design (just so has 5 children)
let warshipLine1 = document.createElementNS('http://www.w3.org/2000/svg', 'path');
warshipLine1.setAttribute('class', localTeam + ' team_fill team_stroke');
warshipLine1.setAttribute('d', 'M 15.5 24 L 15.75 24');
warshipLine1.style.strokeWidth = '1px';
// Warship line SVG design (just so has 5 children)
let warshipLine2 = document.createElementNS('http://www.w3.org/2000/svg', 'path');
warshipLine2.setAttribute('class', localTeam + ' team_fill team_stroke');
warshipLine2.setAttribute('d', 'M 9.25 24 L 9.5 24');
warshipLine2.style.strokeWidth = '1px';
// Building the tile
actionTile.appendChild(warshipDeck);
actionTile.appendChild(warshipLine1);
actionTile.appendChild(warshipLine2);
if (localDamage >= 4) {
// Warship mast SVG design
let warshipMast = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
warshipMast.setAttribute('class', localTeam + ' team_stroke');
warshipMast.setAttribute('cx', '12.5');
warshipMast.setAttribute('cy', '17');
warshipMast.setAttribute('r', '1');
warshipMast.style.strokeWidth = '1px';
warshipMast.style.strokeLinecap = 'round';
actionTile.appendChild(warshipMast);
}
if (localDamage >= 5) {
// Warship sail SVG design
let warshipSail = document.createElementNS('http://www.w3.org/2000/svg', 'path');
warshipSail.setAttribute('d', 'M 2 16 L 23 16 C 20.5 13.5 16.5 12 12.5 12 C 7.5 12 3.5 13.5 2 16 Z');
warshipSail.setAttribute('class', localTeam + ' team_stroke');
warshipSail.setAttribute('fill', 'white');
warshipSail.style.strokeWidth = '1px';
actionTile.appendChild(warshipSail);
}
return actionTile;
},
// Method to create warship tile
// ---------------------------
createCatamaranTile: function(actionTile, localTeam, localDamage) {
// Removes all elements of SVG for damage / repair building
while (actionTile.lastChild) {
actionTile.removeChild(actionTile.lastChild);
}
// Cat left deck SVG design
let catDeck1 = document.createElementNS('http://www.w3.org/2000/svg', 'path');
catDeck1.setAttribute('class', localTeam + ' team_fill team_stroke');
catDeck1.setAttribute('d', 'M 7.5 3 A 3.5 10.5 1 0 0 7.5 22 A 3.5 10.5 1 0 0 7.5 3 Z');
catDeck1.style.strokeWidth = '1px';
// Cat right deck SVG design
let catDeck2 = document.createElementNS('http://www.w3.org/2000/svg', 'path');
catDeck2.setAttribute('class', localTeam + ' team_fill team_stroke');
catDeck2.setAttribute('d', 'M 17.5 3 A 3.5 10.5 1 0 0 17.5 22 A 3.5 10.5 1 0 0 17.5 3 Z');
catDeck2.style.strokeWidth = '1px';
// Cat centre deck SVG design
let catCentreDeck = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
catCentreDeck.setAttribute('x', '7');
catCentreDeck.setAttribute('y', '8.5');
catCentreDeck.setAttribute('width', '11');
catCentreDeck.setAttribute('height', '10.5');
catCentreDeck.setAttribute('rx', '1');
catCentreDeck.setAttribute('ry', '1');
catCentreDeck.style.strokeWidth = '1px';
catCentreDeck.setAttribute('class', localTeam + ' team_fill team_stroke');
// Building the tile
actionTile.appendChild(catDeck1);
actionTile.appendChild(catDeck2);
actionTile.appendChild(catCentreDeck);
if (localDamage >= 4) {
// Catamaran mast SVG design
let warshipMast = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
warshipMast.setAttribute('class', localTeam + ' team_stroke');
warshipMast.setAttribute('cx', '12.5');
warshipMast.setAttribute('cy', '16.5');
warshipMast.setAttribute('r', '1');
warshipMast.style.strokeWidth = '1px';
warshipMast.style.strokeLinecap = 'round';
actionTile.appendChild(warshipMast);
}
if (localDamage >= 5) {
// Catamaran sail SVG design
let warshipSail = document.createElementNS('http://www.w3.org/2000/svg', 'path');
warshipSail.setAttribute('d', 'M 2 15.5 L 23 15.5 C 20.5 12.5 16.5 11.5 12.5 11.5 C 7.5 11.5 3.5 13 2 15.5 Z');
warshipSail.setAttribute('class', localTeam + ' team_stroke');
warshipSail.setAttribute('fill', 'white');
warshipSail.style.strokeWidth = '1px';
actionTile.appendChild(warshipSail);
}
return actionTile;
},
// Method to damage cargo ship after conflict
// ------------------------------------------
damageShip: function(actionTile, localTeam, localType, localDamage) {
if(workFlow == 1) {console.log('Ship damage displayed: ' + (Date.now() - launchTime)); }
if (localType == 'cargo ship') {
actionTile = this.createCargoTile(actionTile, localTeam, localDamage);
} else if (localType == 'warship') {
actionTile = this.createWarshipTile(actionTile, localTeam, localDamage);
} else if (localType == 'catamaran') {
actionTile = this.createCatamaranTile(actionTile, localTeam, localDamage);
}
let shipOars = document.createElementNS('http://www.w3.org/2000/svg', 'path');
shipOars.setAttribute('d', 'M 7.5 10 L 1.5 13.5 M 17.5 10 L 23.5 13.5 M 7 13 L 1.5 16.5 M 18 13 L 23.5 16.5 M 7.5 15.5 L 1.5 19.5 M 17.5 15.5 L 23.5 19.5 M 7.5 18 L 1.5 22.5 M 17.5 18 L 23.5 22.5');
shipOars.setAttribute('class', localTeam + ' team_stroke');
shipOars.style.strokeLinejoin = 'round';
shipOars.style.strokeLinecap = 'round';
shipOars.style.strokeWidth = '1px';
actionTile.appendChild(shipOars);
},
// Method to repair cargo ship docked in harbour
// ---------------------------------------------
repairShip: function(actionTile, localTeam, localType, localDamage) {
if(workFlow == 1) {console.log('Ship repair displayed: ' + (Date.now() - launchTime)); }
if (localType == 'cargo ship') {
actionTile = this.createCargoTile(actionTile, localTeam, localDamage);
} else if (localType == 'warship') {
actionTile = this.createWarshipTile(actionTile, localTeam, localDamage);
} else if (localType == 'catamaran') {
actionTile = this.createCatamaranTile(actionTile, localTeam, localDamage);
}
// Puts up scaffolding
if (localDamage < 5) {
let shipScaffold = document.createElementNS('http://www.w3.org/2000/svg', 'path');
shipScaffold.setAttribute('d', 'M 3 4 L 3 23 M 22 4 L 22 23 M 3 8 L 6.5 8 M 22 8 L 18.5 8 M 3 19 L 6 19 M 22 19 L 19 19');
shipScaffold.setAttribute('class', localTeam + ' team_stroke');
shipScaffold.style.strokeLinejoin = 'round';
shipScaffold.style.strokeLinecap = 'round';
shipScaffold.style.strokeWidth = '1px';
actionTile.appendChild(shipScaffold);
}
},
// Method to create fort tile
// ---------------------------
createFortTile: function(actionTile, localTeam) {
// Fort turret design
let fortTurret1 = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
fortTurret1.setAttribute('class', localTeam + ' team_stroke');
fortTurret1.setAttribute('cx', '7');
fortTurret1.setAttribute('cy', '7');
fortTurret1.setAttribute('r', '2.5');
fortTurret1.style.strokeWidth = '1px';
fortTurret1.style.strokeLinecap = 'round';
let fortTurret2 = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
fortTurret2.setAttribute('class', localTeam + ' team_stroke');
fortTurret2.setAttribute('cx', '7');
fortTurret2.setAttribute('cy', '18');
fortTurret2.setAttribute('r', '2.5');
fortTurret2.style.strokeWidth = '1px';
fortTurret2.style.strokeLinecap = 'round';
let fortTurret3 = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
fortTurret3.setAttribute('class', localTeam + ' team_stroke');
fortTurret3.setAttribute('cx', '18');
fortTurret3.setAttribute('cy', '7');
fortTurret3.setAttribute('r', '2.5');
fortTurret3.style.strokeWidth = '1px';
fortTurret3.style.strokeLinecap = 'round';
let fortTurret4 = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
fortTurret4.setAttribute('class', localTeam + ' team_stroke');
fortTurret4.setAttribute('cx', '18');
fortTurret4.setAttribute('cy', '18');
fortTurret4.setAttribute('r', '2.5');
fortTurret4.style.strokeWidth = '1px';
fortTurret4.style.strokeLinecap = 'round';
// Fort wall rectangle design
let fortWall = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
fortWall.setAttribute('x', '6');
fortWall.setAttribute('y', '6');
fortWall.setAttribute('width', '13');
fortWall.setAttribute('height', '13');
fortWall.setAttribute('rx', '1');
fortWall.setAttribute('ry', '1');
fortWall.style.strokeWidth = '1px';
fortWall.setAttribute('class', localTeam + ' team_fill team_stroke');
// Fort cannon design
let fortCannon = document.createElementNS('http://www.w3.org/2000/svg', 'path');
fortCannon.setAttribute('d', 'M 15 12.5 Q 12.5 16 10 12.5 L 11.5 2 L 13.5 2 L 15 12.5');
fortCannon.setAttribute('class', localTeam + ' team_stroke');
fortCannon.style.strokeLinejoin = 'round';
fortCannon.style.strokeLinecap = 'round';
fortCannon.style.strokeWidth = '1px';
// Building the tile
actionTile.appendChild(fortWall);
actionTile.appendChild(fortTurret1);
actionTile.appendChild(fortTurret2);
actionTile.appendChild(fortTurret3);
actionTile.appendChild(fortTurret4);
actionTile.appendChild(fortCannon);
return actionTile;
},
// Method to create forest tile
// ---------------------------
createForestTile: function(actionTile, localTeam) {
// Canopy circle design
let treeCanopy1 = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
treeCanopy1.setAttribute('class', localTeam + ' team_fill team_stroke');
treeCanopy1.setAttribute('cx', '15');
treeCanopy1.setAttribute('cy', '9');
treeCanopy1.setAttribute('r', '5.5');
treeCanopy1.style.strokeWidth = '1px';
treeCanopy1.style.strokeLinecap = 'round';
let treeCanopy2 = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
treeCanopy2.setAttribute('class', localTeam + ' team_stroke');
treeCanopy2.setAttribute('cx', '8');
treeCanopy2.setAttribute('cy', '10.5');
treeCanopy2.setAttribute('r', '4.5');
treeCanopy2.setAttribute('fill', 'rgb(213, 191, 163)');
treeCanopy2.style.strokeWidth = '1px';
treeCanopy2.style.strokeLinecap = 'round';
// Trunk rectangle design
let treeTrunk1 = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
treeTrunk1.setAttribute('class', localTeam + ' team_stroke');
treeTrunk1.setAttribute('x', '14.5');
treeTrunk1.setAttribute('y', '15');
treeTrunk1.setAttribute('width', '1.5');
treeTrunk1.setAttribute('height', '5');
treeTrunk1.setAttribute('fill', 'rgb(89, 53, 20)');
treeTrunk1.style.strokeWidth = '1px';
let treeTrunk2 = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
treeTrunk2.setAttribute('class', localTeam + ' team_stroke');
treeTrunk2.setAttribute('x', '7.5');
treeTrunk2.setAttribute('y', '15');
treeTrunk2.setAttribute('width', '1');
treeTrunk2.setAttribute('height', '5');
treeTrunk2.setAttribute('fill', 'rgb(89, 53, 20)');
treeTrunk2.style.strokeWidth = '1px';
// Building the tile
actionTile.appendChild(treeTrunk1);
actionTile.appendChild(treeTrunk2);
actionTile.appendChild(treeCanopy1);
actionTile.appendChild(treeCanopy2);
return actionTile;
},
// Method to create ironworks tile
// ---------------------------
createIronworksTile: function(actionTile, localTeam) {
// Mountain background design
let mountainBackground = document.createElementNS('http://www.w3.org/2000/svg', 'path');
mountainBackground.setAttribute('d', 'M 21.5 18 L 12.5 2.5 L 3.5 18');
mountainBackground.setAttribute('class', localTeam + ' team_fill team_stroke');
mountainBackground.style.strokeLinejoin = 'round';
mountainBackground.style.strokeLinecap = 'round';
mountainBackground.style.strokeWidth = '1px';
// Mountain snow design
let mountainSnow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
mountainSnow.setAttribute('d', 'M 9.3 8 A 5 5 0 0 0 15.7 8 L 12.5 2.5 Z');
mountainSnow.setAttribute('class', localTeam + ' team_stroke');
mountainSnow.style.strokeLinejoin = 'round';
mountainSnow.style.strokeLinecap = 'round';
mountainSnow.setAttribute('fill', 'white');
mountainSnow.style.strokeWidth = '1px';
// Iron square design
let ironSquare = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
ironSquare.setAttribute('class', localTeam + ' team_stroke');
ironSquare.setAttribute('x', '9');
ironSquare.setAttribute('y', '14');
ironSquare.setAttribute('width', '7');
ironSquare.setAttribute('height', '7');
ironSquare.setAttribute('fill', 'silver');
ironSquare.style.strokeWidth = '1px';
ironSquare.setAttribute('rx', '1');
ironSquare.setAttribute('ry', '1');
ironSquare.style.strokeLinecap = 'round';
// Building the tile
actionTile.appendChild(mountainBackground);
actionTile.appendChild(mountainSnow);
actionTile.appendChild(ironSquare);
return actionTile;
},
// Method to create desert tile
// ---------------------------
createDesertTile: function(actionTile, localTeam) {
// rear dune
let rearSandDune = document.createElementNS('http://www.w3.org/2000/svg', 'path');
rearSandDune.setAttribute('class', localTeam);
rearSandDune.setAttribute('d', 'M 2 13 C 3 9 6 7 9 6 L 16 13');
rearSandDune.style.strokeWidth = '1px';
rearSandDune.setAttribute('stroke','rgb(138, 87, 50)');
rearSandDune.setAttribute('fill', 'rgb(235, 215, 195)');
// front dune
let frontSandDune = document.createElementNS('http://www.w3.org/2000/svg', 'path');
frontSandDune.setAttribute('d', 'M 9 18 C 10 14 13 12 16 11 L 23 18');
frontSandDune.setAttribute('class', localTeam);
frontSandDune.setAttribute('stroke','rgb(138, 87, 50)');
frontSandDune.setAttribute('fill', 'rgb(235, 215, 195)');
// Building the tile
actionTile.appendChild(rearSandDune);
actionTile.appendChild(frontSandDune);
return actionTile;
},
// Method to create quarry tile
// ---------------------------
createQuarryTile: function(actionTile, localTeam) {
// Pick handle rectangle
let pickHandle = document.createElementNS('http://www.w3.org/2000/svg', 'path');
pickHandle.setAttribute('class', localTeam + ' team_fill team_stroke');
pickHandle.setAttribute('d', 'M 7.5 5.7 Q 7.4 4 9.2 4 L 21.2 16 L 19.5 17.7 L 8.2 6.7 Z');
pickHandle.style.strokeLinejoin = 'round';
pickHandle.style.strokeWidth = '1px';
// Pick metal left
let pickLeft = document.createElementNS('http://www.w3.org/2000/svg', 'path');
pickLeft.setAttribute('d', 'M 8.2 7.8 Q 5.4 10.1 5.5 14.5 Q 6.8 10.9 9.5 9.1 Z');
pickLeft.setAttribute('class', localTeam + ' team_stroke');
pickLeft.setAttribute('fill', 'silver');
pickLeft.style.strokeLinejoin = 'round';
pickLeft.style.strokeWidth = '1px';
// Pick metal right
let pickRight = document.createElementNS('http://www.w3.org/2000/svg', 'path');
pickRight.setAttribute('d', 'M 11.3 4.7 Q 13.6 1.9 18 2 Q 14.4 3.3 12.6 6 Z');
pickRight.setAttribute('class', localTeam + ' team_stroke');
pickRight.setAttribute('fill', 'silver');
pickRight.style.strokeLinejoin = 'round';
pickRight.style.strokeWidth = '1px';
// Pick square
let pickSquare = document.createElementNS('http://www.w3.org/2000/svg', 'path');
pickSquare.setAttribute('d', 'M 7.5 7 L 10.3 4.2 L 13.1 7 L 10.3 9.8 Z');
pickSquare.setAttribute('class', localTeam + ' team_stroke');
pickSquare.setAttribute('fill', 'silver');
pickSquare.style.strokeLinejoin = 'round';
pickSquare.style.strokeWidth = '1px';
// Stone square in quarry
let stoneSquare = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
stoneSquare.setAttribute('class', localTeam + ' team_stroke');
stoneSquare.setAttribute('x', '5.5');
stoneSquare.setAttribute('y', '15.5');
stoneSquare.setAttribute('width', '6');
stoneSquare.setAttribute('height', '6');
stoneSquare.setAttribute('rx', '1');
stoneSquare.setAttribute('ry', '1');
stoneSquare.setAttribute('fill', 'white');
stoneSquare.style.strokeWidth = '1px';
// Building the tile
actionTile.appendChild(pickHandle);
actionTile.appendChild(pickLeft);
actionTile.appendChild(pickRight);
actionTile.appendChild(pickSquare);
actionTile.appendChild(stoneSquare);
return actionTile;
},
// Method to create plantation tile
// --------------------------------
createPlantationTile: function(actionTile, localTeam) {
// lower berry
let berry1 = document.createElementNS('http://www.w3.org/2000/svg', 'ellipse');
berry1.setAttribute('class', localTeam + ' team_stroke');
berry1.setAttribute('cx', '11.2');
berry1.setAttribute('cy', '17.8');
berry1.setAttribute('rx', '2.2');
berry1.setAttribute('ry', '2.7');
berry1.setAttribute('stroke','rgb(138, 87, 50)');
berry1.setAttribute('fill', 'rgb(235, 215, 195)');
// right hand berry
let berry3 = document.createElementNS('http://www.w3.org/2000/svg', 'ellipse');
berry3.setAttribute('class', localTeam + ' team_stroke');
berry3.setAttribute('cx', '17.6');
berry3.setAttribute('cy', '10.2');
berry3.setAttribute('rx', '2.7');
berry3.setAttribute('ry', '2.2');
berry3.setAttribute('stroke','rgb(138, 87, 50)');
berry3.setAttribute('fill', 'rgb(235, 215, 195)');
// diagonal berry
let berry2 = document.createElementNS('http://www.w3.org/2000/svg', 'ellipse');
berry2.setAttribute('class', localTeam + ' team_fill team_stroke');
berry2.setAttribute('cx', '0');
berry2.setAttribute('cy', '0');
berry2.setAttribute('rx', '2.7');
berry2.setAttribute('ry', '2.2');
berry2.setAttribute('stroke','rgb(138, 87, 50)');
berry2.setAttribute('fill', 'rgb(213, 191, 163)');
berry2.setAttribute('transform', 'translate(17.4, 17) rotate(55)');
// twig
let coffeeTwig = document.createElementNS('http://www.w3.org/2000/svg', 'path');
coffeeTwig.setAttribute('class', localTeam + ' team_stroke');
coffeeTwig.setAttribute('d', 'M 4.2 7 C 5.1 7.4 7.7 8 11.2 10.4 C 12.6 11.4 13.8 12.6 15.5 14.6');
coffeeTwig.setAttribute('stroke','rgb(138, 87, 50)');
coffeeTwig.setAttribute('fill', 'none');
coffeeTwig.setAttribute('stroke-linecap', 'round');
// lower coffee leaf
let coffeeLeaf1 = document.createElementNS('http://www.w3.org/2000/svg', 'path');
coffeeLeaf1.setAttribute('d', 'M 5.5 19.2 C 6.5 17.8 7.2 16.0 7.5 15.0 C 7.7 14.2 7.5 13.5 7 12.7 C 6.6 11.6 5.6 10.5 4.8 9.6 C 3.0 12.9 2.7 14.5 3.9 16.6 C 4.2 17.1 5.0 18.5 5.5 19.2 ');
coffeeLeaf1.setAttribute('class', localTeam + ' team_fill team_stroke');
coffeeLeaf1.setAttribute('stroke','rgb(138, 87, 50)');
coffeeLeaf1.setAttribute('fill', 'rgb(213, 191, 163)');
coffeeLeaf1.setAttribute('stroke-linecap', 'round');
coffeeLeaf1.setAttribute('stroke-linejoin', 'round');
coffeeLeaf1.style.strokeWidth = '1px';
// upper coffee leaf
let coffeeLeaf2 = document.createElementNS('http://www.w3.org/2000/svg', 'path');
coffeeLeaf2.setAttribute('d', 'M 17.5 4.5 C 15.74 3.83 13.97 3.29 12.91 3.13 C 11.02 2.85 9.2 4.69 7.72 6.28 C 11.3 7.81 12.85 8.01 14.83 6.61 C 15.34 6.25 16.66 5.35 17.5 4.5 ');
coffeeLeaf2.setAttribute('class', localTeam + ' team_fill team_stroke');
coffeeLeaf2.setAttribute('stroke','rgb(138, 87, 50)');
coffeeLeaf2.setAttribute('fill', 'rgb(213, 191, 163)');
coffeeLeaf2.setAttribute('stroke-linecap', 'round');
coffeeLeaf2.setAttribute('stroke-linejoin', 'round');
coffeeLeaf2.style.strokeWidth = '1px';
// Building the tile
actionTile.appendChild(berry1);
actionTile.appendChild(berry2);
actionTile.appendChild(berry3);
actionTile.appendChild(coffeeTwig);
actionTile.appendChild(coffeeLeaf1);
actionTile.appendChild(coffeeLeaf2);
return actionTile;
},
// Method to create flax tile
// --------------------------------
createFlaxTile: function(actionTile, localTeam) {
function createPetal(centerX, centerY, rotatePetal, size, teamColour) {
// petal
let petal = document.createElementNS('http://www.w3.org/2000/svg', 'path');
if (teamColour == true) {
petal.setAttribute('class', localTeam + ' team_fill team_stroke');
petal.setAttribute('fill', 'rgb(213, 191, 163)');
} else {
petal.setAttribute('class', localTeam);
petal.setAttribute('fill', 'white');
}
petal.setAttribute('d', 'M ' + (centerX - 1.5) + ' ' + (centerY - 1.5) + ' A ' + size + ' ' + size + ' 0 1 0 '+ (centerX - 1.5) + ' ' + (centerY + 1.5) + ' L ' + centerX + ' ' + centerY + ' Z');
petal.setAttribute('stroke','rgb(138, 87, 50)');