-
Notifications
You must be signed in to change notification settings - Fork 0
/
MilitaryChess.aspx
1368 lines (1287 loc) · 77 KB
/
MilitaryChess.aspx
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
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MilitaryChess.aspx.cs" Inherits="MilitaryChess.MailityChess" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery.js"></script>
<style type="text/css">
.test {
position: absolute;
}
.chess {
position: absolute;
}
#center {
width: 210px;
height: 210px;
top: 235px;
left: 368px;
}
#left {
width: 219px;
height: 210px;
top: 235px;
left: 149px;
}
#top {
width: 210px;
height: 219px;
top: 16px;
left: 368px;
}
#right {
width: 219px;
height: 210px;
top: 235px;
left: 578px;
}
#bottom {
width: 210px;
height: 219px;
top: 445px;
left: 368px;
}
.buttomChess {
width: 36px;
height: 27px;
}
.leftChess {
width: 27px;
height: 36px;
}
.chessback {
z-index: 300;
}
.nickname {
width: 110px;
height: 30px;
position: absolute;
color: White;
line-height: 30px;
}
.headimg {
width: 120px;
height: 163px;
position: absolute;
}
.face {
width: 120px;
height: 163px;
}
#name0 {
top: 632px;
left: 586px;
}
#player0 {
top: 464px;
left: 586px;
}
#name1 {
top: 418px;
left: 19px;
}
#player1 {
top: 250px;
left: 19px;
}
#name2 {
top: 188px;
left: 241px;
}
#player2 {
top: 20px;
left: 241px;
}
#name3 {
top: 418px;
left: 816px;
}
#player3 {
top: 250px;
left: 816px;
}
.chosendiv {
outline: 1px solid white;
}
.hide {
display: none;
}
.oldchess {
z-index: 1000;
}
.newchess {
z-index: 100;
}
#timeinterval {
position: absolute;
top: 640px;
left: 720px;
width: 40px;
height: 30px;
border: 1px solid red;
color: White;
font-size: 24px;
}
</style>
</head>
<body>
<div id="currentseat" class="hide"><%=currentseat %></div>
<div id="currentplayer" class="hide"><%=playerid %></div>
<div id="currentposition" class="hide"></div>
<div id="totalplayer" class="hide"><%=totalplayer %></div>
<div id="showtest3">
</div>
<div style="position: relative;">
<div id="timeinterval"></div>
<div class="headimg" id="player0" seatid=""></div>
<div class="nickname" id="name0" seatid=""></div>
<div class="headimg" id="player1" seatid=""></div>
<div class="nickname" id="name1" seatid=""></div>
<div class="headimg" id="player2" seatid=""></div>
<div class="nickname" id="name2" seatid=""></div>
<div class="headimg" id="player3" seatid=""></div>
<div class="nickname" id="name3" seatid=""></div>
<div class="test" id="center">
</div>
<div class="test" id="left">
</div>
<div class="test" id="top">
</div>
<div class="test" id="right">
</div>
<div class="test" id="bottom">
</div>
<img src="militarychess/ChessBoard.png" />
</div>
<input type="button" value="准 备" id="getready" />
<!--<input type="button" value="退 出" id="quit"/>-->
<div id="showtest" class="hide">
</div>
<div id="showtest2" class="hide" style="border: 1px solid red;">
</div>
</body>
<script language="javascript" type="text/javascript">
//棋子对象
//player 棋子属于哪个玩家
//chesstype 棋子的种类,司令、军长等
var chesspieces = function (player, chesstype) {
this.player = player;
this.chesstype = chesstype;
}
///////////////////////////////////////////判断需要拐弯的格子//////////////////////////////////
//4个方向上的增量,仅仅用于下面的方法
var specialDirection = new Array(new Array(0, -1), new Array(-1, 0), new Array(0, 1), new Array(1, 0));
//判断拐弯格子的通用方法,仅仅用在specialArray数组中
function specialFun(row, col, direIndex) {
var rowadd = specialDirection[direIndex][0];
var coladd = specialDirection[direIndex][1];
var temprow = row, tempcol = col;
while (true) {
var tempchess = chessboardArray[temprow + rowadd][tempcol + coladd];
var chesstype = tempchess.type;
//如果是兵站
if (chesstype == 1) {
//如果没棋
if (tempchess.haspieces == 0) {
effectiveArray.push(new Array(temprow + rowadd, tempcol + coladd));
temprow = temprow + rowadd;
tempcol = tempcol + coladd;
}
//说明有棋
else {
//如果不是友方的棋子
if (tempchess.chesspieces.player != playerArray[playerDirectionArray[0]] && tempchess.chesspieces.player != playerArray[playerDirectionArray[2]]) {
effectiveArray.push(new Array(temprow + rowadd, tempcol + coladd));
break
}
//是友方的棋子
else {
break;
}
}
}
//不是兵站
else {
break;
}
}
}
//针对8处拐弯判断的方法数组
var specialArray = new Array(
//不需要判断
function () {
},
//右下角,向上
function () {
specialFun(10, 10, 2);
},
//右下角,向左
function () {
specialFun(10, 10, 3);
},
//右上角,向左
function () {
specialFun(6, 10, 1);
},
//右上角,向下
function () {
specialFun(6, 10, 2);
},
//左上角,向下
function () {
specialFun(6, 6, 0);
},
//左上角,向右
function () {
specialFun(6, 6, 1);
},
//左下角,向右
function () {
specialFun(10, 6, 3);
},
//左下角,向上
function () {
specialFun(10, 6, 0);
}
);
///////////////////////////////////////////判断需要拐弯的格子//////////////////////////////////
//不同类型棋盘格子判断有效落子点位的方法数组
var checkMethodArray = new Array(
//0 中间区域的兵站之间的格子,什么都不用做
function (row, col) {
},
//1 铁道上的兵站,最复杂的判断
function (row, col) {
//先判断左上,右上,左下,右下 4个方向
var temparray = new Array(new Array(row - 1, col - 1), new Array(row - 1, col + 1), new Array(row + 1, col - 1), new Array(row + 1, col + 1));
for (var i = 0; i < temparray.length; i++) {
var tempchess = chessboardArray[temparray[i][0]][temparray[i][1]];
//如果是营,并且其中没有棋子
if (tempchess.type == 2 && tempchess.haspieces == 0) {
effectiveArray.push(temparray[i]);
}
}
//用来标记转弯方式
var special = 0;
//是不是点击的是特殊位置,需要额外判断转弯格子
if (row == 11 && col == 10) { special = 1; }
if (row == 10 && col == 11) { special = 2; }
if (row == 6 && col == 11) { special = 3; }
if (row == 5 && col == 10) { special = 4; }
if (row == 5 && col == 6) { special = 5; }
if (row == 6 && col == 5) { special = 6; }
if (row == 10 && col == 5) { special = 7; }
if (row == 11 && col == 6) { special = 8; }
//判断上下左右4个方向
//这个数组表示的是行与列的增量,从而可以一路判断过去
var temparray = new Array(new Array(0, -1), new Array(-1, 0), new Array(0, 1), new Array(1, 0));
for (var i = 0; i < temparray.length; i++) {
var rowadd = temparray[i][0];
var coladd = temparray[i][1];
var temprow = row;
var tempcol = col;
//用来标记是否经过了兵站,经过的话,就不能再进入营等地方了
var flag = 0;
//用迭代去不停遍历,而不是递归
while (true) {
//如果判断到特殊位置,并且方向也正确,特殊位置上没有棋子的话,那就要判断额外的转弯格子
if ((temprow + rowadd) == 11 && (tempcol + coladd) == 10 && i == 1 && chessboardArray[temprow + rowadd][tempcol + coladd].haspieces == 0) { special = 1; }
if ((temprow + rowadd) == 10 && (tempcol + coladd) == 11 && i == 0 && chessboardArray[temprow + rowadd][tempcol + coladd].haspieces == 0) { special = 2; }
if ((temprow + rowadd) == 6 && (tempcol + coladd) == 11 && i == 0 && chessboardArray[temprow + rowadd][tempcol + coladd].haspieces == 0) { special = 3; }
if ((temprow + rowadd) == 5 && (tempcol + coladd) == 10 && i == 3 && chessboardArray[temprow + rowadd][tempcol + coladd].haspieces == 0) { special = 4; }
if ((temprow + rowadd) == 5 && (tempcol + coladd) == 6 && i == 3 && chessboardArray[temprow + rowadd][tempcol + coladd].haspieces == 0) { special = 5; }
if ((temprow + rowadd) == 6 && (tempcol + coladd) == 5 && i == 2 && chessboardArray[temprow + rowadd][tempcol + coladd].haspieces == 0) { special = 6; }
if ((temprow + rowadd) == 10 && (tempcol + coladd) == 5 && i == 2 && chessboardArray[temprow + rowadd][tempcol + coladd].haspieces == 0) { special = 7; }
if ((temprow + rowadd) == 11 && (tempcol + coladd) == 6 && i == 1 && chessboardArray[temprow + rowadd][tempcol + coladd].haspieces == 0) { special = 8; }
var chesstype = chessboardArray[temprow + rowadd][tempcol + coladd].type;
//如果是-1,说明没路走了
if (chesstype == -1) {
break;
}
//如果是0,就跳过这一格,继续判断下一格
else if (chesstype == 0) {
temprow = temprow + rowadd;
tempcol = tempcol + coladd;
}
//如果不是-1,就说明是只能走一步的地方
else if (chesstype != 1) {
var tempchess = chessboardArray[temprow + rowadd][tempcol + coladd];
//如果没有经过兵站,那就说明可以走
if (flag == 0) {
//是营
if (tempchess.type == 2) {
//如果其中没有棋子
if (tempchess.haspieces == 0) {
effectiveArray.push(new Array(temprow + rowadd, tempcol + coladd));
}
}
//不是营
else {
//如果不是友方的棋子
if (tempchess.chesspieces.player != playerArray[playerDirectionArray[0]] && tempchess.chesspieces.player != playerArray[playerDirectionArray[2]]) {
effectiveArray.push(new Array(temprow + rowadd, tempcol + coladd));
}
}
}
break;
}
//说明是兵站,先改变flag,然后判断棋格上是否有棋子
else {
var tempchess = chessboardArray[temprow + rowadd][tempcol + coladd];
flag = 1;
//如果该棋格上有棋子,那就不能继续往下走了
if (chessboardArray[temprow + rowadd][tempcol + coladd].haspieces == 1) {
//如果不是友方的棋子
if (tempchess.chesspieces.player != playerArray[playerDirectionArray[0]] && tempchess.chesspieces.player != playerArray[playerDirectionArray[2]]) {
effectiveArray.push(new Array(temprow + rowadd, tempcol + coladd));
break
}
//是友方的棋子
else {
break;
}
}
//没有棋子
else {
effectiveArray.push(new Array(temprow + rowadd, tempcol + coladd));
}
temprow = temprow + rowadd;
tempcol = tempcol + coladd;
}
}
//判断拐弯的棋子
specialArray[special]();
}
},
//2 营 周围八个格子
function (row, col) {
for (var i = row - 1; i <= row + 1; i++) {
for (var j = col - 1; j <= col + 1; j++) {
if (i != row || j != col) {
var tempchess = chessboardArray[i][j];
//如果判断的格子是营
if (tempchess.type == 2) {
//如果其中没有棋子
if (tempchess.haspieces == 0) {
effectiveArray.push(new Array(i, j));
}
}
//如果不是营
else {
//如果没有棋子
if (tempchess.haspieces == 0) {
effectiveArray.push(new Array(i, j));
}
//有棋子,但是不是己方的棋子
else if (tempchess.chesspieces.player != playerArray[playerDirectionArray[0]] && tempchess.chesspieces.player != playerArray[playerDirectionArray[2]]) {
effectiveArray.push(new Array(i, j));
}
}
}
}
}
},
//3 最中间营上下左右的四个兵站 上下左右4个
function (row, col) {
var temparray = new Array(new Array(row, col - 1), new Array(row, col + 1), new Array(row - 1, col), new Array(row + 1, col));
for (var i = 0; i < temparray.length; i++) {
var tempchess = chessboardArray[temparray[i][0]][temparray[i][1]];
//如果判断的格子是营
if (tempchess.type == 2) {
//如果其中没有棋子
if (tempchess.haspieces == 0) {
effectiveArray.push(temparray[i]);
}
}
//如果不是营
else {
//如果没有棋子
if (tempchess.haspieces == 0) {
effectiveArray.push(temparray[i]);
}
//有棋子,但是不是己方的棋子
else if (tempchess.chesspieces.player != playerArray[playerDirectionArray[0]] && tempchess.chesspieces.player != playerArray[playerDirectionArray[2]]) {
effectiveArray.push(temparray[i]);
}
}
}
},
//4 最下层的3个兵站 判断上下左右4个方向,能落子的格子
function (row, col) {
//将4个点位放入数组方便循环
var temparray = new Array(new Array(row, col - 1), new Array(row, col + 1), new Array(row - 1, col), new Array(row + 1, col));
for (var i = 0; i < temparray.length; i++) {
//判断的格子在整个棋盘之内
if (temparray[i][0] >= 0 && temparray[i][0] <= 16 && temparray[i][1] >= 0 && temparray[i][1] <= 16) {
var tempchessboard = chessboardArray[temparray[i][0]][temparray[i][1]];
//判断的格子的type不是-1,并且不是自己或者对面的棋子,说明是可以落子的
if (tempchessboard.type != -1 && tempchessboard.chesspieces.player != playerArray[playerDirectionArray[0]] && tempchessboard.chesspieces.player != playerArray[playerDirectionArray[2]]) {
effectiveArray.push(temparray[i]);
}
}
}
},
//5 放军旗的两个格子 什么都不用做
function (row, col) {
});
//棋盘对象
//chesspieces 棋盘上的棋子
//type 棋盘格子的类型,包括铁道上的兵站,营等
// -1 无法落子的格子
// 0 中间区域的兵站之间的格子
// 1 铁道上的兵站
// 2 营
// 3 最中间营上下左右的四个兵站
// 4 最下层的3个兵站
// 5 放军旗的两个格子
//haspieces 当前棋盘格子上是否有棋子
var chessboard = function (chesspieces, type, haspieces) {
this.chesspieces = chesspieces;
this.type = type;
this.haspieces = haspieces;
this.checkmethod = function (row, col) {
effectiveArray = new Array();
//如果不是工兵
if (this.type != -1 && this.type != 0 && this.chesspieces.chesstype != 9) {
//判断哪些点位是可以落子的
checkMethodArray[type](row, col);
$(".chessback").css("backgroundColor", "transparent");
for (var i = 0; i < effectiveArray.length; i++) {
$(".chessback").filter(function (index) {
return $(this).attr("row") == effectiveArray[i][0] && $(this).attr("col") == effectiveArray[i][1];
}).css("backgroundColor", "red");
$(".chessback").filter(function (index) {
return $(this).attr("row") == effectiveArray[i][0] && $(this).attr("col") == effectiveArray[i][1];
}).fadeTo(0, 0.3);
}
}
//如果点击的是工兵
if (this.type != -1 && this.type != 0 && this.chesspieces.chesstype == 9) {
//如果在铁道上
if (this.type == 1) {
//方向数组
var diarray = new Array(new Array(0, -1), new Array(-1, 0), new Array(0, 1), new Array(1, 0));
for (var i = 0; i < 4; i++) {
var temprow = row + diarray[i][0];
var tempcol = col + diarray[i][1];
var tempchess = chessboardArray[temprow][tempcol];
//如果是在铁道中间,就多往前算一格
if (tempchess.type == 0) {
temprow = temprow + diarray[i][0];
tempcol = tempcol + diarray[i][1];
tempchess = chessboardArray[temprow][tempcol];
}
//如果判断的格子是在铁道上
if (tempchess.type == 1) {
//如果有棋子
if (tempchess.haspieces == 1) {
//如果不是友方的棋子
if (tempchess.chesspieces.player != playerArray[playerDirectionArray[0]] && tempchess.chesspieces.player != playerArray[playerDirectionArray[2]]) {
effectiveArray.push(new Array(temprow, tempcol));
}
}
else {
checkGongBing(temprow, tempcol);
//effectiveArray.push(new Array(temprow, tempcol));
}
}
}
}
//按照其他棋子的步骤再计算一边
checkMethodArray[type](row, col);
//alert(effectiveArray.length);
$(".chessback").css("backgroundColor", "transparent");
for (var i = 0; i < effectiveArray.length; i++) {
$(".chessback").filter(function (index) {
return $(this).attr("row") == effectiveArray[i][0] && $(this).attr("col") == effectiveArray[i][1];
}).css("backgroundColor", "red");
$(".chessback").filter(function (index) {
return $(this).attr("row") == effectiveArray[i][0] && $(this).attr("col") == effectiveArray[i][1];
}).fadeTo(0, 0.3);
}
}
}
}
function checkGongBing(row, col) {
//到这一步,说明检查的位置是没有棋子的,肯定符合要求
effectiveArray.push(new Array(row, col));
//方向数组
var diarray = new Array(new Array(0, -1), new Array(-1, 0), new Array(0, 1), new Array(1, 0));
for (var i = 0; i < 4; i++) {
var temprow = row + diarray[i][0];
var tempcol = col + diarray[i][1];
var tempchess = chessboardArray[temprow][tempcol];
//如果是在铁道中间,就多往前算一格
if (tempchess.type == 0) {
temprow = temprow + diarray[i][0];
tempcol = tempcol + diarray[i][1];
tempchess = chessboardArray[temprow][tempcol];
}
//如果判断的格子在铁道上
if (tempchess.type == 1) {
//如果已经保存过了那就不要再计算了
//检测是否已经被收录了
var flag = 0;
for (var j = 0; j < effectiveArray.length; j++) {
//alert("j:" + j + " temprow:" + temprow + " tempcol:" + tempcol + " effrow:" + effectiveArray[j][0] + " effcol:" + effectiveArray[j][1]);
if (temprow == effectiveArray[j][0] && tempcol == effectiveArray[j][1]) {
flag = 1;
}
}
//如果还没被收录
if (flag == 0) {
//如果有棋子
if (tempchess.haspieces == 1) {
//如果不是友方的棋子
if (tempchess.chesspieces.player != playerArray[playerDirectionArray[0]] && tempchess.chesspieces.player != playerArray[playerDirectionArray[2]]) {
effectiveArray.push(new Array(temprow, tempcol));
}
}
else {
//进行递归的判断
checkGongBing(temprow, tempcol);
}
}
}
}
}
var chessboardArray = new Array(
//0
new Array(new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, 4, 0), new chessboard(null, 5, 0), new chessboard(null, 4, 0), new chessboard(null, 5, 0), new chessboard(null, 4, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0)),
//1
new Array(new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0)),
//2
new Array(new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, 1, 0), new chessboard(null, 2, 0), new chessboard(null, 3, 0), new chessboard(null, 2, 0), new chessboard(null, 1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0)),
//3
new Array(new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, 1, 0), new chessboard(null, 3, 0), new chessboard(null, 2, 0), new chessboard(null, 3, 0), new chessboard(null, 1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0)),
//4
new Array(new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, 1, 0), new chessboard(null, 2, 0), new chessboard(null, 3, 0), new chessboard(null, 2, 0), new chessboard(null, 1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0)),
//5
new Array(new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0)),
//6
new Array(new chessboard(null, 4, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 0, 0), new chessboard(null, 1, 0), new chessboard(null, 0, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 4, 0)),
//7
new Array(new chessboard(null, 5, 0), new chessboard(null, 1, 0), new chessboard(null, 2, 0), new chessboard(null, 3, 0), new chessboard(null, 2, 0), new chessboard(null, 1, 0), new chessboard(null, 0, 0), new chessboard(null, -1, 0), new chessboard(null, 0, 0), new chessboard(null, -1, 0), new chessboard(null, 0, 0), new chessboard(null, 1, 0), new chessboard(null, 2, 0), new chessboard(null, 3, 0), new chessboard(null, 2, 0), new chessboard(null, 1, 0), new chessboard(null, 5, 0)),
//8
new Array(new chessboard(null, 4, 0), new chessboard(null, 1, 0), new chessboard(null, 3, 0), new chessboard(null, 2, 0), new chessboard(null, 3, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 0, 0), new chessboard(null, 1, 0), new chessboard(null, 0, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 3, 0), new chessboard(null, 2, 0), new chessboard(null, 3, 0), new chessboard(null, 1, 0), new chessboard(null, 4, 0)),
//9
new Array(new chessboard(null, 5, 0), new chessboard(null, 1, 0), new chessboard(null, 2, 0), new chessboard(null, 3, 0), new chessboard(null, 2, 0), new chessboard(null, 1, 0), new chessboard(null, 0, 0), new chessboard(null, -1, 0), new chessboard(null, 0, 0), new chessboard(null, -1, 0), new chessboard(null, 0, 0), new chessboard(null, 1, 0), new chessboard(null, 2, 0), new chessboard(null, 3, 0), new chessboard(null, 2, 0), new chessboard(null, 1, 0), new chessboard(null, 5, 0)),
//10
new Array(new chessboard(null, 4, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 0, 0), new chessboard(null, 1, 0), new chessboard(null, 0, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 4, 0)),
//11
new Array(new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0)),
//12
new Array(new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, 1, 0), new chessboard(null, 2, 0), new chessboard(null, 3, 0), new chessboard(null, 2, 0), new chessboard(null, 1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0)),
//13
new Array(new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, 1, 0), new chessboard(null, 3, 0), new chessboard(null, 2, 0), new chessboard(null, 3, 0), new chessboard(null, 1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0)),
//14
new Array(new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, 1, 0), new chessboard(null, 2, 0), new chessboard(null, 3, 0), new chessboard(null, 2, 0), new chessboard(null, 1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0)),
//15
new Array(new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, 1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0)),
//16
new Array(new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, 4, 0), new chessboard(null, 5, 0), new chessboard(null, 4, 0), new chessboard(null, 5, 0), new chessboard(null, 4, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0), new chessboard(null, -1, 0))
);
//画出测试棋盘的类型
for (var i = 0; i < 17; i++) {
for (var j = 0; j < 17; j++) {
$("#showtest").append($("<div style='width:25px;height:25px;float:left;text-align:center;'>" + chessboardArray[i][j].type + "</div>"));
}
$("#showtest").append($("<div style='clear:both;'></div>"));
}
//存放图片的文件夹名
var imgfile = "militarychess";
//五个部分的坐标位置数组
var bottomPosition = new Array(); //底部坐标数组
var leftPosition = new Array(); //左边坐标数组
var rightPosition = new Array(); //右边坐标数组
var topPosition = new Array(); //顶部坐标数组
var centerPosition = new Array(); //中部坐标数组
//坐标数组,用来通过循环确定使用哪个坐标
var positionArray = new Array(bottomPosition, leftPosition, topPosition, rightPosition);
//div数组,用来通过循环确定添加到哪个div中
var divArray = new Array($("#bottom"), $("#left"), $("#top"), $("#right"));
//棋子数组,每一个数组下标对应一种棋的图片名称,方便于图片显示
var chessArray = new Array("zhadan", "siling", "junzhang", "shizhang", "lvzhang", "tuanzhang", "yingzhang", "lianzhang", "paizhang", "gongbing", "dilei", "junqi");
//方向数组,此数组不与上面玩家标识对应,仅仅用于方便图片的显示
var directionArray = new Array("", "l", "", "r");
//数组转换公式数组,在绘制棋子时用eval函数转换
//详细说明:
//本来是作两维数组进行转换,但是由于json作两维数组比较麻烦,所以现在变为两个一维数组进行转换
//若原先的下标为 x ,转换后的下标为 i
//底部:不需要进行旋转,所以 i = x
//左边:需要顺势针旋转90度,所以 i = (x % col) * row + ( row - 1 - parseInt(x / col)) 这里必须用parseInt,因为要取整
//对面:顺时针旋转180度,所以 i = col * row - 1 - x
//右边:逆时针旋转90度,所以 i = (col - 1 - x % col) * row + parseInt(x / col)
var row = 6, col = 5;
var changeArray = new Array(
"i = x",
"i = (x % " + col + ")*" + row + "+ (" + row + "- 1 - parseInt(x / " + col + "))",
"i = " + (row * col - 1) + " - x",
"i = (" + col + " - 1 - x % " + col + ") * " + row + " + parseInt(x / " + col + ")");
//将点位数组与最大的棋盘点位数组对应起来
var changeArray2 = new Array(
new Array("m = parseInt(i / " + col + ") + 11", "n = i % " + col + " + 6"),
new Array("m = parseInt(i / " + row + ") + 6", "n = i % " + row),
new Array("m = parseInt(i / " + col + ")", "n = i % " + col + " + 6"),
new Array("m = parseInt(i / " + row + ") + 6", "n = i % " + row + " + 11"),
new Array("m = 2 * parseInt((x - 30) / 3) + 6", "n = 2 * ((x - 30) % 3) + 6")
);
///////////////////////下面3个数组相互关联//////////////////////////////
//背景图片数组
var backArray = new Array("ChessmanB", "ChessmanG", "ChessmanO", "ChessmanP");
//玩家id数组
var totalplayer = $("#totalplayer").text();
var playerArray = totalplayer.split(",");
//玩家位置数组,下标0表示自己,下标1表示左边,下标2表示对面,下标3表示右边
//数组的值对应playerArray数组的下标 和 backArray数组的下标,表示玩家的id和对应的颜色
//通过修改这个数组,来改变棋子视角的转换
var playerDirectionArray = new Array(0, 1, 2, 3);
////////////////////////////////////////////////////////////////////////
//整个棋盘背景的点位数组
var wholePositionArray = new Array();
drawChessBoardDiv();
//绘制整个棋盘div
function drawChessBoardDiv() {
bottomPosition.splice(0, bottomPosition.length); //底部坐标数组
leftPosition.length = 0; //左边坐标数组
rightPosition.length = 0; //右边坐标数组
topPosition.length = 0; //顶部坐标数组
centerPosition.length = 0; //中间坐标数组
//上下位置的棋谱坐标
for (var i = 0; i < 6; i++) {
for (var j = 0; j < 5; j++) {
var tempdiv = $("<div class='buttomChess test chessback' row='" + (11 + i) + "' col='" + (6 + j) + "' style='top:" + (i * 39 - 2) + "px;left:" + (j * 40 + 7) + "px;'></div>");
$("#bottom").append(tempdiv);
var tempdiv = $("<div class='buttomChess test chessback' row='" + i + "' col='" + (6 + j) + "' style='top:" + (i * 39 - 2) + "px;left:" + (j * 40 + 7) + "px;'></div>");
$("#top").append(tempdiv);
bottomPosition.push(new Array(i * 39 - 2, j * 40 + 7));
topPosition.push(new Array(i * 39 - 2, j * 40 + 7));
}
}
//左右位置的棋谱坐标
for (var i = 0; i < 5; i++) {
for (var j = 0; j < 6; j++) {
var tempdiv = $("<div class='leftChess test chessback' row='" + (6 + i) + "' col='" + (11 + j) + "' style='top:" + (i * 40 + 7) + "px;left:" + (j * 39 - 2) + "px;'></div>");
$("#right").append(tempdiv);
var tempdiv = $("<div class='leftChess test chessback' row='" + (6 + i) + "' col='" + j + "' style='top:" + (i * 40 + 7) + "px;left:" + (j * 39 - 2) + "px;'></div>");
$("#left").append(tempdiv);
leftPosition.push(new Array(i * 40 + 7, j * 39 - 2));
rightPosition.push(new Array(i * 40 + 7, j * 39 - 2));
}
}
//中间位置的棋谱坐标
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) {
var tempdiv = $("<div class='buttomChess test chessback' row='" + (6 + i * 2) + "' col='" + (6 + j * 2) + "' style='top:" + (i * 76 + 15) + "px;left:" + (j * 80 + 7) + "px;'></div>");
$("#center").append(tempdiv);
centerPosition.push(new Array(i * 76 + 15, j * 80 + 7));
}
}
//设置初始的键盘点击事件
SetDivClickType0();
}
//设置div的透明度
//$(".test").fadeTo(0, 0.3);
//当前可以落子的格子
var effectiveArray = new Array();
//是否“拿起”了一个棋子
var isChessLifted = null;
//获取的JSON格式数据
//因为数据太长容易瞎眼,所以先分成几部分做拼接
// var positionjf = '{"identity":1,"position":{';
// var positionj1 = '"p1111":[{"id":"p1111","type":"1"},{"id":"p1111","type":"2"},{"id":"p1111","type":"3"},{"id":"p1111","type":"3"},{"id":"p1111","type":"4"},{"id":"p1111","type":"4"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"5"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"5"},{"id":"p1111","type":"6"},{"id":"p1111","type":"6"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"7"},{"id":"p1111","type":"7"},{"id":"p1111","type":"7"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"8"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"8"},{"id":"p1111","type":"10"},{"id":"p1111","type":"10"},{"id":"p1111","type":"10"},{"id":"p1111","type":"9"},{"id":"p1111","type":"9"},{"id":"p1111","type":"0"},{"id":"p1111","type":"11"},{"id":"p1111","type":"9"},{"id":"p1111","type":"8"},{"id":"p1111","type":"0"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"-1"}],';
// var positionj2 = '"p2222":[{"id":"p2222","type":"1"},{"id":"p2222","type":"2"},{"id":"p2222","type":"3"},{"id":"p2222","type":"3"},{"id":"p2222","type":"4"},{"id":"p2222","type":"4"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"5"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"5"},{"id":"p2222","type":"6"},{"id":"p2222","type":"6"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"7"},{"id":"p2222","type":"7"},{"id":"p2222","type":"7"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"8"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"8"},{"id":"p2222","type":"10"},{"id":"p2222","type":"10"},{"id":"p2222","type":"10"},{"id":"p2222","type":"9"},{"id":"p2222","type":"9"},{"id":"p2222","type":"0"},{"id":"p2222","type":"11"},{"id":"p2222","type":"9"},{"id":"p2222","type":"8"},{"id":"p2222","type":"0"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"-1"}],';
// var positionj3 = '"p3333":[{"id":"p3333","type":"1"},{"id":"p3333","type":"2"},{"id":"p3333","type":"3"},{"id":"p3333","type":"3"},{"id":"p3333","type":"4"},{"id":"p3333","type":"4"},{"id":"p3333","type":"-1"},{"id":"p3333","type":"5"},{"id":"p3333","type":"-1"},{"id":"p3333","type":"5"},{"id":"p3333","type":"6"},{"id":"p3333","type":"6"},{"id":"p3333","type":"-1"},{"id":"p3333","type":"7"},{"id":"p3333","type":"7"},{"id":"p3333","type":"7"},{"id":"p3333","type":"-1"},{"id":"p3333","type":"8"},{"id":"p3333","type":"-1"},{"id":"p3333","type":"8"},{"id":"p3333","type":"10"},{"id":"p3333","type":"10"},{"id":"p3333","type":"10"},{"id":"p3333","type":"9"},{"id":"p3333","type":"9"},{"id":"p3333","type":"0"},{"id":"p3333","type":"11"},{"id":"p3333","type":"9"},{"id":"p3333","type":"8"},{"id":"p3333","type":"0"},{"id":"p3333","type":"-1"},{"id":"p3333","type":"-1"},{"id":"p3333","type":"-1"},{"id":"p3333","type":"-1"},{"id":"p3333","type":"-1"},{"id":"p3333","type":"-1"},{"id":"p3333","type":"-1"},{"id":"p3333","type":"-1"},{"id":"p3333","type":"-1"}],';
// var positionj4 = '"p4444":[{"id":"p4444","type":"1"},{"id":"p4444","type":"2"},{"id":"p4444","type":"3"},{"id":"p4444","type":"3"},{"id":"p4444","type":"4"},{"id":"p4444","type":"4"},{"id":"p4444","type":"-1"},{"id":"p4444","type":"5"},{"id":"p4444","type":"-1"},{"id":"p4444","type":"5"},{"id":"p4444","type":"6"},{"id":"p4444","type":"6"},{"id":"p4444","type":"-1"},{"id":"p4444","type":"7"},{"id":"p4444","type":"7"},{"id":"p4444","type":"7"},{"id":"p4444","type":"-1"},{"id":"p4444","type":"8"},{"id":"p4444","type":"-1"},{"id":"p4444","type":"8"},{"id":"p4444","type":"10"},{"id":"p4444","type":"10"},{"id":"p4444","type":"10"},{"id":"p4444","type":"9"},{"id":"p4444","type":"9"},{"id":"p4444","type":"0"},{"id":"p4444","type":"11"},{"id":"p4444","type":"9"},{"id":"p4444","type":"8"},{"id":"p4444","type":"0"},{"id":"p4444","type":"-1"},{"id":"p4444","type":"-1"},{"id":"p4444","type":"-1"},{"id":"p4444","type":"-1"},{"id":"p4444","type":"-1"},{"id":"p4444","type":"-1"},{"id":"p4444","type":"-1"},{"id":"p4444","type":"-1"},{"id":"p4444","type":"-1"}]';
// var positionjl = '}}';
//var positionJSON = '{"identity":1,"position":{"p4444":[{"id":"p1111","type":"1"},{"id":"p1111","type":"2"},{"id":"p1111","type":"3"},{"id":"p1111","type":"3"},{"id":"p1111","type":"4"},{"id":"p1111","type":"4"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"0"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"0"},{"id":"p1111","type":"6"},{"id":"p1111","type":"6"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"7"},{"id":"p1111","type":"7"},{"id":"p1111","type":"7"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"8"},{"id":"p1111","type":"-1"},{"id":"p1111","type":"8"},{"id":"p1111","type":"10"},{"id":"p1111","type":"10"},{"id":"p1111","type":"10"},{"id":"p1111","type":"9"},{"id":"p1111","type":"9"},{"id":"p1111","type":"5"},{"id":"p1111","type":"11"},{"id":"p1111","type":"9"},{"id":"p1111","type":"8"},{"id":"p1111","type":"5"}],"p2222":[{"id":"p2222","type":"1"},{"id":"p2222","type":"2"},{"id":"p2222","type":"3"},{"id":"p2222","type":"3"},{"id":"p2222","type":"4"},{"id":"p2222","type":"4"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"0"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"0"},{"id":"p2222","type":"6"},{"id":"p2222","type":"6"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"7"},{"id":"p2222","type":"7"},{"id":"p2222","type":"7"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"8"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"8"},{"id":"p2222","type":"10"},{"id":"p2222","type":"10"},{"id":"p2222","type":"10"},{"id":"p2222","type":"9"},{"id":"p2222","type":"9"},{"id":"p2222","type":"5"},{"id":"p2222","type":"11"},{"id":"p2222","type":"9"},{"id":"p2222","type":"8"},{"id":"p2222","type":"5"}],"p3333":[{"id":"p2222","type":"1"},{"id":"p2222","type":"2"},{"id":"p2222","type":"3"},{"id":"p2222","type":"3"},{"id":"p2222","type":"4"},{"id":"p2222","type":"4"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"0"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"0"},{"id":"p2222","type":"6"},{"id":"p2222","type":"6"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"7"},{"id":"p2222","type":"7"},{"id":"p2222","type":"7"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"8"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"8"},{"id":"p2222","type":"10"},{"id":"p2222","type":"10"},{"id":"p2222","type":"10"},{"id":"p2222","type":"9"},{"id":"p2222","type":"9"},{"id":"p2222","type":"5"},{"id":"p2222","type":"11"},{"id":"p2222","type":"9"},{"id":"p2222","type":"8"},{"id":"p2222","type":"5"}],"p3333":[{"id":"p2222","type":"1"},{"id":"p2222","type":"2"},{"id":"p2222","type":"3"},{"id":"p2222","type":"3"},{"id":"p2222","type":"4"},{"id":"p2222","type":"4"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"0"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"0"},{"id":"p2222","type":"6"},{"id":"p2222","type":"6"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"7"},{"id":"p2222","type":"7"},{"id":"p2222","type":"7"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"8"},{"id":"p2222","type":"-1"},{"id":"p2222","type":"8"},{"id":"p2222","type":"10"},{"id":"p2222","type":"10"},{"id":"p2222","type":"10"},{"id":"p2222","type":"9"},{"id":"p2222","type":"9"},{"id":"p2222","type":"5"},{"id":"p2222","type":"11"},{"id":"p2222","type":"9"},{"id":"p2222","type":"8"},{"id":"p2222","type":"5"}]}}';
//var positionJSON = positionjf + positionj1 + positionj2 + positionj3 + positionj4 + positionjl;
//画出对应玩家棋盘上的所有棋子,并将其信息存入棋盘
function draw(json, target) {
//根据target确定用哪一个点位数组,放入哪一个div中
var parray = positionArray[target];
var darray = divArray[target];
//通过eval函数来取出对应于玩家的点位数组
var array = eval("json.position." + playerArray[playerDirectionArray[target]]);
//循环数组中的前30个点位
for (var x = 0; x < 30; x++) {
//因为是画左边,进行了一次旋转,所以先要把坐标进行转换
var i = eval(changeArray[target]);
//将棋子的信息与最大的棋盘数组关联
var m = eval(changeArray2[target][0]);
var n = eval(changeArray2[target][1]);
chessboardArray[m][n].chesspieces = new chesspieces(array[x].id, array[x].type);
//根据是否有棋子改变棋盘格子的属性
if (array[x].type != -1) {
chessboardArray[m][n].haspieces = 1;
}
else {
chessboardArray[m][n].haspieces = 0;
}
//如果type不等于-1,说明有棋子
if (parseInt(array[x].type) != -1) {
//如果是自己的棋子,就将具体名称画上
if (array[x].id == playerArray[playerDirectionArray[0]]) {
var img1 = $("<img class='chess selfchess newchess' index='" + x + "' src='" + imgfile + "/" + chessArray[parseInt(array[x].type)] + directionArray[target] + ".png' style='top:" + parray[i][0] + "px;left:" + parray[i][1] + "px;'/>");
var img2 = $("<img class='chess selfchess newchess' src='" + imgfile + "/" + backArray[playerDirectionArray[0]] + directionArray[target] + ".png' style='top:" + parray[i][0] + "px;left:" + parray[i][1] + "px;'/>");
darray.append(img2);
darray.append(img1);
}
//如果不是自己的棋子,就画一个背景色
else {
//判断应该画哪一个背景色
var currentDraw = -1;
for (var j = 0; j < backArray.length; j++) {
if (playerArray[j] == array[x].id) {
currentDraw = j;
break;
}
}
var img3 = $("<img class='chess newchess' src='" + imgfile + "/" + backArray[currentDraw] + directionArray[target] + ".png' style='top:" + parray[i][0] + "px;left:" + parray[i][1] + "px;' />");
darray.append(img3);
}
}
}
//画中间的9个格子,只需要画一次
if (target == 0) {
for (var x = 30; x < 39; x++) {
//将棋子的信息与最大的棋盘数组关联
var m = eval(changeArray2[4][0]);
var n = eval(changeArray2[4][1]);
chessboardArray[m][n].chesspieces = new chesspieces(array[x].id, array[x].type);
//根据是否有棋子改变棋盘格子的属性
if (array[x].type != -1) {
chessboardArray[m][n].haspieces = 1;
}
else {
chessboardArray[m][n].haspieces = 0;
}
if (parseInt(array[x].type) != -1) {
if (array[x].id == playerArray[playerDirectionArray[0]]) {
var img1 = $("<img class='chess newchess' src='" + imgfile + "/" + chessArray[parseInt(array[x].type)] + directionArray[target] + ".png' style='top:" + centerPosition[x - 30][0] + "px;left:" + centerPosition[x - 30][1] + "px;'/>");
var img2 = $("<img class='chess newchess' src='" + imgfile + "/" + backArray[playerDirectionArray[0]] + directionArray[target] + ".png' style='top:" + centerPosition[x - 30][0] + "px;left:" + centerPosition[x - 30][1] + "px;'/>");
$("#center").append(img2);
$("#center").append(img1);
}
//如果不是自己的棋子,就画一个背景色
else {
//判断应该画哪一个背景色
var currentDraw = -1;
for (var j = 0; j < backArray.length; j++) {
if (playerArray[j] == array[x].id) {
currentDraw = j;
break;
}
}
var img3 = $("<img class='chess newchess' src='" + imgfile + "/" + backArray[currentDraw] + directionArray[target] + ".png' style='top:" + centerPosition[x - 30][0] + "px;left:" + centerPosition[x - 30][1] + "px;' />");
$("#center").append(img3);
}
}
}
}
}
//画出测试棋盘的棋子类型
for (var i = 0; i < 17; i++) {
for (var j = 0; j < 17; j++) {
if (chessboardArray[i][j].chesspieces != null) {
$("#showtest2").append($("<div style='width:70px;height:70px;float:left;text-align:center;'>" + chessboardArray[i][j].chesspieces.player + " :" + chessboardArray[i][j].chesspieces.chesstype + " :" + chessboardArray[i][j].haspieces + "</div>"));
}
else {
$("#showtest2").append($("<div style='width:70px;height:70px;float:left;text-align:center;'>00</div>"));
}
}
$("#showtest2").append($("<div style='clear:both;'></div>"));
}
//判断当前用户的座位号,改变视角
var value = $("#currentseat").text();
switch (parseInt(value)) {
case 0:
{
playerDirectionArray = new Array(0, 1, 2, 3);
modifyDivSeat()
} break;
case 1:
{
playerDirectionArray = new Array(1, 2, 3, 0);
modifyDivSeat()
} break;
case 2:
{
playerDirectionArray = new Array(2, 3, 0, 1);
modifyDivSeat()
} break;
case 3:
{
playerDirectionArray = new Array(3, 0, 1, 2);
modifyDivSeat()
} break;
}
/////////////////////////////////////////////////具体的下棋部分
//当前游戏所处的状态,0代表未准备,1代表已准备,2代表所有人都准备好,游戏开始
var gameProgress = 0;
//根据游戏状态改变div的点击事件
//获取用户保存的初始点位
var positionJSON = $("#currentposition").text();
var chess = <%=currentPosition%>
//画出棋子
draw(chess, 0);
//画出棋盘
drawChessBoardDiv()
//修改div和作为对应关系
function modifyDivSeat() {
for (var i = 0; i < playerDirectionArray.length; i++) {
$("#player" + i).attr("seatid", playerDirectionArray[i]);
$("#name" + i).attr("seatid", playerDirectionArray[i]);
}
}
//画出已经准备好的玩家的棋子,target指的是座位号
function drawReadyPlayer(target) {
var divnum;
//寻找和座位编号相对应的div位置
for (var y = 0; y < playerDirectionArray.length; y++) {
if (target == playerDirectionArray[y]) {
divnum = y;
}
}
for (var x = 0; x < 30; x++) {
if (x != 6 && x != 8 && x != 12 && x != 16 && x != 18) {
//根据target确定用哪一个点位数组,放入哪一个div中
var parray = positionArray[divnum];
var darray = divArray[divnum];
var i = eval(changeArray[divnum]);
var img3 = $("<img class='chess onlyback' player='" + playerArray[target] + "' src='" + imgfile + "/" + backArray[target] + directionArray[divnum] + ".png' style='top:" + parray[i][0] + "px;left:" + parray[i][1] + "px;' />");
darray.append(img3);
}
}
}
////////////////刷新用户头像 开始
var oldplayer = "";
var getPlayerInterval = setInterval(function () {
$.get("GetPlayer.ashx", {}, function (re) {
//如果玩家发生了改变
if (oldplayer != re) {
oldplayer = re;
var playerjson = JSON.parse(re);
//这里的i表示的是桌子的座位号,并不是自己看到的div相对应的位置
for (var i = 0; i < playerjson.length; i++) {
//如果不是自己,并且玩家点了准备,就画出背景
if (playerDirectionArray[0] != i && playerjson[i].ready == 1) {
drawReadyPlayer(i);
}
//改变玩家数组
var tempplayer = playerArray[i];
playerArray[i] = playerjson[i].player;
//如果某个位置有玩家
if (playerjson[i].player != "") {
//这里必须把i作为参数传入,因为座位号在后面需要用到
//而这里是异步请求,不传的话直接获取只会得到 i=4
$.get("GetPlayerInfo.ashx", { "player": playerjson[i].player, "seat": i }, function (re1) {
var infojson = JSON.parse(re1);
$(".headimg").filter("[seatid=" + infojson.seat + "]").html("<img class='face' src='playerimg/" + infojson.img + "' />");
$(".nickname").filter("[seatid=" + infojson.seat + "]").text(infojson.nickname);
})
}
else {
//清空已经存在的头像昵称棋子
$(".headimg").filter("[seatid=" + i + "]").empty();
$(".nickname").filter("[seatid=" + i + "]").text("");
$(".onlyback").filter("[player=" + tempplayer + "]").remove();
}
}
//如果4个人都准备好了那就需要开始游戏
if (playerjson[0].ready == 1 && playerjson[1].ready == 1 && playerjson[2].ready == 1 && playerjson[3].ready == 1) {
//清除所有的棋盘
$(".onlyback").remove();
$(".selfchess").remove();
//清除棋盘div的点击事件
ClearDivClick();
//设立新的计时器去获取所有玩家的点位,并且画出新的棋盘
beginInterval = setInterval(function () {
$.get("GetAllPosition.ashx", {}, function (re) {
if (totalposition != re) {
totalposition = re;
//重新绘制棋盘,这里是为了防止屏幕过分闪动
$(".newchess").addClass("oldchess");
$(".oldchess").removeClass("newchess");
//清除div点击事件
ClearDivClick();
//标记有没有输
var loseornot = true;
chess = JSON.parse(re);
//先去判断自己的军旗还在不在
var temparray = eval("chess.position." + $("#currentplayer").text());
if (temparray[26].type != 11 && temparray[28].type != 11) {
eval("chess.seat" + $("#currentseat").text() + " = 1");
//清除已经输掉的玩家的所有棋子
clearLoserChess($("#currentplayer").text());
}
eval("if(chess.seat" + $("#currentseat").text() + " == 0) loseornot = false;");
//判断游戏是否结束了
if (chess.seat0 == 1 && chess.seat2 == 1 || chess.seat1 == 1 && chess.seat3 == 1) {
if (alertornot == 1) {
alert("游戏结束");
alertornot = 0;
}
chess.identity = -2;
sendNewPosition();
resetAll();
return;
}