-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
44 lines (42 loc) · 1.27 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
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="static/css/chessboard-1.0.0.min.css">
<script src="static/js/jquery-3.3.1.min.js"></script>
<script src="static/js/chessboard.js"></script>
</head>
<body>
<button onClick="newGame()"> New Game </button><br/>
<div id="myBoard" style="width: 500px"></div>
<p></p>
<script type="text/javascript">
var config = {
draggable: true,
onDrop: onDrop,
dropOffBoard: "snapback",
position: "start"
}
var myBoard = Chessboard("myBoard", config)
function onDrop (source, target, piece, newPos, oldPos, orientation) {
$.get('/move_coordinate', {'source': source, 'target': target, 'piece': piece},
function(response){
if (response.includes("game over")) {
document.querySelector("p").innerText = "game over";
} else {
document.querySelector("p").innerText = "";
myBoard.position(response);
}
}
);
}
function newGame() {
$.get('/new_game',
function(response) {
document.querySelector("p").innterText = "";
myBoard.position(response);
}
);
}
</script>
</body>
</html>