-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
1350 lines (1247 loc) · 38.8 KB
/
index.html
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
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>test</title>
<style>@keyframes blockBoom {
0% {
transform: scale(1);
opacity: 100%;
}
50% {
filter: saturate(0.5);
transform: scale(1);
}
100% {
filter: saturate(0);
transform: scale(0);
}
}
@keyframes small {
0% {
transform: scale(1);
}
50% {
transform: scale(0.7);
}
100% {
transform: scale(1);
}
}
@keyframes putFx {
0% {
transform: scale(3);
opacity: 0.54;
}
100% {
transform: scale(1);
opacity: 1;
}
}
@keyframes littleShake {
0% {
transform: translateX(0px) translateY(0px);
}
50% {
transform: translateX(2px) translateY(2px);
}
100% {
transform: translateX(0px) translateY(0px);
}
}
@keyframes fireFlame {
0% {
filter: blur(0);
}
50% {
filter: blur(3px);
}
100% {
filter: blur(0);
}
}
@keyframes fireStoneLeft {
from {
transform: translateX(0);
}
to {
transform: translateX(-30px);
}
}
@keyframes fireStoneRight {
from {
transform: translateX(0);
}
to {
transform: translateX(30px);
}
}
@keyframes fireStoneTop {
from {
transform: translateY(0);
}
to {
transform: translateY(-30px);
}
}
@keyframes fireStoneDown {
from {
transform: translateY(0);
}
to {
transform: translateY(30px);
}
}
@keyframes bigShake {
0% {
transform: translateX(0px) translateY(0px);
}
20% {
transform: translateX(1px) translateY(1px);
}
40% {
transform: translateX(-2px) translateY(-2px);
}
60% {
transform: translateX(2px) translateY(2px);
}
80% {
transform: translateX(-1px) translateY(-1px);
}
100% {
transform: translateX(0px) translateY(0px);
}
}
/*# sourceMappingURL=animation.css.map */</style><style>* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
overflow-x: hidden;
}
body h1 {
text-align: center;
}
body .normalGameDiv .boardShakeFx {
animation-name: littleShake;
animation-fill-mode: forwards;
}
body .normalGameDiv .table {
width: 100%;
outline: solid 1px;
padding-top: 100px;
padding-left: 30px;
padding-bottom: 100px;
background-color: #d3a969;
}
body .normalGameDiv .table .tableLine {
height: 30px;
margin-bottom: 0;
}
body .normalGameDiv .table .tableLine .tableBoxShakeFx {
animation-name: small;
animation-fill-mode: forwards;
}
body .normalGameDiv .table .tableLine .tableBoxHover {
outline-width: 3px;
z-index: 4;
transform: scale(1.5);
}
body .normalGameDiv .table .tableLine .tableBox {
width: 30px;
height: 30px;
margin-left: 0;
float: left;
transition: all 0.2s;
position: relative;
}
body .normalGameDiv .table .tableLine .tableBox .block {
width: 100%;
height: 100%;
z-index: 3;
position: absolute;
left: 0;
top: 0;
transition: outline-color 0.5s;
outline-width: 3px;
outline-color: transparent;
}
body .normalGameDiv .table .tableLine .tableBox .block:hover {
cursor: pointer;
outline-style: solid;
}
body .normalGameDiv .table .tableLine .tableBox .bz {
display: block;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 0;
background-size: contain;
}
body .normalGameDiv .table .tableLine .tableBox .bz:hover {
filter: blur(5px);
}
body .normalGameDiv .table .tableLine .tableBox .littleStone {
position: absolute;
border-radius: 50%;
left: 50%;
top: 50%;
z-index: 1;
transition-timing-function: ease-out;
}
body .normalGameDiv .table .tableLine .tableBox .shrink {
position: absolute;
width: 30px;
height: 30px;
left: 0;
top: 0;
border-radius: 50%;
z-index: 100;
animation-name: blockBoom;
animation-fill-mode: forwards;
}
body .normalGameDiv .table .tableLine .tableBox .putFx {
position: absolute;
width: 30px;
height: 30px;
left: 0;
top: 0;
border-radius: 50%;
animation-name: putFx;
animation-fill-mode: forwards;
animation-timing-function: ease-in-out;
}
body .normalGameDiv .table .tableLine .tableBox .wall {
background-color: dimgray;
border-radius: 20%;
outline: none;
}
body .normalGameDiv .table .tableLine .tableBox .wall:hover {
cursor: not-allowed;
}
body .normalGameDiv .table .tableLine .tableBox .fireStone {
background-color: #ea4040;
border: solid 3px gold;
border-radius: 20%;
outline: none;
}
body .normalGameDiv .table .tableLine .tableBox .fireStone:hover {
cursor: not-allowed;
}
body .normalGameDiv .table .tableLine .tableBox .fireStoneMoveFx {
background-color: #ea4040;
border: solid 3px gold;
border-radius: 20%;
outline: none;
width: 30px;
height: 30px;
}
body .normalGameDiv .table .tableLine .tableBox .playerBlock {
border-radius: 50%;
}
body .normalGameDiv .table .tableLine .tableBox .playerBlock:hover {
cursor: auto;
}
/*# sourceMappingURL=index.css.map */</style> <style class="normalStyle">
.air:hover {
}
</style>
</head>
<body>
<h1>围棋大变种</h1>
<button class="normal">正方形网络</button>
<div class="normalOption" style="display: none">
棋盘宽度:
<label>
<input type="number" class="width" value="19">
</label>
棋盘高度:
<label>
<input type="number" class="height" value="19">
</label>
玩家数量:
<input type="number" value="2" min="2" class="playerNumber">
玩家颜色设定:
<span class="userColorList">
<input type="color" value="#000000">
<input type="color" value="#ffffff">
</span>
地形模式:
<select name="hinderMode" class="hinderMode">
<option value="传统">传统</option>
<option value="随机碎石地">随机碎石地</option>
<option value="随机火石地">随机火石地</option>
<option value="中凸高原">中凸高原</option>
<option value="中框">中框</option>
<option value="角落消失">角落消失</option>
<option value="九宫格分裂世界">九宫格分裂世界</option>
<option value="九宫格迷宫世界">九宫格迷宫世界</option>
<option value="田字格分裂世界">田字格分裂世界</option>
<option value="X分裂世界">X分裂世界</option>
</select>
碎石出现概率
<input type="range" max="100" min="0" value="0" class="stoneRate">
火石出现概率
<input type="range" max="100" min="0" value="0" class="firestoneRate">
<button class="play">开始游戏</button>
</div>
<div class="normalGameDiv" style="display: none">
<button class="autoPlayRandom100">自动随机100步</button>
<button class="autoPlayRandom10">自动随机10步</button>
<div class="table"></div>
</div>
<button class="triangle">三角形</button>
<button class="triangle">六边形</button>
</body>
<script>/**
* 一些辅助小函数
* by littlefean
*/
function $(queryStr) {
if (document.querySelector(queryStr) === null) {
console.log("选择器没有找到");
}
return document.querySelector(queryStr);
}
/**
* 在数组中随机选择一个元素并返回
* @return {*}
*/
Array.prototype.choiceOne = function () {
let r = Math.floor(Math.random() * this.length);
return this[r];
}
/**
* 创建一个div
* @param classNameString
* @param content
* @return {HTMLDivElement}
*/
function div(classNameString, content = "",) {
let res = document.createElement("div");
if (content !== "") {
res.innerText = content;
}
for (let className of classNameString.split(" ")) {
res.classList.add(className);
}
return res;
}
/**
* 随机一个十六进制颜色
*/
function randomColor() {
let strNormal = (str) => {
if (str.length === 1) {
return "0" + str;
}
return str;
}
let r = Math.floor(Math.random() * 256).toString(16);
let g = Math.floor(Math.random() * 256).toString(16);
let b = Math.floor(Math.random() * 256).toString(16);
return `#${strNormal(r)}${strNormal(g)}${strNormal(b)}`;
}
</script><script>/**
* 坐标点类
* 用来表示二维数组中的坐标点
*/
class Point {
/**
* 坐标点构造方法
* @param x {Number}
* @param y {Number}
*/
constructor(x, y) {
this.x = x;
this.y = y;
}
/**
* 获取一个坐标的周围四个点,以数组形式返回
* @return {Point[]}
*/
getRound4() {
return [
new Point(this.x + 1, this.y),
new Point(this.x - 1, this.y),
new Point(this.x, this.y + 1),
new Point(this.x, this.y - 1),
];
}
toString() {
return `(x:${this.x},y:${this.y})`;
}
/**
* 这个点是否在矩形棋盘内部
* @param width
* @param height
*/
isInSquireBoard(width, height) {
return (0 <= this.x && this.x < width) && (0 <= this.y && this.y < height);
}
outOfBoard(width, height) {
return !((0 <= this.x && this.x < width) && (0 <= this.y && this.y < height));
}
/**
* 转化成唯一的int值。用于点集类解析用。
* @return {*}
*/
hashCode() {
return 100_0000 * this.x + this.y;
}
/**
* 用于点集类解析用
* @param b
* @return {Point}
*/
static evalHashCode(b) {
let x = Math.floor(b / 100_0000);
let y = b % 100_0000;
return new Point(x, y);
}
/**
* 返回两个点之间的直线距离
* @param p
* @return {number}
*/
distance(p) {
return ((this.x - p.x) ** 2 + (this.y - p.y) ** 2) ** 0.5
}
/**
* 返回一个特殊实例
* @return {Point}
* @constructor
*/
static NegOne() {
return new Point(-1, -1);
}
up() {
return new Point(this.x, this.y - 1);
}
down() {
return new Point(this.x, this.y + 1);
}
left() {
return new Point(this.x - 1, this.y);
}
right() {
return new Point(this.x + 1, this.y);
}
}
/**
* 点集合
* 封装了js原生的set。
*/
class PointSet {
constructor() {
this.s = new Set();
}
add(point) {
this.s.add(point.hashCode());
}
have(point) {
return this.s.has(point.hashCode());
}
clear() {
this.s.clear();
}
notHave(point) {
return !this.have(point);
}
remove(point) {
if (this.s.has(point)) {
this.s.delete(point.hashCode());
}
}
size() {
return this.s.size;
}
toArray() {
let res = [];
for (let v of this.s) {
res.push(Point.evalHashCode(v));
}
return res;
}
}
</script><script>/**
* 枚举类
* 此类不要实例化对象,仅作为棋盘的格子中可能出现的东西使用。
*/
class GameObject {
/**
* 空气
* @type {number}
*/
static air = 0;
/**
* 墙体、石头
* @type {number}
*/
static wall = 1;
/**
* 火石
* @type {number}
*/
static fireStone = -1;
// 上面和css同名
/**
* 从2开始以上都是玩家,包括2
* @type {number}
*/
static BasePlayerNumber = 2;
/**
* 传入一个数字,解析这个数字是否是玩家数字
* @param n
* @return {boolean}
*/
static isPlayer(n) {
return n >= 2;
}
/**
* 解析一个数字,返回这个数字表示的GameObject的字符串。
* 用于渲染时候给div添加对应的css类名
* @param n
* @return {string}
*/
static eval(n) {
for (let k in GameObject) {
if (GameObject[k] === n) {
return k;
}
}
return "";
}
}
</script><script>/**
* 方格子的围棋
* by littlefean
*/
class NormalGame {
// 火石移动时间
static fireStoneMoveMs = 1000;
/**
*
* @param ele 界面div
* 界面div中有一个table子div用来存储棋盘
* @param optionEle 设置界面信息
*/
constructor(ele, optionEle) {
this.width = +optionEle.querySelector(".width").value;
this.height = +optionEle.querySelector(".height").value;
this.bindTableEle = ele.querySelector(".table");
this.arr = [];
/**
* 轮流轮
* @type {number[]}
*/
this.turnList = [];
/**
* 每个玩家上一次被吃掉的子的集合
* @type {PointSet[]}
*/
this.lastEatenSet = [];
/**
* 每个玩家对应的颜色
* @type {string[]}
*/
this.colorList = []
this._initPlayer();
this.turnIndex = 0;
this._initBoard();
this._initFunction();
}
_getHoverCss() {
return `.tableBox:hover {
outline-color: ${this.colorList[this.turnIndex]} !important;
outline-width: 3px !important;
z-index: 4;
}`;
}
/**
* 初始化一些功能:随机下棋按钮绑定事件。
* @private
*/
_initFunction() {
let randomStep = () => {
let airList = []; // 收集所有的空气方块
for (let y = 0; y < this.height; y++)
for (let x = 0; x < this.width; x++)
if (this._get(new Point(x, y)) === GameObject.air)
airList.push(new Point(x, y));
if (airList.length === 0)
return;
let p = airList.choiceOne();
this.putBlock(p.x, p.y);
this.rend();
}
$(".autoPlayRandom100").onclick = () => {
for (let i = 0; i < 100; i++) {
randomStep();
}
}
$(".autoPlayRandom10").onclick = () => {
for (let i = 0; i < 10; i++) {
randomStep();
}
}
}
/**
* 根据设定初始化棋盘数据内容
* 在结束时候会调用一次渲染。
* @private
*/
_initBoard() {
// 构建二维数组,全是空气
for (let y = 0; y < this.height; y++) {
let line = [];
for (let x = 0; x < this.width; x++) {
line.push(GameObject.air);
}
this.arr.push(line);
}
let selectEle = $(".hinderMode");
let modeName = selectEle.options[selectEle.selectedIndex].value;
let stoneRate = (+$(".stoneRate").value) / 100;
let firestoneRate = (+$(".firestoneRate").value) / 100;
// 1/3 的点
let Lh2 = Math.floor(this.height / 2);
let Lw2 = Math.floor(this.width / 2);
// 1/3 的点
let Lh3 = Math.floor(this.height / 3);
let Lw3 = Math.floor(this.width / 3);
// 1/4 点
let Lh4 = Math.floor(this.height / 4);
let Lw4 = Math.floor(this.width / 4);
let setWall = (x, y) => {
if (new Point(x, y).isInSquireBoard(this.width, this.height)) {
this.arr[y][x] = GameObject.wall;
}
}
let setFireStone = (x, y) => {
if (new Point(x, y).isInSquireBoard(this.width, this.height)) {
this.arr[y][x] = GameObject.fireStone;
}
}
let setWallLine = (p1, p2) => {
setWall(p1.x, p1.y);
if (p1.x === p2.x && p1.y === p2.y) {
setWall(p1.x, p1.y);
} else {
let step;
if (Math.abs(p2.x - p1.x) >= Math.abs(p2.y - p1.y)) {
step = Math.abs(p2.x - p1.x);
} else {
step = Math.abs(p2.y - p1.y);
}
for (let i = 0; i < step; i++) {
let x = Math.round(p1.x + (p2.x - p1.x) / step * (i + 1))
let y = Math.round(p1.y + (p2.y - p1.y) / step * (i + 1));
setWall(x, y);
}
}
}
switch (modeName) {
case "传统":
break;
case "随机碎石地":
for (let y = 0; y < this.height; y++)
for (let x = 0; x < this.width; x++)
if (Math.random() < stoneRate)
setWall(x, y);
break;
case "随机火石地":
for (let y = 0; y < this.height; y++)
for (let x = 0; x < this.width; x++)
if (Math.random() < firestoneRate)
setFireStone(x, y);
break;
case "中凸高原":
for (let y = Lh3; y < Lh3 * 2; y++)
for (let x = Lw3; x < Lw3 * 2; x++)
setWall(x, y);
break;
case "中框":
for (let y = Lh3; y < Lh3 * 2; y++) {
setWall(Lw3, y);
setWall(Lw3 * 2, y);
}
for (let x = Lw3; x < Lw3 * 2; x++) {
setWall(x, Lh3);
setWall(x, Lh3 * 2);
}
break;
case "角落消失":
for (let dy = 0; dy < Lh4; dy++) {
for (let dx = 0; dx < Lw4; dx++) {
setWall(dx, dy);
setWall(this.width - 1 - dx, dy);
setWall(dx, this.height - 1 - dy);
setWall(this.width - 1 - dx, this.height - 1 - dy);
}
}
break;
case "九宫格分裂世界":
for (let y = 0; y < this.height; y++) {
setWall(Lw3, y);
setWall(Lw3 * 2, y);
}
for (let x = 0; x < this.width; x++) {
setWall(x, Lh3);
setWall(x, Lh3 * 2);
}
break;
case "田字格分裂世界":
for (let y = 0; y < this.height; y++)
setWall(Lw2, y);
for (let x = 0; x < this.width; x++)
setWall(x, Lh2);
break;
case "X分裂世界":
setWallLine(new Point(0, 0), new Point(this.width - 1, this.height - 1));
setWallLine(new Point(this.width - 1, 0), new Point(0, this.height - 1));
break;
}
// 初始化前端显示
this._initTableEle();
this.rend();
}
/**
* 初始化玩家颜色信息、上一轮被吃掉的位置数组信息
* @private
*/
_initPlayer() {
let playerNumber = +$(".playerNumber").value;
let userColorList = $(".userColorList");
for (let i = 0; i < playerNumber; i++) {
this.turnList.push(i + GameObject.BasePlayerNumber);
this.lastEatenSet.push(new PointSet());
this.colorList.push(userColorList.children[i].value)
}
}
/**
* 获取周围四个位置 返回一个数组
* @private
*/
_getRound(x, y) {
let p = new Point(x, y);
let res = [];
for (let roundPoint of p.getRound4()) {
if (roundPoint.isInSquireBoard(this.width, this.height)) {
res.push(roundPoint);
}
}
return res;
}
/**
* 获取数据棋盘上一个坐标位置是什么
* @param p {Point} 传入的是坐标点类型
* @return {Number} 返回的是数字
* @private
*/
_get(p) {
return this.arr[p.y][p.x];
}
/**
* 获取棋盘p位置上的小容器格子div。
* @param p {Point}
* @return {Element}
* @private
*/
_getBox(p) {
if (p === undefined) {
console.log("传入坐标点是undef")
}
if (p === null) {
console.log("传入坐标点是null")
}
if (typeof p !== "object") {
console.log(p, "不是obj")
}
if (p.isInSquireBoard(this.width, this.height)) {
return this.bindTableEle.children[p.y].children[p.x];
} else {
console.log("访问box越界了");
}
}
/**
* 设定数据棋盘中的物品
* @param p 设定的位置的坐标
* @param obj {Number}
* @private
*/
_set(p, obj) {
if (obj === undefined) {
console.warn("不能设置棋盘上一个位置为undefined");
} else {
this.arr[p.y][p.x] = obj;
}
}
/**
* 从一个点开始获取一连串相同颜色形成的集合
* @param rootPoint
* @return {PointSet}
* @private
*/
_getGroupSet(rootPoint) {
let n = this._get(rootPoint);
let q = [rootPoint];
let visitedBody = new PointSet();
visitedBody.add(rootPoint);
while (q.length) {
let p = q.shift(); // 队列出
visitedBody.add(p); // 添加访问
// 遍历当前的周围四个
for (let roundP of p.getRound4()) {
if (roundP.isInSquireBoard(this.width, this.height)) {
if (this._get(roundP) === n && visitedBody.notHave(roundP)) {
// 当前这个是自己还没访问过的身体
q.push(roundP);
visitedBody.add(roundP);
}
}
}
}
return visitedBody;
}
/**
* 检测一个位置上的棋子,BFS,这一块棋有多少口气
* @param rootPoint
* @return {number}
* @private
*/
_gasCount(rootPoint) {
let n = this._get(rootPoint);
if (GameObject.isPlayer(n)) {
// 当前这个点不是障碍物,也不是空气
let q = [rootPoint];
let visitedBody = new PointSet();
visitedBody.add(rootPoint); // 添加访问
let gasSet = new PointSet();
while (q.length) {
let p = q.shift(); // 队列出
// 遍历当前的周围四个
for (let roundP of p.getRound4()) {
if (roundP.isInSquireBoard(this.width, this.height)) {
if (this._get(roundP) === GameObject.air) {
// 当前这个是空气
gasSet.add(roundP);
}
if (this._get(roundP) === n && visitedBody.notHave(roundP)) {
// 当前这个是自己还没访问过的身体
q.push(roundP);
visitedBody.add(roundP);
}
}
}
}
return gasSet.size();
} else {
return 0;
}
}
/**
* 世界其他生物运行活动
* 火石移动
*/
otherMotion() {
// 火石移动特效
let addFireMoveFx = (p1, p2) => {
let dx = p2.x - p1.x;
let dy = p2.y - p1.y;
let fireEle = div("fireStoneMoveFx");
fireEle.style.animationDuration = `${NormalGame.fireStoneMoveMs}ms`;
if (dx === 1) {
fireEle.style.animationName = "fireStoneRight";
} else if (dx === -1) {
fireEle.style.animationName = "fireStoneLeft";
} else if (dy === 1) {
fireEle.style.animationName = "fireStoneDown";
} else if (dy === -1) {
fireEle.style.animationName = "fireStoneTop";
} else {
// 火石被困住了
console.log("有火石被困住了")
fireEle.style.animationName = "bigShake";
}
this._getBox(p1).appendChild(fireEle);
setTimeout(() => {
this._getBox(p1).removeChild(fireEle);
}, NormalGame.fireStoneMoveMs);
};
let moveEndLoc = new PointSet(); // 存放已经移动过的火石的位置
for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
let p = new Point(x, y);
if (this._get(p) === GameObject.fireStone) {
if (moveEndLoc.have(p)) {
continue;
}
// 当前位置是一个火石,开始随机移动
let roundAirList = [];
for (let round of this._getRound(x, y)) {
if (this._get(round) === GameObject.air) {
roundAirList.push(round);
}
}
if (roundAirList.length !== 0) {
let moveLoc = roundAirList.choiceOne();
// 处理移动
this._set(p, GameObject.air);
this._set(moveLoc, GameObject.fireStone);
addFireMoveFx(p, moveLoc);
moveEndLoc.add(moveLoc); // 移动过集合
let deadList = [];
for (let r of this._getRound(moveLoc.x, moveLoc.y)) {
if (GameObject.isPlayer(this._get(r))) {
// 检测这个玩家是否死了
if (this._gasCount(r) === 0) {
// 被火石挤死了
console.log(r, "这个位置的玩家被挤死了")
deadList = deadList.concat(this._getGroupSet(r).toArray());
console.log(deadList);
// 立刻处理掉
this.dead(deadList);
}
}
}
} else {
// 火石被困住了
addFireMoveFx(p, p);
}
}
}
}
this.rend();
}
/**
* 处理提子效果
* @param attackArr {Point[]}
*/
dead(attackArr) {
// 遍历每一个要死的位置
for (let deadPoint of attackArr) {
// 添加一点小动画
let dur = 2000;
console.log(deadPoint, "dp")
let box = this._getBox(deadPoint);
let shrinkEle = div("shrink");
let colorStr = this.colorList[this._get(deadPoint) - GameObject.BasePlayerNumber]