Skip to content

Commit 1257d94

Browse files
committed
Added new feature to main menu, Added mock subscription pop up, and cleaned up some functions.
1 parent 393de26 commit 1257d94

3 files changed

Lines changed: 179 additions & 24 deletions

File tree

index.html

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<div class="page-layout">
1111

1212
<!-- LEFT AD -->
13-
<div class="side-ad left-ad">
13+
<div id= "leftAd" class="side-ad left-ad">
1414
<img src="ads/ad_part_1.png" alt="Left Ad">
1515
<img src="ads/ad_part_2.png" alt="Left Ad 2">
1616
</div>
@@ -19,10 +19,15 @@
1919
<div class="main-content">
2020

2121
<h1>Skill Issue Main Menu</h1>
22-
<div>
22+
<button id="mainMenuBtn" aria-label="Main Menu">Main Menu</button>
23+
<div id="menuContainer" style="text-align:center;">
2324
<button id="startBtn">Start Game</button>
24-
<button id="mainMenuBtn" aria-label="Main Menu">Main Menu</button>
25-
<button id="loginBtn" aria-label="loginBtn">Login / Sign-up</button>
25+
<button id="continueGameBtn" style="display:none;">Continue</button>
26+
</div>
27+
28+
<div class="top-right-buttons">
29+
<button id="loginBtn">Login</button>
30+
<button id="subscriptionBtn">Subscribe</button>
2631
</div>
2732

2833
<div id="panel" style="display: none;">
@@ -55,12 +60,21 @@ <h2>Skill Shop</h2>
5560
</div>
5661

5762
<!-- RIGHT AD -->
58-
<div class="side-ad right-ad">
63+
<div id= "rightAd" class="side-ad right-ad">
5964
<img src="ads/ad_part_3.png" alt="Right Ad">
6065
<img src="ads/ad_part_4.png" alt="Right Ad 2">
6166
</div>
6267

6368
</div>
69+
70+
<div id="popupWindow" class="hidden">
71+
<div class="popup-box">
72+
<h3>Skill Issue Subscription</h3>
73+
<p>Remove all Advertisements - $4.99</p>
74+
<button id="runFuncBtn">Accept</button>
75+
<button id="closePopupBtn">Close</button>
76+
</div>
77+
</div>
6478
<script type="module" src="firebase.js"></script>
6579
<script type="module" src="script.js"></script>
6680
</body>

script.js

