-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.js
95 lines (83 loc) · 1.79 KB
/
project.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// sets background color when color is clicked
$("#redBtn").on("click", function () {
console.log("test");
$("body").addClass("bgCol1");
});
$("#blueBtn").on("click", function () {
console.log("test");
$("body").addClass("bgCol2");
});
$("#yellowBtn").on("click", function () {
console.log("test");
$("body").addClass("bgCol3");
});
//player 1 & 2 score counter
var p1 = 0;
$(".p1Btn").on("click",function () {
p1++;
console.log(p1);
$(".display").text(p1);
outcome();
score();
});
//
//
var p2 = 0;
$(".p2Btn").on("click",function () {
p2++;
console.log(p2);
$(".display2").text(p2);
outcome();
score();
});
// function used to keep up with winner
function outcome() {
if (p1 === 15)
{
alert("Player 1 WINS!!!")
}
else if (p2 === 15)
{
alert("Player 2 WINS!!!")
}
}
function score() {
if (p1 > p2)
{
$("#winning").text("Player 1!!!")
}
else if (p1 < p2)
{
$("#winning").text("Player 2!!!")
}
else if (p1 === p2)
{
$("#winning").text("TIED!!!")
}
}
// function used for keyboard and mouse option
$("#mouse").on("click", function () {
$("#keyboard").removeAttr("disabled","");
$("#mouse").attr("disabled","");
});
$("#keyboard").on("click", function () {
$("#mouse").removeAttr("disabled","");
$("#keyboard").attr("disabled","");
//adds the ability to use keys P 7 W
document.addEventListener("keydown", function (e) {
if(e.code === "KeyW")
{
p1++;
$(".display").text(p1);
outcome();
score();
}
else if(e.code === "KeyP")
{
p2++;
$(".display2").text(p2);
outcome();
score();
}
})
});