-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
77 lines (70 loc) · 2.57 KB
/
main.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
const fireButton = document.getElementById("myBtn");
const readyButton = document.getElementById("myBtn2");
const testThing = document.getElementById("testp");
const scoreCard = document.getElementById("thescore");
const resetScore = document.getElementById("resetButton");
const BigIron = document.getElementById("bigIron");
const bangSound = document.getElementById("bang");
const death = document.getElementById("death")
const muteMusic = document.getElementById("mute");
const playSong = document.getElementById("playMusic")
//Game logic ------------
playSong.addEventListener("click",playMusic)
const cowboy1 = document.getElementById("cowboy1");
const samurai1 = document.getElementById("samurai1");
let imageC = document.getElementById('cowboy1');
let imageS = document.getElementById('samurai1');
//Game logic ------------
function playMusic(){
BigIron.play()
}
muteMusic.addEventListener("click", pauseMusic)
function pauseMusic(){
BigIron.pause()
}
readyButton.addEventListener("click", fireTime)
let scoreAmount = 0
resetScore.addEventListener("click", resetTheScore)
function resetTheScore(){
scoreAmount = 0
scoreCard.innerHTML = `Score: ${scoreAmount}`
}
function fireTime(){
imageC.src = "cowboyStart1.png"
imageS.src = "samuraiStart.png"
let done = false
testThing.innerHTML = "Hold"
function drawTime(){
testThing.innerHTML = "DRAW"
}
const drawTimeout = setTimeout(drawTime, 1000); // After 1 second, users will have 1 second to draw
function badFire(){
death.play()
testThing.innerHTML = "Better luck next time. Click ready to play again.";
clearTimeout(drawTimeout)
imageS.src = "samuraiSwing.png"
cowboy1.style.animation="CdeathMove 2s";
done = true
}
let tooLate = setTimeout(badFire, 2000); // If user doesn't hit in time, bad message
if(done === false){
function goodFire(){
imageC.src = "cowboyShoot1.png"
bangSound.play()
clearTimeout(tooLate);
clearTimeout(drawTimeout);
if(testThing.innerHTML === "DRAW"){
testThing.innerHTML = "You did it! Click ready to play again";
samurai1.style.animation = "samdeathMove 2s"
scoreCard.innerHTML = `Score: ${scoreAmount}`
}
else if(testThing.innerHTML === "Hold"){
testThing.innerHTML = "Too soon! Click ready to try again"
}
}
fireButton.addEventListener("click", goodFire)
}
if(goodFire){
scoreAmount += 1
}
}