Repository navigation
Expand file tree
/
Copy pathscripts.js
More file actions
253 lines (207 loc) · 7.03 KB
/
Copy pathscripts.js
File metadata and controls
253 lines (207 loc) · 7.03 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
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
// /*create list of all elements and store it inside const named card */
// /*This returns a list of all <div> elements within the document with a class of memory-card*/
// //document.querySelector(cards);
// const gameContainer = document.querySelector(".memory-game");
// // gameContainer.onclick = function (event) {
// // event.target = cardsData.forEach((cardData) =>
// // cardData.addEventListener("click", flipCard)
// // );
// // };
// const backFace = "img/js-badge.svg";
// const cardsData = [
// {
// framework: "aurelia",
// frontFace: "img/aurelia.svg",
// },
// {
// framework: "vue",
// frontFace: "img/vue.svg",
// },
// {
// framework: "angular",
// frontFace: "img/angular.svg",
// },
// {
// framework: "backbone",
// frontFace: "img/backbone.svg",
// },
// {
// framework: "ember",
// frontFace: "img/ember.svg",
// },
// {
// framework: "react",
// frontFace: "img/react.svg",
// },
// ];
// // Get references to the selection and button elements
// const cardsSelect = document.getElementById("cards");
// const filterFour = document.getElementById("filterFour");
// const filterEight = document.getElementById("filterEight");
// const updateButton = document.getElementById("btn");
// // Add an event listener to the update button
// updateButton.addEventListener("click", updateCards);
// // Initial call to display the cards
// updateCards();
// hideModal();
// function hideModal() {
// const modal = document.getElementById("modal");
// modal.style.display = "none";
// }
// // Function to generate the card HTML and add it to the DOM
// function generateCards(cardsData) {
// // Create pairs of each card
// const pairedCardsData = cardsData.concat(cardsData);
// // Shuffle the paired cards
// const shuffledCardsData = shuffle(pairedCardsData);
// shuffledCardsData.forEach((cardData) => {
// const cardHTML = `
// <div class="memory-card" data-framework="${cardData.framework}">
// <img class="front-face" src="${cardData.frontFace}" alt="${cardData.framework}">
// <img class="back-face" src="${backFace}" alt="Memory Card">
// </div>
// `;
// gameContainer.innerHTML += cardHTML;
// });
// shuffleCards();
// }
// // Function to shuffle an array
// function shuffle(array) {
// let currentIndex = array.length,
// randomIndex;
// // While there remain elements to shuffle...
// while (currentIndex != 0) {
// // Pick a remaining element...
// randomIndex = Math.floor(Math.random() * currentIndex);
// currentIndex--;
// // And swap it with the current element.
// [array[currentIndex], array[randomIndex]] = [
// array[randomIndex],
// array[currentIndex],
// ];
// }
// return array;
// }
// // Function to add event listeners to the cards
// function addEventListeners() {
// const cardsData = document.querySelectorAll(".memory-card");
// cardsData.forEach((cardData) => cardData.addEventListener("click", flipCard));
// }
// /*Has to know if player clicks first or second card */
// let hasFlippedCard = false;
// let lockBoard = false;
// let firstCard, secondCard;
// function flipCard() {
// console.log(this);
// if (lockBoard) return;
// if (this === firstCard) return;
// /*toggle means if class is there add it, if not remove*/
// this.classList.add("flip");
// if (!hasFlippedCard) {
// //first click
// hasFlippedCard = true;
// firstCard = this;
// return;
// }
// //second click
// secondCard = this;
// if (firstCard && secondCard) {
// // Get the number of cards from the select element
// const numberOfCards = parseInt(cardsSelect.value);
// // Filter the cards data to get the desired number of card pairs
// const filteredCardsData = cardsData.slice(0, numberOfCards);
// checkForMatch(filteredCardsData); // Pass the filteredCardsData as an argument
// }
// }
// let pairedCards = 0;
// function checkForMatch(filteredCardsData) {
// //do cards match?
// /*now we can identify cards. Check if framework from first and second card are the same. If they are remove eventlistener to prevent from click again */
// let isMatch = firstCard.dataset.framework === secondCard.dataset.framework;
// if (isMatch) {
// disableCards();
// pairedCards += 2; // Increment the paired cards counter
// if (pairedCards === filteredCardsData.length * 2) {
// setTimeout(() => {
// showModal();
// }, 1000);
// }
// console.log("length", filteredCardsData.length);
// } else {
// unflipCards();
// }
// function disableCards() {
// //its a match!!
// firstCard.removeEventListener("click", flipCard);
// secondCard.removeEventListener("click", flipCard);
// resetBoard();
// }
// function showModal() {
// const modal = document.getElementById("modal");
// const newGameBtn = document.getElementById("newGameBtn");
// modal.style.display = "block";
// newGameBtn.onclick = function () {
// hideModal();
// resetGame();
// };
// window.onclick = function (event) {
// if (event.target === modal) {
// hideModal();
// resetGame();
// }
// };
// }
// function resetGame() {
// // Clear the game container
// gameContainer.innerHTML = "";
// // Generate and display the filtered cards data
// generateCards(filteredCardsData);
// addEventListeners();
// // Reset the paired cards counter
// pairedCards = 0;
// }
// function unflipCards() {
// // not a match
// lockBoard = true;
// setTimeout(() => {
// firstCard.classList.remove("flip");
// secondCard.classList.remove("flip");
// resetBoard();
// }, 1500);
// }
// }
// // Function to handle updating the number of cards displayed
// function updateCards() {
// const numberOfCards = parseInt(cardsSelect.value);
// // Log the value of numberOfCards
// console.log("Number of Cards: ", numberOfCards);
// // Filter the cards data to get the desired number of card pairs
// const filteredCardsData = cardsData.slice(0, numberOfCards);
// // Clear the game container
// gameContainer.innerHTML = "";
// // Generate and display the cards
// generateCards(filteredCardsData);
// // addEventListeners();
// //Update the checkForMatch function to use the filtered cards data
// const cards = document.querySelectorAll(".memory-card");
// cards.forEach(function (card) {
// card.addEventListener("click", function () {
// flipCard.call(this);
// // checkForMatch(filteredCardsData);
// });
// });
// // Reset the paired cards counter
// //pairedCards = 0;
// }
// function resetBoard() {
// [hasFlippedCard, lockBoard] = [false, false];
// [firstCard, secondCard] = [null, null];
// }
// // Shuffle cards
// function shuffleCards() {
// const cards = document.querySelectorAll(".memory-card");
// cards.forEach((card) => {
// let randomPos = Math.floor(Math.random() * cards.length);
// card.style.order = randomPos;
// });
// }