forked from sf-squirrels-2015/Connect4-team-9
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication.js
76 lines (64 loc) · 1.76 KB
/
application.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
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
$(document).ready(function(){
click_count = 0;
// HOVER EFFECT
$(".column").each(function(index, value){
$(this).mouseenter(function(event){
event.preventDefault();
if (click_count % 2 == 0) {
$("h2").eq(index).addClass("red");
} else {
$("h2").eq(index).addClass("blue");
}
})
})
$(".column").each(function(index, value){
$(this).mouseleave(function(event){
event.preventDefault();
$("h2").eq(index).removeClass("blue").removeClass("red").addClass("empty");
})
})
// CLICKING
$(".column").each(function(index, value){
$(this).click(function(event){
event.preventDefault();
click_count += 1;
if (click_count % 2 == 0) {
$(this).find(".empty").last().removeClass("empty").addClass("blue").addClass("animated bounceInDown");
addPiece(board, index, "blue");
if (checkWin(board,"blue")){
alert("Player Blue Wins!!!!!");
clear_board();
}
}
else{
$(this).find(".empty").last().removeClass("empty").addClass("red").addClass("animated bounceInDown");
addPiece(board, index, "red");
if (checkWin(board,"red")){
alert("Player Red Wins!!!!!");
clear_board();
}
}
})
})
// RESTART
$("#restart").click(clear_board);
function clear_board(){
$("li").addClass("animated bounceOutDown").one('oanimationend animationend webkitAnimationEnd', function(event) {
$(this).removeClass('animated bounceOutDown red blue bounceInDown');
$(this).addClass('empty');
console.log(board);
// board.forEach(function(col, index) {
// col.forEach(function(spot, index) {
// spot = '';
// })
// })
for(var i = 0; i < 7; i++) {
var col = board[i];
for(var j = 0; j < 6; j++) {
col[j] = '';
}
}
console.log(board);
});
}
});