-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdarkChess.html
More file actions
859 lines (783 loc) · 19.8 KB
/
darkChess.html
File metadata and controls
859 lines (783 loc) · 19.8 KB
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="shortcut icon" href="icon.png">
<title>Dark Chess</title>
</head>
<style>
body{
font-family: Courier;
background-color: #e0e0e0;
margin: 0;
padding: 0;
border: 0;
}
canvas{
/* border: 0.5px #5f5f5f solid;*/
display: block;
cursor: crosshair;
transform-origin: top left;
transform: scale(1);
position: fixed;
top: 0;
left: 0;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
//css
</style>
<body oncontextmenu="return false;">
<canvas id="mainCanvas">
瀏覽器不支援
</canvas>
<script language="JavaScript" type="text/JavaScript">
class Brick {
constructor(tabX, tabY){
this.tabX = tabX;
this.tabY = tabY;
this.x = (this.tabX - 1) * 200 + ((playBoardWidth - 800) / 2);
this.y = (this.tabY - 1) * 200 + 25;
this.w = 200;
this.h = 200;
this.color = "#111111";
this.lineWidth = 3;
}
draw(){
ctx.lineWidth = this.lineWidth;
ctx.strokeStyle = this.color;
ctx.strokeRect(this.x, this.y, this.w, this.h);
}
}
class Chess{
constructor(id, tabY, tabX, group, type){
this.id = id;
this.tabX = tabX;
this.tabY = tabY;
this.lastTabX = tabX;
this.lastTabY = tabY;
this.group = group;
this.type = type;
this.typeNo = 0;
this.clicked = false;
this.eated = false;
this.cover = true;
this.x = (this.tabX - 1) * 200 + 100 + ((playBoardWidth - 800) / 2);
this.y = (this.tabY - 1) * 200 + 100 + 25;
this.toX = this.x;
this.toY = this.y;
this.dx = 0;
this.dy = 0;
this.moveTime = 0;
this.delayEatTime = -1;//未翻開被吃的顯示時間 -1:未啟動 0:開吃 >0:倒數
this.delayEat = null;//要被吃得棋子id
this.r = 80;
this.color = "#f9d08b";
this.clickedColor = "#ffcdcd";
this.coverCloor = "#d8b455";
if(this.group == "B"){
this.fontColor = "#222222";
}else if(this.group == "R"){
this.fontColor = "#e00606";
}
//初始化棋子大小
if(this.type == "king"){
this.typeNo = 7;
}else if(this.type == "guard"){
this.typeNo = 6;
}else if(this.type == "elephant"){
this.typeNo = 5;
}else if(this.type == "horse"){
this.typeNo = 4;
}else if(this.type == "car"){
this.typeNo = 3;
}else if(this.type == "cannon"){
this.typeNo = 2;
}else if(this.type == "normal"){
this.typeNo = 1;
}
}
draw(){
if(this.delayEatTime > 0){
this.delayEatTime--;
}else if(this.delayEatTime == 0){
this.delayEat.toEated();
this.delayEat = null;
this.delayEatTime = -1;
}
if(this.delayEatTime <= 0 && (this.lastTabX != this.tabX || this.lastTabY != this.tabY)){
this.lastTabX = this.tabX;
this.lastTabY = this.tabY;
this.toX = (this.tabX - 1) * 200 + 100 + ((playBoardWidth - 800) / 2);
this.toY = (this.tabY - 1) * 200 + 100 + 25;
this.dx = (this.toX - this.x)/10;
this.dy = (this.toY - this.y)/10;
this.moveTime = 10;
}
if(this.moveTime > 0){
this.x += this.dx;
this.y += this.dy;
this.moveTime--;
console.log("move");
}else if(this.moveTime == 0){
this.dx = 0;
this.dy = 0;
this.moveTime = 0;
this.x = this.toX;
this.y = this.toY;
}
ctx.beginPath();
ctx.arc(this.x, this.y, this.r, 0, Math.PI*2, true);
ctx.closePath();
if(this.cover){
ctx.fillStyle = this.coverCloor;
}else{
if(this.clicked){
ctx.fillStyle = this.clickedColor;
}else{
ctx.fillStyle = this.color;
}
}
ctx.fill();
if(!this.cover){
ctx.font = "85px Arial";
ctx.textAlign = "center";
ctx.fillStyle = this.fontColor;
ctx.fillText(this.getChineseWord(), this.x , this.y + 34);
}
}
toEated(){
this.tabX = 99;
this.tabY = 99;
this.eated = true;
}
toDelayEated(chess){
this.delayEatTime = 25;
this.delayEat = chess;
}
getChineseWord(){
var word = "";
if(this.group == "B"){
if(this.type == "car"){
word = "車";
}else if(this.type == "horse"){
word = "馬";
}else if(this.type == "elephant"){
word = "象";
}else if(this.type == "guard"){
word = "士";
}else if(this.type == "king"){
word = "將";
}else if(this.type == "cannon"){
word = "包";
}else if(this.type == "normal"){
word = "卒";
}
}else if(this.group == "R"){
if(this.type == "car"){
word = "俥";
}else if(this.type == "horse"){
word = "傌";
}else if(this.type == "elephant"){
word = "相";
}else if(this.type == "guard"){
word = "仕";
}else if(this.type == "king"){
word = "帥";
}else if(this.type == "cannon"){
word = "炮";
}else if(this.type == "normal"){
word = "兵";
}
}
return word;
}
}
class Score {
constructor(){
this.color = "#111111";
}
draw(){
var bHp = 0;
var rHp = 0;
for(chess of chesses){
if(chess.tabX < 90){
if(chess.group == "B"){
bHp++;
}else if(chess.group == "R"){
rHp++;
}
}
}
if(bHp == 0){
this.win("紅方");
}else if(rHp == 0){
this.win("黑方");
}
}
win(name){
ctx.fillStyle = this.color;
ctx.font = "80px Arial";
ctx.textAlign = "center";
ctx.fillText(name + "獲勝!!", canvas.width / 2, canvas.height / 2 - 70);
}
}
class Tip{
constructor(x, y, str){
this.x = x;
this.y = y;
this.str = str;
this.fontSize = "60px";
this.existTime = 30;
this.color = "#111111";
this.alpha = 1;
this.dx = 0;
this.dy = -0.5;
}
draw(){
this.y += this.dy;
ctx.golbalAlpha = this.alpha * this.existTime / 50;
ctx.fillStyle = this.color;
ctx.font = this.fontSize + " Arial";
ctx.textAlign = "center";
ctx.fillText(this.str, this.x, this.y);
this.existTime--;
}
}
class Log{
constructor(chessTimeNo, id, tabX, tabY, action = "move"){
this.chessTimeNo = chessTimeNo;
this.id = id;
this.tabX = tabX;
this.tabY = tabY;
this.action = action;
}
back(){
for(chess of chesses){
if(chess.id == this.id){
if(this.action == "cover"){
chess.cover = true;
}else{
chess.tabX = this.tabX;
chess.tabY = this.tabY;
}
}
}
}
}
class Controller{
constructor(x, y, type){
this.w = 150;
this.h = 60;
this.x = x;
this.y = y;
this.centerX = this.x + (this.w / 2);
this.centerY = this.y + (this.h / 2);
this.color = "#252525";
this.type = type;
if(this.type == "replay"){
this.text = "重下";
}else if(this.type == "dark"){
this.text = "明單";
}
}
draw(){
ctx.strokeStyle = this.color;
ctx.strokeRect(this.x, this.y, this.w, this.h);
ctx.fillStyle = this.color;
ctx.font = "50px Arial";
ctx.textAlign = "center";
if(this.type == "dark"){
this.text = darkEatFlag? "明單":"暗連";
}
ctx.fillText(this.text, this.centerX, this.centerY + 20);
}
}
function createBrick(){
for(let i=1; i<=4; i++){
for(let j=1; j<=8; j++){
bricks.push(new Brick(i, j));
}
}
}
//產生0<=return<max的整數
function getRandomInt(max){
return Math.floor(Math.random() * Math.floor(max));
}
function getRandomSeries(max){
var series = [];
var first = [];
var second = [];
var no = -1;
for(let i=0; i<max; i++){
first.push(i);
}
var j = 0;
do{
no = getRandomInt(max - j);
second.push(first[no]);
first.splice(no, 1);
j++;
}while(j < max)
var k = 0;
do{
no = getRandomInt(max - k);
series.push(second[no]);
second.splice(no, 1);
k++;
}while(k < max)
return series;
}
function createChess(){
var ids = getRandomSeries(32);
var i = 0;
var groups = ["R", "B"];
for(group of groups){
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "car"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "car"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "horse"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "horse"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "elephant"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "elephant"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "guard"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "guard"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "cannon"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "cannon"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "normal"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "normal"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "normal"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "normal"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "normal"));
chesses.push(new Chess(ids[i], Math.floor(ids[i] / 4) + 1, (ids[i++] % 4) + 1, group, "king"));
}
}
function createController(){
controllers.push(new Controller(playBoardWidth - 250, 1635, "replay"));
controllers.push(new Controller(playBoardWidth - 430, 1635, "dark"));
}
function createElement(){
createBrick();
createChess();
score = new Score();
createController();
}
function draw(){
for(brick of bricks){
brick.draw();
}
for(chess of chesses){
if(chess.tabX < 90){
chess.draw();
}
}
for(tip of tips){
tip.draw();
}
score.draw();
for(controller of controllers){
if(!(controller.type == "dark" && startPlayFlag)){
controller.draw();
}
}
}
function clear(){
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
function deleteElement(){
var newTips = [];
for(tip of tips){
if(tip.existTime <= 0){
tip = null;
delete tip;
}else{
newTips.push(tip);
}
}
tips = newTips;
if(nowChessTimeNo < logs.length){
var newLogs = [];
for(log of logs){
if(log.chessTimeNo >= nowChessTimeNo){
log = null;
delete log;
}else{
newLogs.push(log);
}
}
logs = newLogs;
}
}
function showMsg(str){
tips.push(new Tip(canvas.width / 2, canvas.height / 2 - 265, str));
}
function getChess(tabX, tabY){
for(chess of chesses){
if(chess.tabX == tabX && chess.tabY == tabY){
return chess;
}
}
return null;
}
function getChessById(id){
for(chess of chesses){
if(chess.id == id){
return chess;
}
}
return null;
}
//判斷位移
function checkChessPath(chess, toX, toY){
var pathFlag = false;
var toEatedChess = getChess(toX , toY);
var x = chess.tabX;
var y = chess.tabY;
console.log(x,y,toX,toY);
if(chess.type == "cannon"){//炮
var count = 0;
if(x == toX && y > toY){
for(let i=y-1; i>toY; i--){
if(getChess(x , i) != null){
count++;
}
}
}else if(x == toX && y < toY){
for(let i=y+1; i<toY; i++){
if(getChess(x , i) != null){
count++;
}
}
}else if(y == toY && x > toX){
for(let i=x-1; i>toX; i--){
if(getChess(i , y) != null){
count++;
}
}
}else if(y == toY && x < toX){
for(let i=x+1; i<toX; i++){
if(getChess(i , y) != null){
count++;
}
}
}
if(count > 1){
return false;
}else if(count == 1){
if(toEatedChess == null){
return false;
}else{
pathFlag = true;//吃
}
}else if(count == 0){
if(toEatedChess == null){//走
if(x == toX && y + 1 == toY){
pathFlag = true;
}else if(x == toX && y - 1 == toY){
pathFlag = true;
}else if(x - 1 == toX && y == toY){
pathFlag = true;
}else if(x + 1 == toX && y == toY){
pathFlag = true;
}
}else{
return false;
}
}
}else{
if(x == toX && y + 1 == toY){
pathFlag = true;
}else if(x == toX && y - 1 == toY){
pathFlag = true;
}else if(x - 1 == toX && y == toY){
pathFlag = true;
}else if(x + 1 == toX && y == toY){
pathFlag = true;
}
}
return pathFlag;
}
//判斷大小
function checkChessEat(chess, toX, toY){
var eatFlag = false;
var toEatedChess = getChess(toX , toY);
if(toEatedChess != null){
if(chess.typeNo == 7){//將
if(toEatedChess.typeNo != 1){
eatFlag = true;
}
}else if(chess.typeNo == 2){//炮
eatFlag = true;
}else if(chess.typeNo == 1){//兵
if(toEatedChess.typeNo == 7 || toEatedChess.typeNo == 1){
eatFlag = true;
}
}else{
if(chess.typeNo >= toEatedChess.typeNo){
eatFlag = true;
}
}
}else{
eatFlag = true;
}
console.log("吃的兵太大了");
return eatFlag;
}
function onClickChess(x, y){
for(brick of bricks){
if(x > brick.x && x < brick.x + brick.w
&& y > brick.y && y < brick.y + brick.h){
var clickChess = getChess(brick.tabX, brick.tabY);
if(nowClicked){//已經選取
if(clickChess != null){//點到棋子
if(clickChess == nowChess){//點自己
//結束選取狀態
nowChess.clicked = false;
nowClicked = false;
}else if(clickChess.cover){//吃未開棋
if(darkEatFlag){//明吃
showMsg("該棋尚未翻開");
}else{//暗吃
if(checkChessPath(nowChess, brick.tabX, brick.tabY)){
//翻開加入紀錄檔
logs.push(new Log(nowChessTimeNo, clickChess.id, 0, 0, "cover"));
//翻開
clickChess.cover = false;
if(clickChess.group == nowChess.group){//暗吃同國
//結束選取狀態
nowChess.clicked = false;
nowClicked = false;
}else{//暗吃別國
if(checkChessEat(nowChess, brick.tabX, brick.tabY)){//暗吃成功
//移動前加入紀錄檔
logs.push(new Log(nowChessTimeNo, nowChess.id, nowChess.tabX, nowChess.tabY));
logs.push(new Log(nowChessTimeNo, clickChess.id, clickChess.tabX, clickChess.tabY));
nowChess.toDelayEated(clickChess);//延遲再吃掉;
//選中棋子移動
nowChess.tabX = brick.tabX;
nowChess.tabY = brick.tabY;
}else{//暗吃失敗
//結束選取狀態
nowChess.clicked = false;
nowClicked = false;
}
}
nowChessTimeNo++;
}
}
}else if(clickChess.group == nowChess.group){//點同國無效
//交換狀態
nowChess.clicked = false;
clickChess.clicked = true;
//持續選取狀態
nowChess = clickChess;
nowClicked = true;
}else{//吃
if(checkChessPath(nowChess, brick.tabX, brick.tabY) && checkChessEat(nowChess, brick.tabX, brick.tabY)){
//移動前加入紀錄檔
logs.push(new Log(nowChessTimeNo, nowChess.id, nowChess.tabX, nowChess.tabY));
logs.push(new Log(nowChessTimeNo++, clickChess.id, clickChess.tabX, clickChess.tabY));
clickChess.toEated();
//選中棋子移動
nowChess.tabX = brick.tabX;
nowChess.tabY = brick.tabY;
}
if(darkEatFlag){//明吃結束狀態 暗吃繼續
//結束選取狀態
nowChess.clicked = false;
nowClicked = false;
}
}
}else{//沒點到棋子
if(checkChessPath(nowChess, brick.tabX, brick.tabY)){
//移動前加入紀錄檔
logs.push(new Log(nowChessTimeNo++, nowChess.id, nowChess.tabX, nowChess.tabY));
//選中棋子移動
nowChess.tabX = brick.tabX;
nowChess.tabY = brick.tabY;
//結束選取狀態
nowChess.clicked = false;
nowClicked = false;
}
}
}else{//尚未選取
if(clickChess != null){//點到棋子
if(clickChess.cover){//如果還沒翻面
//移動前加入紀錄檔
logs.push(new Log(nowChessTimeNo++, clickChess.id, 0, 0, "cover"));
clickChess.cover = false;
startPlayFlag = true;//開始下棋
}else{
clickChess.clicked = true;
nowChess = clickChess;
nowClicked = true;//開始選取狀態
}
}
}
break;
}
}
if(x > controller.x && x < controller.x + controller.w
&& y > controller.y && y < controller.y + controller.h){
}
for(controller of controllers){
if(x > controller.x && x < controller.x + controller.w
&& y > controller.y && y < controller.y + controller.h){
if(controller.type == "replay"){//重下
if(nowChessTimeNo > 0){
for(log of logs){
if(log.chessTimeNo == nowChessTimeNo - 1){
log.back();
}
}
nowChessTimeNo--;
}
}else if(!startPlayFlag && controller.type == "dark"){//暗吃
if(darkEatFlag){
darkEatFlag = false;
}else{
darkEatFlag = true;
}
localStorage.setItem("darkEatFlag", darkEatFlag);
}
}
}
}
function aiWalkBug(){//爬蟲
var allGap = [];
for(ai of aiChess){
var gap = [];
for(player of playerChess){
gap.push(Math.abs(player.tabX - ai.tabX) + Math.abs(player.tabY - ai.tabY))
}
allGap.push(gap);
}
console.log(allGap);
}
function aiEatChess(chess, toChess){
console.log(chess, toChess);
if(toChess != null && chess.group != toChess.group){
toChess.toEated();
chess.tabX = toChess.tabX;
chess.tabY = toChess.tabY;
}
}
function ai(){
//
for(chess of chesses){
if(!chess.cover){
if(chess.group == aiGroup){
aiChess.push(chess);
}else{
playerChess.push(chess);
}
}
}
if(aiChess.length == 0 || getRandomInt(100) <= (aiChess.length / 16) * 100){
//翻棋
var temp = [];
for(chess of chesses){
if(chess.cover){
temp.push(chess);
}
}
var key = getRandomInt(temp.length) - 1;
temp[key].cover = false;
//組成電腦棋隊
if(aiChess.length == 0){
aiGroup = temp[key].group;
}
}else{
}
}
function main(){
time++;
clear();
draw();
deleteElement();
raf = window.requestAnimationFrame(main);
}
function init(){
//ui初始化 大小調整
var clientWidth = document.documentElement.clientWidth;
var clientHeight = document.documentElement.clientHeight;
canvas.width = playBoardWidth;
canvas.height = playBoardHeight;
if(clientWidth * (16 / 9) < clientHeight){
scale = clientWidth / playBoardWidth;
}else{
scale = clientHeight / playBoardHeight;
}
canvas.style.transform = "scale(" + scale + ")";
canvas.style.left = (clientWidth - (playBoardWidth * scale)) / 2 + "px";
fixLeft = (clientWidth - (playBoardWidth * scale)) / 2;
playBoardScale = scale;
//記憶設定
if(localStorage.getItem("darkEatFlag") != null){
if(localStorage.getItem("darkEatFlag") == "true"){
darkEatFlag = true;
}else if(localStorage.getItem("darkEatFlag") == "false"){
darkEatFlag = false;
}
}
createElement();
raf = window.requestAnimationFrame(main);
}
function restart(){
}
var canvas = document.getElementById("mainCanvas");
var ctx;
if (canvas.getContext){
ctx = canvas.getContext("2d");
}else{
alert("瀏覽器不支援");
}
var raf;
var paush;
var playBoardScale = 1;//縮放
var playBoardHeight = 1700;
var playBoardWidth = playBoardHeight * (9 / 16);
var time = 0;
var scale = 0;
var nowClicked = false;//已經選取的狀態
var nowChess = null;//現在選取的棋子
var nowChessTimeNo = 0;//現在的移動紀錄
//物件類別
var bricks = [];
var chesses = [];
var tips = [];
var logs = [];//遊戲紀錄
var score;
var controllers = [];
var aiGroup;//電腦顏色
var aiChess = [];//電腦的棋子
var playerChess = [];//玩家的棋子
var darkEatFlag = true;//是否明吃
var startPlayFlag = false;//下了第一顆子了
var fixLeft = 0;
init();
window.addEventListener("mousemove", function(e){
});
window.addEventListener("click", function(e){
e.preventDefault();//防止click與touchend衝突
var x = e.offsetX - fixLeft;
var y = e.offsetY;
onClickChess(x, y);
});
window.addEventListener("touchstart", function(e){
});
window.addEventListener("touchmove", function(e){
});
window.addEventListener("touchend", function(e){
e.preventDefault();//防止click與touchend衝突
var x = e.changedTouches[0].pageX - fixLeft;
var y = e.changedTouches[0].pageY;
onClickChess(x * (1 / scale), y * (1 / scale));
});
</script>
</body>
</html>