Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
316 lines (258 loc) Β· 10 KB
/
Copy pathscript.js
File metadata and controls
316 lines (258 loc) Β· 10 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
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
308
309
310
311
312
313
314
315
316
// Test if script is loading
console.log("Script loaded successfully!");
// Navigation functionality
document.addEventListener("DOMContentLoaded", function () {
console.log("DOM Content Loaded - Initializing event listeners");
const navButtons = document.querySelectorAll(".nav-btn");
const sections = document.querySelectorAll(".content-section");
console.log("Found nav buttons:", navButtons.length);
console.log("Found content sections:", sections.length);
navButtons.forEach((button) => {
button.addEventListener("click", () => {
console.log("Nav button clicked:", button);
const targetSection = button.getAttribute("data-section");
console.log("Target section:", targetSection);
// Hide all sections
sections.forEach((section) => {
section.classList.remove("active");
});
// Show target section
document.getElementById(targetSection).classList.add("active");
// Update active nav button
navButtons.forEach((btn) => btn.classList.remove("active"));
button.classList.add("active");
});
});
// Pet interaction functionality
const petCards = document.querySelectorAll(".pet-card");
console.log("Found pet cards:", petCards.length);
// Debug: Let's also try to find buttons directly
const allFeedBtns = document.querySelectorAll(".feed-btn");
const allPlayBtns = document.querySelectorAll(".play-btn");
const allSleepBtns = document.querySelectorAll(".sleep-btn");
console.log(
"Direct button search - Feed:",
allFeedBtns.length,
"Play:",
allPlayBtns.length,
"Sleep:",
allSleepBtns.length
);
petCards.forEach((card, index) => {
console.log(`Processing pet card ${index + 1}:`, card);
const feedBtn = card.querySelector(".feed-btn");
const playBtn = card.querySelector(".play-btn");
const sleepBtn = card.querySelector(".sleep-btn");
const petAvatar = card.querySelector(".pet-avatar");
console.log(`Card ${index + 1} elements:`, {
feedBtn: !!feedBtn,
playBtn: !!playBtn,
sleepBtn: !!sleepBtn,
petAvatar: !!petAvatar,
});
// Check if all required elements exist
if (!feedBtn || !playBtn || !sleepBtn || !petAvatar) {
console.error("Missing required elements in pet card:", card);
return;
}
console.log(`Adding event listeners to card ${index + 1}`);
// Remove the test onclick handlers since buttons are working now
feedBtn.addEventListener("click", () => {
console.log("Feed button clicked for:", card);
petAvatar.style.transform = "scale(1.2)";
setTimeout(() => {
petAvatar.style.transform = "scale(1)";
}, 300);
showMessage("Yummy! π");
updateHappiness(card, 10);
});
playBtn.addEventListener("click", () => {
console.log("Play button clicked for:", card);
petAvatar.style.animation = "none";
setTimeout(() => {
petAvatar.style.animation = "bounce 0.5s ease-in-out 3";
}, 10);
showMessage("Woof! So fun! πΎ");
updateHappiness(card, 15);
updateEnergy(card, -10); // Playing uses energy
});
sleepBtn.addEventListener("click", () => {
console.log("Sleep button clicked for:", card);
petAvatar.style.opacity = "0.5";
setTimeout(() => {
petAvatar.style.opacity = "1";
}, 2000);
showMessage("Zzz... π΄");
updateEnergy(card, 20); // Sleep should restore energy
});
});
// Shop functionality
const buyButtons = document.querySelectorAll(".buy-btn");
console.log("Found buy buttons:", buyButtons.length);
buyButtons.forEach((button) => {
button.addEventListener("click", (e) => {
console.log("Buy button clicked:", button);
const item = e.target.closest(".shop-item");
if (!item) {
console.error("Could not find shop item for button:", button);
return;
}
const itemNameElement = item.querySelector(".item-name");
if (!itemNameElement) {
console.error("Could not find item name element:", item);
return;
}
const itemName = itemNameElement.textContent;
button.textContent = "Purchased!";
button.style.background = "rgba(72, 187, 120, 0.8)";
setTimeout(() => {
button.textContent = "Buy Now";
button.style.background = "rgba(255,255,255,0.2)";
}, 2000);
showMessage(`You bought ${itemName}! ποΈ`);
});
});
// Add new pet functionality
const addPetBtn = document.querySelector(".add-pet-btn");
const petGrid = document.querySelector(".pet-grid");
console.log("Add pet button found:", !!addPetBtn);
console.log("Pet grid found:", !!petGrid);
if (!addPetBtn || !petGrid) {
console.error("Missing add pet button or pet grid elements");
return;
}
addPetBtn.addEventListener("click", () => {
console.log("Add pet button clicked");
const petEmojis = ["π°", "πΉ", "π¦", "π ", "π’", "π¦"];
const petNames = [
"Whiskers",
"Nibbles",
"Chirpy",
"Bubbles",
"Shelly",
"Spike",
];
const randomEmoji = petEmojis[Math.floor(Math.random() * petEmojis.length)];
const randomName = petNames[Math.floor(Math.random() * petNames.length)];
const newPetCard = createPetCard(randomEmoji, randomName);
petGrid.appendChild(newPetCard);
showMessage(`Welcome ${randomName}! π`);
// Add event listeners to new pet
addPetEventListeners(newPetCard);
});
function createPetCard(emoji, name) {
const petCard = document.createElement("div");
petCard.className = "pet-card";
petCard.innerHTML = `
<div class="pet-avatar">${emoji}</div>
<h3 class="pet-name">${name}</h3>
<div class="pet-stats">
<div class="stat">
<span class="stat-label">Happiness:</span>
<div class="stat-bar"><div class="stat-fill" style="width: 50%"></div></div>
</div>
<div class="stat">
<span class="stat-label">Energy:</span>
<div class="stat-bar"><div class="stat-fill" style="width: 70%"></div></div>
</div>
</div>
<div class="pet-actions">
<button class="action-btn feed-btn">Feed</button>
<button class="action-btn play-btn">Play</button>
<button class="action-btn sleep-btn">Sleep</button>
</div>
`;
return petCard;
}
function addPetEventListeners(card) {
const feedBtn = card.querySelector(".feed-btn");
const playBtn = card.querySelector(".play-btn");
const sleepBtn = card.querySelector(".sleep-btn");
const petAvatar = card.querySelector(".pet-avatar");
feedBtn.addEventListener("click", () => {
petAvatar.style.transform = "scale(1.2)";
setTimeout(() => (petAvatar.style.transform = "scale(1)"), 300);
showMessage("Nom nom! π");
updateHappiness(card, 10);
});
playBtn.addEventListener("click", () => {
petAvatar.style.animation = "bounce 0.5s ease-in-out 3";
showMessage("Wheee! πΎ");
updateHappiness(card, 15);
updateEnergy(card, -10); // Playing uses energy
});
sleepBtn.addEventListener("click", () => {
petAvatar.style.opacity = "0.5";
setTimeout(() => (petAvatar.style.opacity = "1"), 2000);
showMessage("Sweet dreams! π΄");
updateEnergy(card, 20); // Sleep should restore energy
});
}
function updateHappiness(card, amount) {
// Find the happiness stat specifically (first stat in the pet stats)
const stats = card.querySelectorAll(".stat");
const happinessStat = stats[0]; // First stat is happiness
if (!happinessStat) {
console.error("Could not find happiness stat in card:", card);
return;
}
const happinessFill = happinessStat.querySelector(".stat-fill");
if (!happinessFill) {
console.error("Could not find happiness fill element in card:", card);
return;
}
const currentWidth = parseInt(happinessFill.style.width) || 50;
const newWidth = Math.min(100, currentWidth + amount);
happinessFill.style.width = newWidth + "%";
console.log(`Updated happiness from ${currentWidth}% to ${newWidth}%`);
}
function updateEnergy(card, amount) {
// Find the energy stat specifically (second stat in the pet stats)
const stats = card.querySelectorAll(".stat");
const energyStat = stats[1]; // Second stat is energy
if (!energyStat) {
console.error("Could not find energy stat in card:", card);
return;
}
const energyFill = energyStat.querySelector(".stat-fill");
if (!energyFill) {
console.error("Could not find energy fill element in card:", card);
return;
}
const currentWidth = parseInt(energyFill.style.width) || 50;
const newWidth = Math.max(0, Math.min(100, currentWidth + amount)); // Ensure it stays between 0 and 100
energyFill.style.width = newWidth + "%";
console.log(`Updated energy from ${currentWidth}% to ${newWidth}%`);
}
function showMessage(text) {
const message = document.createElement("div");
message.textContent = text;
message.style.cssText = `
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(0,0,0,0.8);
color: white;
padding: 1rem 2rem;
border-radius: 25px;
font-size: 1.2rem;
z-index: 1000;
animation: messagePopup 2s ease-in-out forwards;
`;
document.body.appendChild(message);
setTimeout(() => {
document.body.removeChild(message);
}, 2000);
}
// Add CSS animation for message popup
const style = document.createElement("style");
style.textContent = `
@keyframes messagePopup {
0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
20% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}
`;
document.head.appendChild(style);
});