-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
100 lines (78 loc) · 2.94 KB
/
Copy pathmain.js
File metadata and controls
100 lines (78 loc) · 2.94 KB
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
let pcScore = 0;
let userScore = 0;
const _material = document.querySelector('.user').children;
const _msg = document.querySelector('.masseg');
for (let i = 0; i < _material.length; i++) {
_material[i].addEventListener('click', _game);
}
function _game() {
let userChois = ((event.target).parentElement).getAttribute('id');
let pcChois = (_material[(Math.random() * 2).toFixed()]).getAttribute('id');
let _pc = document.querySelector(`#${pcChois}`).children[0].getAttribute('class');
let _temp;
if (userChois == pcChois) {
_temp = 'Your Tie!';
_remove();
_msg.classList.add('bg-tie');
document.querySelector(`#${userChois}`).children[0].classList.add('bg-lose-user');
} else if ((userChois == 'rock' && pcChois == 'scissors') ||
(userChois == 'paper' && pcChois == 'rock') ||
(userChois == 'scissors' && pcChois == 'paper')
) {
_temp = "Your Win!!";
_remove();
_msg.classList.add('bg-win');
document.querySelector(`#${userChois}`).children[0].classList.add('bg-win-user');
userScore++;
} else {
_temp = 'You Lose!!';
_remove();
_msg.classList.add('bg-lose');
document.querySelector(`#${userChois}`).children[0].classList.add('bg-lose-user');
pcScore++;
}
document.querySelector('#usescore').innerHTML = userScore;
document.querySelector('#pcscore').innerHTML = pcScore;
document.querySelector('#masseg').innerHTML = _temp;
document.querySelector('#computer').classList.add('transform');
setTimeout(() => {
document.querySelector('#computer').innerHTML = `<span class='${_pc}' ><span/>`;
}, 100);
setTimeout(() => {
document.querySelector('#alert').classList.add('alert-1');
}, 400);
for (let i = 0; i < _material.length; i++) {
_material[i].classList.remove('anime-1');
}
}
function _close() {
document.querySelector('#alert').classList.remove('alert-1');
document.querySelector('#computer').classList.remove('transform');
document.querySelector('.container').style.background = `${_bg()}`;
console.log(_bg())
_remove();
for (let i = 0; i < _material.length; i++) {
_material[i].classList.add('anime-1');
_material[i].children[0].classList.remove('bg-tie-user');
}
}
function _remove() {
for (let i = 0; i < _material.length; i++) {
_material[i].children[0].classList.remove('bg-win-user');
_material[i].children[0].classList.add('bg-tie-user');
_material[i].children[0].classList.remove('bg-lose-user');
}
_msg.classList.remove('bg-win');
_msg.classList.remove('bg-tie');
_msg.classList.remove('bg-lose');
}
function _bg(){
let color1 = '#';
let color2 = '#';
for(let i=0;i<6;i++){
color1 += (Math.random()*9).toFixed();
color2 += (Math.random()*9).toFixed();
}
let bgc = `linear-gradient(70deg,${color1},${color2})`;
return bgc;
}