-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
124 lines (113 loc) · 3.67 KB
/
script.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
let sumo1 = document.getElementById("playerImg1");
let sumo2 = document.getElementById("playerImg2");
let button1 = document.getElementById("button1");
let button2 = document.getElementById("button2");
let rotate1 = true;
let rotate2 = true;
let sumo1Score = document.getElementById("playerScore1");
let sumo2Score = document.getElementById("playerScore2");
let sumo1Count = 0;
let sumo2Count = 0;
let sumo1Stop = "0";
let sumo2Stop = "0";
let boxSize = document.getElementById("boxSize");
boxSize = window.getComputedStyle(boxSize);
boxSize = boxSize.width;
if (boxSize === "500px") {
sumo1Stop = "410px";
sumo2Stop = "410px";
}
else if (boxSize === "400px") {
sumo1Stop = "320px";
sumo2Stop = "320px";
}
else if (boxSize === "300px") {
sumo1Stop = "240px";
sumo2Stop = "240px";
}
// function changeMode() {
// let currentMode = document.getElementById("changeMode");
// mode = currentMode.getAttribute("src");
// console.log(mode);
// if (mode == "js/bot_Mode.js") {
// currentMode.setAttribute("src", "script.js");
// console.log(mode);
// }
// else {
// currentMode.setAttribute("src", "js/bot_Mode.js");
// console.log(mode);
// }
// console.log(mode);
// }
function music() {
var bg_song = new Audio('sound/neon_bg_song.mp3');
bg_song.play();
document.getElementById("body").removeAttribute("onclick");
}
async function move1(move) {
if (move == 1) {
button2.removeAttribute("onClick");
if (sumo1.style.paddingTop == sumo1Stop) {
winner(1);
}
else {
var audio = new Audio('sound/figth_sound.mp3');
audio.play();
if (rotate1 == true) {
sumo1.style.transform = "rotate(-2deg)";
rotate1 = false;
}
else {
sumo1.style.transform = "rotate(2deg)";
rotate1 = true;
}
sumo1.style.paddingTop = parseInt(sumo1.style.paddingTop || 0) + 10 + 'px';
sumo2.style.paddingTop = parseInt(sumo2.style.paddingTop || 0) - 10 + 'px';
button2.setAttribute("onclick", "move1(2)");
}
}
else if (move == 2) {
button1.removeAttribute("onclick");
if (sumo2.style.paddingTop == sumo2Stop) {
winner(2);
}
else {
var audio = new Audio('sound/figth_sound.mp3');
audio.play();
if (rotate2 == true) {
sumo2.style.transform = "rotate(-182deg)";
rotate2 = false;
}
else {
sumo2.style.transform = "rotate(182deg)";
rotate2 = true;
}
sumo2.style.paddingTop = parseInt(sumo2.style.paddingTop || 0) + 10 + 'px';
sumo1.style.paddingTop = parseInt(sumo1.style.paddingTop || 0) - 10 + 'px';
button1.setAttribute("onclick", "move1(1)");
}
}
}
function winner(winner) {
button1.removeAttribute("onclick");
button2.removeAttribute("onClick");
if (winner === 1) {
sumo1Count += 1;
sumo1Score.innerHTML = sumo1Count;
}
else if (winner === 2) {
sumo2Count += 1;
sumo2Score.innerHTML = sumo2Count;
}
}
function gameReset() {
sumo1.style.paddingTop = "0px";
sumo2.style.paddingTop = "0px";
button1.setAttribute("onclick", "move1(1)");
button2.setAttribute("onclick", "move1(2)");
sumo1.style.transform = "rotate(0deg)";
sumo2.style.transform = "rotate(180deg)";
}
function gameRestart() {
document.location.reload();
}