-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
140 lines (90 loc) · 2.78 KB
/
app.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const mainContainerIndex = document.getElementById('mainContainerIndex');
const feedBtn = document.getElementById('feedBtn');
const sleepBtn = document.getElementById('sleepBtn');
const playBtn = document.getElementById('playBtn');
const pokeBtn = document.getElementById('pokeBtn');
const buttonContainer = document.getElementById('buttonContainer');
const gameTitle = document.getElementById ('gameTitle');
const game = document.getElementById ('game');
const message = document.getElementById('message');
const catPic = document.getElementById('catPic');
const catContainer = document.getElementById('catContainer');
const slothContainer = document.getElementById('slothContainer');
const alienContainer = document.getElementById('alienContainer');
let insertName = document.getElementById('insertName');
let petName = document.getElementsByClassName('window');
const restart = document.getElementById('restart');
//Show||Hide Content Functions//
const hide = (i)=>{
i.style.display = "none";
}
const show = (i)=>{
i.style.display = "block";
}
//Hide//
hide(buttonContainer);
hide(gameTitle);
hide(catContainer);
hide(slothContainer);
hide(alienContainer);
hide(restart);
// function that asks user for name of pet//
const getName = () => {
petName = prompt("Aw, great choice! Now enter a name for your pet.");
while (petName.length === 0) {
alert("Please enter a name for your pet.");
petName = prompt("Your pet name:");
}
};
//Main Buttons//
catPic.addEventListener("click", () =>{
hide(mainContainerIndex);
getName();
pet = new Cat (petName);
// defined new pet as cat^
show(catContainer);
show(buttonContainer);
show(gameTitle);
show(restart);
audioCat.src = "sounds/Cat.mp3";
})
slothPic.addEventListener("click", () =>{
hide(mainContainerIndex);
getName();
pet = new Sloth (petName);
show(slothContainer);
show(buttonContainer);
show(gameTitle);
show(restart);
audioSloth.src ="sounds/Sloth.mov"
})
alienPic.addEventListener("click", (event) => {
hide(mainContainerIndex);
getName();
pet = new Alien (petName);
show(alienContainer);
show(buttonContainer);
show(gameTitle);
show(restart);
audioAlien.src ="sounds/Alien1.mp3"
});
//Event Listener//
// const cat = new CyberPet("cat1");
feedBtn.addEventListener("click", () =>{
pet.feed()
})
sleepBtn.addEventListener("click", () =>{
pet.sleep()
})
playBtn.addEventListener("click", () =>{
pet.play()
})
pokeBtn.addEventListener("click",() =>{
pet.poke()
})
// defined pet as new cat and changed from cat.feed() cat.sleep() and cat.play() to cat.sleep() to pet.feed()
//Event Listener Sound//
//re-start button//
restart.addEventListener("click", () => {
window.location.reload()
})