-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
80 lines (55 loc) · 1.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
const head = document.getElementById("header");
const img = ["Image/dice1.png","Image/dice2.png","Image/dice3.png","Image/dice4.png","Image/dice5.png","Image/dice6.png"]
var audio = document.getElementById("myAudio")
function reset() {
head.innerHTML = "Let's Play the Game!"
}
function showHeader(head,para) {
head.innerHTML = para
}
function playAudio() {
audio.play();
}
function pauseAudio() {
audio.pause();
}
function audioDic(){
let MyAudio =
`
<source src="music.mpeg" type="audio/mpeg">
Your browser does not support the audio element.
`
audio.innerHTML = MyAudio;
playAudio();
}
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
function rotate(){
audioDic();
document.getElementById("img-dice").classList.add("img-dice-tr")
var player1 =Math.floor(getRandomArbitrary(1,7))
var player2 = Math.floor(getRandomArbitrary(1,7))
const myTimeout = setTimeout(stp, 7000);
function stp() {
pauseAudio();
document.getElementById("img-dice").classList.remove("img-dice-tr")
DiceValue(player1, player2);
}
}
function DiceValue(value1,value2){
console.log(value1,value2);
document.getElementById("pl1-dice").src = img[value1-1]
document.getElementById("pl2-dice").src = img[value2-1]
if (value1>value2){
showHeader(head,"Player 1 won the game 🥳🥳🥳🥳!!");
}else if(value2>value1){
showHeader(head,"Player 2 won the game 🥳🥳🥳🥳!!");
}else{
showHeader(head,"Opps! It's Draw☹️☹️☹️☹️☹️!!");
}
}
function btn(){
reset();
rotate();
}