Lines changed: 103 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,16 @@ const shop = document.getElementById("shop");
307307
const lifeDisplay = document.getElementById("lifePoints");
308308
const skillCountDisplay = document.getElementById("skillCount");
309309
const loginBtn = document.getElementById("loginBtn");
310+
const subscriptionBtn = document.getElementById("subscriptionBtn");
311+
const popup = document.getElementById("popupWindow");
312+
const closeBtn = document.getElementById("closePopupBtn");
313+
const runFuncBtn = document.getElementById("runFuncBtn");
314+
const leftAd = document.getElementById("leftAd");
315+
const rightAd = document.getElementById("rightAd");
316+
317+
const continueGameBtn = document.getElementById("continueGameBtn");
318+
319+
const saved = localStorage.getItem("savedGame");
310320
// ---------- Show question ----------
311321
function showQuestion() {
312322
const q = questions[currentIndex];
@@ -329,12 +339,14 @@ function checkAnswer(selected, correct) {
329339
skillCount += skillMultiplier;
330340
message.textContent = "Correct! +1 skill!";
331341
saveStats();
342+
saveGameToLocal();
332343

333344
} else {
334345
wrongCount++;
335346
lifePoints--;
336347
message.textContent = `Wrong! -1 Life Point!`;
337348
saveStats();
349+
saveGameToLocal();
338350
}
339351

340352
correctDisplay.textContent = correctCount;
@@ -455,29 +467,92 @@ continueBtn.onclick = () => {
455467
}
456468

457469
mainMenuBtn.onclick = () => {
458-
showWelcomeMessage();
459470
panel.style.display = "none";
460-
startBtn.style.display = "inline-block";
461471
shop.style.display = "none";
462472

463-
currentIndex = 0;
464-
correctCount = 0;
465-
wrongCount = 0;
466-
skillCount = 0;
467-
lifePoints = 5;
468-
skillMultiplier = 1;
469-
470-
correctDisplay.textContent = correctCount;
471-
wrongDisplay.textContent = wrongCount;
472-
skillDisplay.textContent = skillCount;
473-
lifeDisplay.textContent = lifePoints;
473+
document.getElementById("menuContainer").style.display = "block";
474+
startBtn.style.display = "none";
475+
continueGameBtn.style.display = "inline-block";
474476
};
475477

476478
loginBtn.onclick = () => {
477479
window.location.href = "LoginPage.html";
478480

479481
}
480482

483+
subscriptionBtn.onclick = () => {
484+
popup.classList.remove("hidden");
485+
}
486+
487+
closeBtn.onclick = () => {
488+
popup.classList.add("hidden");
489+
};
490+
491+
runFuncBtn.onclick = () => {
492+
adBanner.classList.add("hidden");
493+
leftAd.classList.add("hidden");
494+
rightAd.classList.add("hidden");
495+
subscriptionBtn.disabled = true;
496+
subscriptionBtn.textContent = "(Subscribed)";
497+
subscriptionBtn.style.opacity = "0.5";
498+
popup.classList.add("hidden");
499+
};
500+
501+
continueGameBtn.onclick = () => {
502+
try {
503+
const raw = localStorage.getItem('savedGame');
504+
console.log('Continue clicked. raw savedGame:', raw);
505+
506+
if (!raw) {
507+
console.warn('No saved game found in localStorage.');
508+
return;
509+
}
510+
511+
const saved = JSON.parse(raw);
512+
513+
// Validate required keys
514+
if (typeof saved.questionIndex !== 'number' ||
515+
typeof saved.correct !== 'number' ||
516+
typeof saved.wrong !== 'number' ||
517+
typeof saved.skill !== 'number' ||
518+
typeof saved.life !== 'number') {
519+
console.error('Saved game missing required numeric fields:', saved);
520+
return;
521+
}
522+
523+
// Restore stats safely
524+
currentIndex = saved.questionIndex;
525+
correctCount = saved.correct;
526+
wrongCount = saved.wrong;
527+
skillCount = saved.skill;
528+
lifePoints = saved.life;
529+
530+
// Update UI numbers
531+
correctDisplay.textContent = correctCount;
532+
wrongDisplay.textContent = wrongCount;
533+
skillDisplay.textContent = skillCount;
534+
lifeDisplay.textContent = lifePoints;
535+
536+
// Make sure index is within bounds
537+
if (currentIndex < 0) currentIndex = 0;
538+
if (currentIndex >= questions.length) {
539+
console.warn('Saved questionIndex out of range, resetting to last question.');
540+
currentIndex = Math.max(0, questions.length - 1);
541+
}
542+
543+
// showQuestion uses currentIndex global — call without args
544+
showQuestion();
545+
546+
// Hide main-menu/continue and show panel
547+
startBtn.style.display = "none";
548+
continueGameBtn.style.display = "none";
549+
panel.style.display = "block";
550+
551+
console.log('Game restored. currentIndex =', currentIndex);
552+
} catch (err) {
553+
console.error('Error while restoring saved game:', err);
554+
}
555+
};
481556
// --- Initialize display on page load ---
482557
function initializeDisplay() {
483558
correctDisplay.textContent = correctCount;
@@ -523,3 +598,18 @@ async function saveStats() {
523598
}, { merge: true });
524599
}
525600

601+
if (saved) {
602+
continueGameBtn.style.display = "inline-block";
603+
}
604+
605+
function saveGameToLocal() {
606+
const payload = {
607+
questionIndex: currentIndex,
608+
correct: correctCount,
609+
wrong: wrongCount,
610+
skill: skillCount,
611+
life: lifePoints
612+
};
613+
localStorage.setItem('savedGame', JSON.stringify(payload));
614+
}
615+

style.css

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,19 @@ button {
6666
background: #2ecc71;
6767
}
6868

69-
#loginBtn {
70-
position: fixed;
71-
right: 12px;
72-
top: 12px;
73-
z-index: 1100;
74-
background: #2ecc71;
69+
.top-right-buttons {
70+
position: fixed;
71+
top: 20px;
72+
right: 20px;
73+
display: flex;
74+
flex-direction: column;
75+
gap: 10px;
7576
}
7677

78+
.top-right-buttons button {
79+
width: 120px;
80+
background: #2ecc71;
81+
}
7782
#panel {
7883
display: none;
7984
margin-top: 20px;
@@ -125,6 +130,7 @@ button {
125130
cursor: pointer;
126131
}
127132

133+
128134
/* Rotating ad */
129135
.rotating-ad {
130136
margin-top: 20px;
@@ -163,5 +169,50 @@ button {
163169
}
164170
}
165171

172+
/* Popup background overlay */
173+
174+
.hidden {
175+
display: none;
176+
}
177+
178+
#popupWindow {
179+
position: fixed;
180+
top: 50%;
181+
left: 50%;
182+
transform: translate(-50%, -50%);
183+
background: white;
184+
padding: 20px;
185+
border: 2px solid black;
186+
z-index: 1000;
187+
}
188+
189+
190+
191+
/* Popup box */
192+
.popup-box {
193+
background: white;
194+
padding: 20px;
195+
border-radius: 10px;
196+
text-align: center;
197+
min-width: 250px;
198+
}
199+
200+
.main-content > div {
201+
text-align: center;
202+
}
203+
204+
#startBtn,
205+
#continueGameBtn {
206+
display: inline-block;
207+
margin-top: 20px;
208+
padding: 12px 20px;
209+
font-size: 18px;
210+
}
211+
212+
#continueGameBtn {
213+
display: none;
214+
}
215+
216+
166217

167218

0 commit comments

Comments
 (0)