forked from K4us/khmer-chess-board.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
101 lines (97 loc) · 4.12 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
<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>Khmer Chess Board</title>
<script src="khmer-chess-board.bundle.js"></script>
</head>
<body>
<button onclick="toggleFullScreen();">Toggle Full Screen</button>
<br>
<button onclick="resetBoard();">Reset</button>
<br>
<button onclick="undoMove();" title="Ctrl+z">Undo</button>
<div style="height: 1000px;" id="board-container1"></div>
<div id="board-container2"></div>
<script>
var container1 = document.getElementById("board-container1");
var kcb1 = new KhmerChessBoard();
kcb1.setOptions({
width: 500,
container: container1
});
kcb1.soundManager.enable();
// kcb1.boardManager.flip();
kcb1.playManager.playEventController.addOnPlayEventListener(() => {
console.log('play');
});
kcb1.playManager.playEventController.addOnPauseEventListener(() => {
console.log('pause');
});
kcb1.boardManager.addBoardStatusEventListener((event) => {
console.log(event.message);
});
// Base64 format
kcb1.loadKpng('eyJldmVudCI6IiIsImRhdGUiOiIiLCJsb2NhdGlvbiI6IiIsInBsYXllcnMiOnsid2hpdGUiOnsiaWQiOiIiLCJuYW1lI' +
'joiIn0sImJsYWNrIjp7ImlkIjoiIiwibmFtZSI6IiJ9fSwicmVzdWx0Ijp7Imxhc3QiOnsid2hpdGVXaW4iOmZhbHNlLCJibGFja1dp' +
'biI6ZmFsc2V9LCJ3aGl0ZSI6eyJ3aW4iOjAsImRyYXciOjAsImxvc3QiOjB9fSwidGltZXIiOnsidG90YWxTZWNvbmQiOjAsImJvbnV' +
'zVGltZSI6MCwiY3VycmVudFdoaXRlIjowLCJjdXJyZW50QmxhY2siOjB9LCJtb3ZlcyI6WyJGZDNkNCIsImZlNmU1IiwiRmQ0ZDUiL' +
'CJmZjZmNSIsIlRkNWM2PDBeMTUiLCJnYzhkNyIsIlRjNmQ3PDEiLCJrZThmNyIsIkZnM2c0IiwiZmY1ZzQ8MiIsIkZoM2c0PDMiLCJm' +
'aDZoNSIsIkJoMWg1PDQiLCJmZTVlNCIsIkZmM2U0PDUiLCJmZzZnNSIsIkJoNWc1PDYiLCJiaDhoNCIsIkJnNWc4PDciLCJiaDRnNDw' +
'4IiwiQmc4aDgiLCJiZzRlNDw5IiwiQmg4aDciLCJrZjdnOCIsIlRkN2M2IiwiYmU0ZTM8MTAiLCJRZTFkMiIsImJlM2MzPDExIiwiR2' +
'YxZTIiLCJiYzNiMzwxMiIsIkhnMWYzIiwiYmIzYTM8MTMiLCJCYTFhMzwxNCIsImdmOGc3IiwiQmg3Zzc8MTUiLCJrZzhmOCIsIkJnN' +
'2E3IiwiaGI4ZDciLCJCYTdhODwxNiIsImhkN2I4IiwiQmE4Yjg8MTciLCJmYTZhNSIsIkJhM2E1PDE4IiwiZmI2YjUiLCJUYzZkNyIs' +
'ImZiNWI0IiwiQmE1ZDUiLCJ0YjRiMyoiLCJCZDVkNjwxOSIsInRiM2MyIl0sInJlbiI6IjFIR0s0LzJ0UUczLzVIMi84LzgvM0I0Lz' +
'NUNC8xQjFxMWsyIHcgS1FrcSAtLSAtLi1ALSBmZ0ZmZmZmaEZGRkZGRmJnYmhmZiJ9');
kcb1.playManager.play();
function resetBoard() {
kcb1.reset();
kcb1.playManager.play();
}
function undoMove() {
kcb1.playManager.undo();
kcb1.playManager.play();
}
// kcb1.messageManager.showMessage('hello');
// 'a'.repeat(30).split('').forEach(() => kcb1.playManager.add('12'));
// kcb.boardManager.get(63).attacked()
function toggleFullScreen() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen().then(() => {
kcb1.setFullScreen(true);
})
} else {
if (document.exitFullscreen) {
document.exitFullscreen().then(() => {
kcb1.setFullScreen(false);
})
}
}
}
document.onkeydown = function (e) {
e = e || window.event;
if (e.keyCode == '37') {
kcb1.playManager.back();
} else if (e.keyCode == '39') {
kcb1.playManager.next();
} else if (e.keyCode == '32') {
kcb1.playManager.toggle();
}
if (e.ctrlKey && e.key === 'z') {
undoMove();
}
}
</script>
<script>
if (false) {
var container2 = document.getElementById("board-container2");
var kcb2 = new KhmerChessBoard();
kcb2.setOptions({
width: 300,
container: container2
});
}
</script>
</body>
</html>