-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
307 lines (271 loc) · 7.72 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
console.log('hello');
// const player1={
// name:null,
// score:0,
// correctAnswers: [],
// wrongAnswers:[]
// }
// const player2={
// name:null,
// score:0,
// correctAnswers: [],
// wrongAnswers:[]
// }
// console.log(player1);
// let ansIndex = -1;
const gameTool = {
question: {
Landmarkquestion: "Question: what landmark is this ?",
},
Images: {
LandmarkImages:[
"images/tajMahal.jpg",
"images/Colosseum.jpeg",
"images/Parthenon.jpg",
"images/eiffelTower.jpg",
"images/dubaiBuilding.jpg",
"images/pyramidGiza.jpg",
"images/sagradafamilia.jpg",
"images/SheikhZayedMosque.jpg"
]
},
rightOptions:{
landmarkOptions: [
"Taj Mahal",
"Colosseum",
"Parthenon",
"Eiffel Tower",
"Burj Al Arab Jumeirah",
"Pyramid at Giza",
"Sagrada Familia spain ",
"Sheikh Zayed Mosque "
]
},
wrongOptions:{
landmarkWrongOptions: [
"Stonehenge",
"Milan Cathedral",
"Great Sphinx Of Giza",
"Arc de Triomphe",
"Trevi Fountain",
"Machu Picchu",
"Angkor Wat",
"Amer Fort",
"Ganges",
"Leaning Tower Of Pisa",
"Hawa Mahal",
"Roman Forum",
"Pantheon",
"St.Peter's Baslica",
"Meteora",
"Great Wall of China",
"Acropolis of Anthens",
"Mycenae",
"Norte-Dame de Paris",
"Louvre museum",
"Arc de Triomphe",
"Burj Khalifa",
"Hagia Sophia",
"Alhambra"
]
}
}
//Function Add Each image to the images1 divs
let images1 = document.getElementsByClassName('images1'); qa
// NEW FUNCTION
const addImage = () => {
gameTool.Images.LandmarkImages.map( img => {
for (var imageDiv in images1) {
imageDiv.src = "./images/tajMahal.jpg"
}
console.log(img);
})
let landmarkCategories = document.getElementById('landmark')
}
addImage()
// OLD FUNCTION
// let i = gameTool.images.LandmarkImages.length - 1; //Note to self this returns the value at the last index, index 11, item 12
// for(let j = images1.length - 1; j >= 0; j-= 1){
// images1[j].src=gameTool.images[i];
// i-= 1;
// }
// return gameTool.images.length;
let images = Object.values(gameTool.Images.LandmarkImages);//array 4
let right = Object.values(gameTool.rightOptions);//array 4
let wrong = Object.values(gameTool.wrongOptions);//array 1
let inputBtn = document.getElementsByClassName('option');
let scoreCounter = document.getElementById('scoreCounter');
// createObj();
function createObj(ans){
let thisObj =
{
theAns:ans,
correct: false
}
return thisObj
}
//function to displayOptions
// debugger;
function displayAns(image){
let index = gameTool.images.indexOf(image);
let allChoices = [];
let theRightAns = {
theAns: gameTool.rightOptions[index],
correct: true
};
let wrongChoices=wrong.map(createObj);
let j=wrongChoices.length-1;
let s = 3;
while(s > 0){
let rad = Math.floor(Math.random() * j);
let wrongAPos = wrongChoices[rad];
wrongChoices[rad]=wrongChoices[j];
wrongChoices[j]=wrongChoices[rad];
allChoices.push(wrongAPos);
j -= 1;// reduce here
s -= 1;
}
debugger;
allChoices = allChoices.concat(theRightAns);
allChoices.sort(()=> 0.5-Math.random());
let inp=inputBtn.length-1;
let i=allChoices.length-1;
while(inp >=0){
inputBtn[inp].textContent = allChoices[i].theAns;
if (allChoices[i].correct) {
inputBtn[inp].dataset.correct = true;
}
else{
delete inputBtn[inp].dataset.correct;//Delete is a keyword
}
i -=1;
inp -=1;
}
return allChoices;
}
//function checkAnswer
let currentAnswer;
function checkAnswer(playersClick){
let modal22 = document.getElementById('modal2');
let click = playersClick.target;
click.style.backgroundColor = '#99DCFF';
let playersAns = click.getAttribute("data-correct");
let play1 = player1.name;
let play2 = player2.name;
let ourQuestions = addImage();
console.log(ourQuestions);
let currentScore = 0;
let targetScore = 8;
debugger;
if(playersAns == "true"){
player1.score += 1;
window.alert("You are correct!, pick another card.")
modal22.innerHTML =`${player2.name} your turn`;
modal22.style.visibility='visible';
scoreCounter.textContent =player1.score;
click.style.backgroundColor = '#8DCDF3';
console.log(scoreCounter.textContent);
}
else{
window.alert("soryy you are incorrect, pick another card.")
}
};
// displaye question
function ask(){
let taker=document.getElementById('questionTaker');
taker.textContent=gameTool.question;
}
//Global
let currentQuestion;
//function animate deckImg
function animate(theEvent){
let card=theEvent.target;
let height= 202;
let set= setInterval(move, 5);
function move(){
let thisQuest;
if(height === 0){
clearInterval(set);
}
else{
height-=1;
card.style.height= height + 'px';
}
}
debugger;
if(ansIndex === -1){
ansIndex = theEvent.target.getAttribute("data-index");
let questionIndex = parseInt(ansIndex);
currentQuestion = gameTool.images[questionIndex];
let coverImage = document.getElementsByClassName('images');
let cover = 0;
while(cover < coverImage.length){
coverImage[cover].addEventListener('click', displayAns(currentQuestion));
cover += 1;
}
ansIndex =-1;
}
ask();
for(let i=0; i<inputBtn.length; i +=1){
inputBtn[i].addEventListener('click', checkAnswer);
}
inputBtn.length.textContent = " ";
closeModal2();
}
//modal function
function showModal(){
let modal = document.getElementById('landmark');
window.onload = modal.style.display='block';
}
//Diplay player's name on scoreBoard
function displayPlayer(){
let player1Input =document.getElementById('namePut').value;
let player2Input =document.getElementById('namePut2').value;
player1.name =player1Input;
player2.name =player2Input;
let thePlayer=document.getElementById('thePlayer');
let thePlayer2=document.getElementById('thePlayer2');
thePlayer.innerHTML=player1Input;
thePlayer2.innerHTML=player2Input;
thePlayer.style.color ='#2B5C80';
thePlayer2.style.color ='#2B5C80';
modal.style.display='none';
};
// function click categories;
function category(){
// let list=theCat.target;
let imgHolder =document.getElementById('imageHolder');
let actualImages=document.getElementById('actualImages');
let finger=document.getElementById('finger');
let par=document.getElementById('par');
imgHolder.style.visibility='visible';
actualImages.style.visibility='visible';
finger.style.visibility='hidden';
par.style.visibility='hidden';
showModal2();
}
function showModal2(){
let modal2= document.getElementById('modal2');
modal2.innerHTML = `${player1.name} please pick a card`;
modal2.style.visibility ='visible';
}
function closeModal2(){
let modal21= document.getElementById('modal2');
modal21.style.visibility ='hidden';
}
function playgame(){
showModal();
let submit = document.getElementById('submit');
submit.addEventListener('click', displayPlayer);
let select =document.querySelector('li');
select.addEventListener('click', category);
addImage();
let modal2= document.getElementById('modal2');
let coverImages =document.getElementsByClassName('images');
let covers =0;
while(covers < coverImages.length){
coverImages[covers].addEventListener('click', animate);
covers +=1;
}
}
playgame();