-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (31 loc) · 1.01 KB
/
index.js
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
$(document).ready(function() {
var game = new Game();
var message = new Message("turn", game.currentPlayer())
$(".notice").html(message.message);
$("li").on("click", function(event) {
if (!game.over()) {
var spaceIndex = parseInt($(this).attr("id"));
var status = game.status(spaceIndex);
if (status != "invalid") {
renderMove(spaceIndex, game.currentPlayer());
if (status === "win") {
renderMessage(message, "win", game.currentPlayer())
renderWin(game);
} else if (status === "continue") {
game.turnCount += 1
renderMessage(message, "turn", game.currentPlayer());
} else if (status === "draw") {
renderMessage(message, "draw", null);
$(".replay").toggle();
}
} else {
renderMessage(message, "invalidMove", null);
}
}
});
$(".replay").on("click", function(event) {
game.reset()
resetBoard(game);
renderMessage(message, "turn", game.currentPlayer())
});
});