-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
795 lines (773 loc) · 28 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>翻转棋</title>
<link rel="stylesheet" href="css/chessboard.css" />
<link rel="stylesheet" href="css/canvas.css" />
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/ant-design-vue/1.7.3/antd.min.js"></script>
<!-- <script type="module" src="model/index.js"></script> -->
<link
href="https://cdn.bootcdn.net/ajax/libs/ant-design-vue/1.7.3/antd.css"
rel="stylesheet"
/>
</head>
<body>
<div id="app">
<div :class="{container: true, threeDimensionsOn: threeDimensionsOn}">
<div class="player">
<div
ref="player1"
class="player-hp"
:style="{ width: player1._hp/initialHp*100 + '%' }"
></div>
<div class="player-hp--ratio">{{player1._hp}}/{{initialHp}}</div>
</div>
<div class="desk-table" ref="table">
<canvas id="canvas" ref="canvas" width="421" height="421"></canvas>
<table>
<tbody>
<tr v-for="(row, rowIndex) in tableArr" :index="rowIndex">
<td
v-for="(col, colIndex) in row"
:index="colIndex"
v-on:click="moveChess(rowIndex, colIndex)"
:ref="'reftd' + rowIndex + colIndex"
>
<div class="element">
<div :class="{'chess-character': col.character !== '{}'}">{{ showName(col.character._name) }}</div>
<div
:data-attack="col.character._attack"
:data-combo="col.character._combo"
:class="{
'chess': true,
'chess-orange': col.type === 1,
'chess-blue': col.type === 2,
'chess-movable': col.type === 3,
'chess-rotate': col.reversal,
}"
>
</div>
<!-- <div v-if="col.type == 1" :class="{ chess: true, 'chess-orange': true, 'chess-rotate': col.reversal }"></div>
<div v-if="col.type == 2" :class="{ chess: true, 'chess-blue': true, 'chess-rotate': col.reversal }"></div>
<div v-if="col.type == 3" class="chess chess-movable"></div> -->
</div>
</td>
</tr>
<!-- <tr >
<td >
<div class="element">
<div class="chess chess_orange"></div>
<div class="chess chess_blue"></div>
</div>
</td>
</tr> -->
</tbody>
</table>
</div>
<div class="player">
<div
ref="player2"
class="player-hp"
:style="{ width: player2._hp/initialHp*100 + '%' }"
></div>
<div class="player-hp--ratio">{{player2._hp}}/{{initialHp}}</div>
</div>
</div>
<button v-on:click="undoClick" v-if="undoStack.length > 1">悔棋</button>
<a-modal
v-model:visible="gameOverModalVisible"
title="游戏结束"
@ok="handleGameOverOk"
>
<p>重新开始吧!</p>
</a-modal>
<div>
3D模式 <a-switch @change="on3DChange" checked-children="开" un-checked-children="关"/>
</div>
<!-- <button v-on:click="setChessTypeAction" >翻转</button> -->
</div>
</body>
<script type="module">
import { Player } from './model/player.js'
import { Liubei, Guanyu, Zhangfei } from './model/characters/index.js'
// 点击下子
// 上传github (今天)
// 计算可下子区域
// 计算翻转棋子(2.22)
// 支持悔棋,方便调整状态,每一步推入栈,bug 血量没考虑
// 增加翻转特效(2.22) 棋子对象属性?
// 增加初始血量和基础攻击力棋子(需要引入对象概念) 重写棋子12的概念?
// 血量为0判断失败 目前不为零已经判断为输了,写法变一下,判断一方血量为0再输。
// 增加血条变少的动画,渐变 complete
// 增加combo伤害和效果(周三前)
// 增加卡牌
// 增加特殊效果棋子
// 增加正营
// 增加棋子特效
// 1橙色 2蓝色 3可以落子的位置
function createArray(m, n) {
return new Array(m).fill("").map((d) => {
return new Array(n).fill("").map((o) => {
return { type: 0, reversal: true, character: {} };
});
});
}
var app = new Vue({
el: "#app",
data: {
gameOverModalVisible: false,
tableArr: null,
tableColNum: 6,
tableRowNum: 6,
tableProp: null,
lastMove: null,
undoStack: [],
player1: {},
player2: {},
initialHp: 120,
threeDimensionsOn: false,
},
computed: { },
watch: {
// player1: {
// handler(newValue, oldValue) {
// let self = this;
// if(newValue._hp === 0) {
// self.$nextTick(() => {
// self.gameOver();
// });
// }
// },
// immediate: true,
// deep: true
// },
// player2: {
// handler(newValue, oldValue) {
// let self = this;
// if(newValue._hp === 0) {
// self.$nextTick(() => {
// self.gameOver();
// });
// }
// },
// immediate: true,
// deep: true
// },
},
mounted: function () {
this.initDataDOM();
this.initCanvas();
this.initChessDesk();
},
methods: {
initDataDOM: function() {
let tableProp = this.$refs.table.getBoundingClientRect();
this.tableProp = tableProp;
},
initCanvas: function() {
const canvas = this.$refs.canvas
let context = this.context;
context = canvas.getContext('2d');
context.lineWidth = 3;
context.lineCap='round';
context.lineJoin='round';
context.strokeStyle='#fff70e';
this.context = context;
},
initChessDesk: function () {
let tableArr = createArray(6, 6);
let self = this;
tableArr[2][2].type = 1;
tableArr[2][3].type = 2;
tableArr[3][2].type = 2;
tableArr[3][3].type = 1;
console.log(tableArr);
self.tableArr = tableArr;
self.lastMove = 1;
self.$nextTick(() => {
self.calculateMovableArea(self.lastMove);
self.initPlayer();
});
// this.pushIntoUndoStack(JSON.parse(JSON.stringify(this.$data)));
},
pushIntoUndoStack: function (data) {
if (this.undoStack.length >= 3) {
this.undoStack.shift();
}
this.undoStack.push(data);
},
undoClick: function () {
let nowStep = this.undoStack.pop();
let stackLen = this.undoStack.length;
if (this.undoStack.length >= 1) {
let { tableArr, player1, player2, lastMove } = JSON.parse(
JSON.stringify(this.undoStack[stackLen - 1])
);
this.tableArr = tableArr;
this.player1 = player1;
this.player2 = player2;
this.lastMove = lastMove;
}
// this.lastMove = this.lastMove === 1 ? 2 : 1;
this.$forceUpdate();
},
showName: function (name) {
let _name = name || "";
if (_name) {
return String(_name).substr(0, 1).toUpperCase();
}
return "";
},
initChess: function () {
let arr = [Liubei, Guanyu, Zhangfei];
return arr[Math.floor((Math.random()*arr.length))];
},
computeAttack: function (nowMoveType, attack) {
// 还需要改写,加上combo的伤害
let self = this;
let chessType = nowMoveType;
let playerBeAttacked;
if (Number(chessType) === 2) {
playerBeAttacked = self.player1;
} else {
playerBeAttacked = self.player2;
}
if (playerBeAttacked._hp - attack > 0) {
playerBeAttacked._hp -= attack;
} else {
playerBeAttacked._hp = 0;
self.$nextTick(() => {
self.gameOver();
});
}
},
moveChess: function (row, col) {
let self = this;
let character = self.initChess(); // 每次选择棋子落子实现人物不同
let { type } = self.tableArr[row][col];
let nowMoveType = self.lastMove;
if (type === 3) {
if (self.lastMove == 1) {
self.setChessTypeAction(row, col, {
type: 1,
character: { ...character },
});
self.lastMove = 2;
} else if (self.lastMove == 2) {
self.setChessTypeAction(row, col, {
type: 2,
character: { ...character },
});
self.lastMove = 1;
}
self.reversiChess(row, col, nowMoveType);
// 计算伤害?在生成人物时?还是在落子后
self.computeAttack(nowMoveType, character._attack);
// 清空画布
self.clearCanvas();
// 计算新的可落子位置
self.calculateMovableArea(self.lastMove);
}
// self.pushIntoUndoStack(JSON.parse(JSON.stringify(self.$data)));
},
calculateMovableArea: function (nowMoveType) {
let self = this;
// 先清除之前的可下子区域
self.clearMovableArea();
// 现在的下子的是1还是2
// 每一颗棋子的上下左右的尽头不是自己
// 每一颗的斜边尽头不是自己
// 满足8个方向的上述条件可下子
// 先遍历每个棋子的位置,找到棋子相同类型棋子,再寻找可以落子的位置。
let tableArr = this.tableArr;
tableArr.map((row, rowIndex) => {
row.map((chess, colIndex) => {
if (chess.type === nowMoveType) {
// 找到当前已下的相同子
self.findCouldMoveArea(rowIndex, colIndex, nowMoveType);
console.log(rowIndex, colIndex);
}
return chess;
});
// tableArr[rowIndex][colIndex] = 3;
return row;
});
},
clearMovableArea: function () {
let self = this;
let tableArr = self.tableArr;
tableArr.map((row, rowIndex) => {
row.map((chess, colIndex) => {
if (chess.type === 3) {
self.setChessTypeAction(rowIndex, colIndex, { type: 0 });
}
return chess;
});
return row;
});
},
findCouldMoveArea: function (row, col, chessType) {
let self = this;
let tableArr = self.tableArr;
// 边界
let colLen = self.tableColNum;
let rowLen = self.tableRowNum;
let enemyType = chessType === 1 ? 2 : 1;
// 上下左右
/**
* 向上找
* 是自己的子或直接false
* 不是自己的子继续向上找
* 是空位置返回true且不是临近的子且临界子不能为空
* 是边界返回false
*/
// col不变 row-1 判断边界情况>0
// 上下左右判断方法一样,只是搜索规则不一样
for (let i = row - 1; i >= 0; i--) {
if (
tableArr[i][col].type === chessType ||
tableArr[row - 1][col].type === 0 ||
tableArr[row - 1][col].type === 3
) {
break;
} else if (tableArr[i][col].type === enemyType) {
continue;
} else {
self.movableAreaAction(i, col, { type: 3, reversal: false }, { row, col });
break;
}
}
for (let i = row + 1; i <= rowLen - 1; i++) {
if (
tableArr[i][col].type === chessType ||
tableArr[row + 1][col].type === 0 ||
tableArr[row + 1][col].type === 3
) {
break;
} else if (tableArr[i][col].type === enemyType) {
continue;
} else {
self.movableAreaAction(i, col, { type: 3, reversal: false }, { row, col });
break;
}
}
// 左
for (let j = col - 1; j >= 0; j--) {
if (
tableArr[row][j].type === chessType ||
tableArr[row][col - 1].type === 0 ||
tableArr[row][col - 1].type === 3
) {
break;
} else if (tableArr[row][j].type === enemyType) {
continue;
} else {
self.movableAreaAction(row, j, { type: 3, reversal: false }, { row, col });
break;
}
}
for (let j = col + 1; j <= colLen - 1; j++) {
if (
tableArr[row][j].type === chessType ||
tableArr[row][col + 1].type === 0 ||
tableArr[row][col + 1].type === 3
) {
break;
} else if (tableArr[row][j].type === enemyType) {
continue;
} else {
self.movableAreaAction(row, j, { type: 3, reversal: false }, { row, col });
break;
}
}
// 左上角
for (let i = row - 1, j = col - 1; i >= 0 && j >= 0; i--, j--) {
if (
tableArr[i][j].type === chessType ||
tableArr[row - 1][col - 1].type === 0 ||
tableArr[row - 1][col - 1].type === 3
) {
break;
} else if (tableArr[i][j].type === enemyType) {
continue;
} else {
self.movableAreaAction(i, j, { type: 3, reversal: false }, { row, col });
break;
}
}
// 右下角
for (
let i = row + 1, j = col + 1;
i <= rowLen - 1 && j <= colLen - 1;
i++, j++
) {
if (
tableArr[i][j].type === chessType ||
tableArr[row + 1][col + 1].type === 0 ||
tableArr[row + 1][col + 1].type === 3
) {
break;
} else if (tableArr[i][j].type === enemyType) {
continue;
} else {
self.movableAreaAction(i, j, { type: 3, reversal: false }, { row, col });
break;
}
}
// 左下角
for (
let i = row + 1, j = col - 1;
i <= rowLen - 1 && j >= 0;
i++, j--
) {
if (
tableArr[i][j].type === chessType ||
tableArr[row + 1][col - 1].type === 0 ||
tableArr[row + 1][col - 1].type === 3
) {
break;
} else if (tableArr[i][j].type === enemyType) {
continue;
} else {
self.movableAreaAction(i, j, { type: 3, reversal: false }, { row, col });
break;
}
}
// 右上角
for (
let i = row - 1, j = col + 1;
i >= 0 && j <= colLen - 1;
i--, j++
) {
if (
tableArr[i][j].type === chessType ||
tableArr[row - 1][col + 1].type === 0 ||
tableArr[row - 1][col + 1].type === 3
) {
break;
} else if (tableArr[i][j].type === enemyType) {
continue;
} else {
self.movableAreaAction(i, j, { type: 3, reversal: false }, { row, col });
break;
}
}
// this.$forceUpdate();
},
movableAreaAction: function(_row, _col, obj, nowRowCol) {
let self = this;
let { row, col } = nowRowCol;
let tableDOM = this.tableProp;
self.setChessTypeAction(_row, _col, obj);
// 找到当前的ref
let _reftd = self.$refs[`reftd${_row}${_col}`][0];
let now_reftd = self.$refs[`reftd${row}${col}`][0];
// 获取当前坐标
let pos = _reftd.getBoundingClientRect();
let now_pos = now_reftd.getBoundingClientRect();
// 判断是不是有人物
let _character = JSON.stringify(self.tableArr[row][col].character);
if(_character !== '{}') {
// 如果有,告诉canvas从这里划线,划到现有位置
// 计算相对位置
self.beginCanvasAnimation(pos, now_pos);
}
},
reversiChess: function (row, col, chessType) {
// 当前下子的位置和当前下子的类型
// 寻找当前下子类型相同的上下左右,中间有不同类型的子就翻转
// 遇到空直接返回false
// 为其他类型的子继续查找
// 为相同类型的子就跳出,且翻转同一行或者同一列的子
// 上
let self = this;
let tableArr = self.tableArr;
// 边界
let colLen = self.tableColNum;
let rowLen = self.tableRowNum;
let enemyType = chessType === 1 ? 2 : 1;
// 上下左右
/**
* 向上找
* 不是自己的子且连续则继续向上找
* 遇到是自己的子停止
* 是空位置直接break
* 是边界直接break
*/
// col不变 row-1 判断边界情况>0
// 上下左右判断方法一样,只是搜索规则不一样
for (let i = row - 1; i >= 0; i--) {
if (tableArr[i][col].type === chessType && i !== row - 1) {
// 寻找有效值和当前值的所有纵向的子,进行值的翻转
if (tableArr[i][col].character._combo) {
// 如果当前棋子有combo伤害,把伤害加上,直接扣除血量?
self.computeAttack(chessType, tableArr[i][col].character._combo);
}
for (let _i = row - 1; _i > i; _i--) {
self.reversiChessAction(_i, col, chessType);
}
break;
} else if (tableArr[i][col].type === enemyType) {
continue;
} else {
break;
}
}
for (let i = row + 1; i <= rowLen - 1; i++) {
if (tableArr[i][col].type === chessType && i !== row + 1) {
if (tableArr[i][col].character._combo) {
self.computeAttack(chessType, tableArr[i][col].character._combo);
}
for (let _i = row + 1; _i < i; _i++) {
self.reversiChessAction(_i, col, chessType);
}
break;
} else if (tableArr[i][col].type === enemyType) {
continue;
} else {
break;
}
}
for (let j = col - 1; j >= 0; j--) {
if (tableArr[row][j].type === chessType && j !== col - 1) {
if (tableArr[row][j].character._combo) {
self.computeAttack(chessType, tableArr[row][j].character._combo);
}
for (let _j = col - 1; _j > j; _j--) {
self.reversiChessAction(row, _j, chessType);
}
break;
} else if (tableArr[row][j].type === enemyType) {
continue;
} else {
break;
}
}
for (let j = col + 1; j <= colLen - 1; j++) {
if (tableArr[row][j].type === chessType && j !== col + 1) {
if (tableArr[row][j].character._combo) {
self.computeAttack(chessType, tableArr[row][j].character._combo);
}
for (let _j = col + 1; _j < j; _j++) {
self.reversiChessAction(row, _j, chessType);
}
break;
} else if (tableArr[row][j].type === enemyType) {
continue;
} else {
break;
}
}
for (let i = row - 1, j = col - 1; i >= 0 && j >= 0; i--, j--) {
if (
tableArr[i][j].type === chessType &&
i !== row - 1 &&
j !== col - 1
) {
if (tableArr[i][j].character._combo) {
self.computeAttack(chessType, tableArr[i][j].character._combo);
}
for (
let _i = row - 1, _j = col - 1;
_i > i && _j > j;
_i--, _j--
) {
self.reversiChessAction(_i, _j, chessType);
}
break;
} else if (tableArr[i][j].type === enemyType) {
continue;
} else {
break;
}
}
for (
let i = row + 1, j = col + 1;
i <= rowLen - 1 && j <= colLen - 1;
i++, j++
) {
if (
tableArr[i][j].type === chessType &&
i !== row + 1 &&
j !== col + 1
) {
if (tableArr[i][j].character._combo) {
self.computeAttack(chessType, tableArr[i][j].character._combo);
}
for (
let _i = row + 1, _j = col + 1;
_i < i && _j < j;
_i++, _j++
) {
self.reversiChessAction(_i, _j, chessType);
}
break;
} else if (tableArr[i][j].type === enemyType) {
continue;
} else {
break;
}
}
// 左下角
for (
let i = row + 1, j = col - 1;
i <= rowLen - 1 && j >= 0;
i++, j--
) {
if (
tableArr[i][j].type === chessType &&
i !== row + 1 &&
j !== col - 1
) {
if (tableArr[i][j].character._combo) {
self.computeAttack(chessType, tableArr[i][j].character._combo);
}
for (
let _i = row + 1, _j = col - 1;
_i < i && _j > j;
_i++, _j--
) {
self.reversiChessAction(_i, _j, chessType);
}
break;
} else if (tableArr[i][j].type === enemyType) {
continue;
} else {
break;
}
}
// 右上角
for (
let i = row - 1, j = col + 1;
i >= 0 && j <= colLen - 1;
i--, j++
) {
if (
tableArr[i][j].type === chessType &&
i !== row - 1 &&
j !== col + 1
) {
if (tableArr[i][j].character._combo) {
self.computeAttack(chessType, tableArr[i][j].character._combo);
}
for (
let _i = row - 1, _j = col + 1;
_i > i && _j < j;
_i--, _j++
) {
self.reversiChessAction(_i, _j, chessType);
}
break;
} else if (tableArr[i][j].type === enemyType) {
continue;
} else {
break;
}
}
},
setChessTypeAction: function (row, col, obj) {
let self = this;
let tableObj = self.tableArr[row][col];
self.$set(self.tableArr[row], col, Object.assign(tableObj, obj));
},
reversiChessAction: function (i, j, chessType) {
// reset character
this.setChessTypeAction(i, j, {
type: chessType,
reversal: true,
character: {},
});
},
initPlayer: function () {
let player1 = new Player("bot1", "", 1);
let player2 = new Player("bot2", "", 2);
this.player1 = player1;
this.player2 = player2;
},
gameOver: function () {
let self = this;
let player1Width = self.$refs.player1.style.width;
let player2Width = self.$refs.player2.style.width;
if (
!Number(player1Width.slice(0, -1)) ||
!Number(player2Width.slice(0, -1))
) {
self.gameOverModalVisible = true;
}
},
handleGameOverOk: function () {
let self = this;
self.clearCanvas();
self.initChessDesk();
self.gameOverModalVisible = false;
},
beginCanvasAnimation: function(pos, now_pos) {
let self = this;
let ctx = self.context;
let tableDOM = self.tableProp;
let x1 = pos.left-tableDOM.left+pos.width/2;
let y1 = pos.top-tableDOM.top+pos.height/2;
// let x2 = pos.left-tableDOM.left+pos.width/2;
// let y2 = pos.top-tableDOM.top+pos.height/2;
// let x3 = now_pos.left-tableDOM.left+now_pos.width/2;
// let y3 = now_pos.top-tableDOM.top+now_pos.height/2;
let x2 = now_pos.left-tableDOM.left+now_pos.width/2;
let y2 = now_pos.top-tableDOM.top+now_pos.height/2;
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.stroke();
// const draw = function() {
// let ctx = self.context;
// ctx.clearRect(0, 0, self.$refs.canvas.width, self.$refs.canvas.height);
// ctx.save();
// let time = new Date();
// let s = time.getMilliseconds() % 10;
// let c, d;
// c = (x2 - x1) / 4;
// d = (y2 - y1) / 4;
// ctx.beginPath();
// ctx.moveTo(x1, y1);
// // if(y1 === y2) { // 横线
// // ctx.quadraticCurveTo(x1+c,y1+10,x1+c*2,y1);
// // ctx.quadraticCurveTo(x1+c*3,y1-10,x2,y2);
// // } else if(x1 === x2) { // 竖线
// // ctx.quadraticCurveTo(x1+10,y1+d,x1,y1+d*2);
// // ctx.quadraticCurveTo(x1-10,y1+d*3,x1,y2);
// // } else if(x1 > x2 && y1 > y2) { // 左上斜线
// // ctx.lineTo(x2,y2);
// // } else if(x1 > x2 && y1 < y2) { // 左下斜线
// // ctx.lineTo(x2,y2);
// // } else if(x1 < x2 && y1 < y2) { // 右下斜线
// // ctx.quadraticCurveTo(x1+c,y1,x1+c*2,y1+d*2);
// // ctx.quadraticCurveTo(x1+c*2,y1,x1+c*2,y1+d*2);
// // ctx.quadraticCurveTo(x1+c*2,y1,x1+c*2,y1+d*2);
// // ctx.quadraticCurveTo(x1+c*2,y2,x2,y2);
// // } else if(x1 < x2 && y1 > y2) { // 左下斜线
// // ctx.lineTo(x2,y2);
// // }
// // ctx.moveTo(x1, y1);
// ctx.lineTo(x2,y2);
// ctx.stroke();
// // ctx.save();
// ctx.restore();
// window.requestAnimationFrame(draw);
// };
// window.requestAnimationFrame(draw);
},
clearCanvas: function() {
let self = this;
self.context.clearRect(0, 0, self.$refs.canvas.width, self.$refs.canvas.height);
},
on3DChange: function(checked) {
this.threeDimensionsOn = checked;
},
},
});
</script>
</html>