forked from Wavyeli322/MemoryMaster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.html
More file actions
76 lines (70 loc) · 2.26 KB
/
score.html
File metadata and controls
76 lines (70 loc) · 2.26 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Score Summary</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
.score-summary {
max-width: 500px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
button {
padding: 10px 20px;
font-size: 16px;
margin-top: 20px;
cursor: pointer;
background-color: #28a745;
color: white;
border: none;
border-radius: 4px;
}
button:hover {
background-color: #218838;
}
</style>
</head>
<body>
<div class="score-summary">
<h1>Score!</h1>
<p id="score-breakdown"></p>
<button id="next-level-btn">Back to home</button>
</div>
<script>
// Retrieve data from localStorage and validate
const currentLevel = parseInt(localStorage.getItem("currentLevel")) || 1;
const nextLevel = currentLevel + 1;
const levelBonus = parseInt(localStorage.getItem("levelBonus")) || 0;
const matchedPairs = parseInt(localStorage.getItem("matchedPairs")) || 0;
const totalPairs = parseInt(localStorage.getItem("totalPairs")) || 0;
const score = parseInt(localStorage.getItem("score")) || 0;
// Calculate the score for this level
const levelScore = levelBonus + matchedPairs * 10;
// Update and display the score breakdown
const scoreBreakdownElement = document.getElementById("score-breakdown");
scoreBreakdownElement.innerHTML = `
<p><strong>Level:</strong> ${currentLevel}</p>
<p><strong>Level Bonus:</strong> ${levelBonus}</p>
<p><strong>Total Score:</strong> ${score} + ${levelScore} = ${score + levelScore}</p>
`;
// Update the score in localStorage for the next level
const newScore = score + levelScore;
localStorage.setItem("score", newScore);
localStorage.setItem("currentLevel", nextLevel);
document.getElementById("next-level-btn").addEventListener("click", () => {
// End of game: clear progress and return to the main menu
localStorage.clear(); // Reset progress
window.location.href = "index.html";
});
</script>
</body>
</html>