Repository navigation
Expand file tree
/
Copy pathmemory-game.html
More file actions
96 lines (80 loc) · 2.75 KB
/
Copy pathmemory-game.html
File metadata and controls
96 lines (80 loc) · 2.75 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Memory Number Game - Java Terminal Demo</title>
<link rel="stylesheet" href="./styles/main.css">
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&display=swap" rel="stylesheet">
</head>
<body>
<div class="nav-bar">
<a href="./index.html">🏠 Home</a>
<a href="./word-scramble.html">🔤 Word Scramble</a>
<a href="./number-converter.html">🔢 Number Converter</a>
<a href="./memory-game.html" class="active">🧠 Memory Game</a>
<a href="./minesweeper.html">💣 Minesweeper</a>
<a href="https://github.com/Janani-V219/Java_Mini_Projects" target="_blank">📄 GitHub Repo</a>
</div>
<div class="terminal" id="Terminal">
<div class="console-line">
Click <button id="run-button">Run</button> to run Memory Number Game.
</div>
<div class="content" id="Content"></div>
</div>
<script src="./terminal.js"></script>
<script>
let isRunning = false;
document.getElementById("run-button").addEventListener("click", async () => {
if (isRunning) return;
isRunning = true;
clearScreen();
let score = 0;
const rounds = 5;
print("=================================");
print(" MEMORY NUMBER GAME");
print("=================================");
for (let round = 1; round <= rounds; round++) {
const length = round + 4;
const numbers = [];
for (let i = 0; i < length; i++) {
numbers.push(Math.floor(Math.random() * 10));
}
print("");
print("Round " + round);
print("Remember:");
print(numbers.join(" "));
// Give 4 seconds to remember
await sleep(4000);
// Clear screen (matches Java's 30 newlines clearing)
clearScreen();
const answer = (await readLine("Enter the numbers:\n")).trim();
const correct = numbers.join(" ");
if (answer === correct) {
print("🎉 Correct!");
score++;
} else {
print("❌ Wrong!");
print("Correct answer: " + correct);
}
print("Score: " + score + "/" + rounds);
}
print("");
print("=================================");
print(" GAME OVER");
print("=================================");
print("Final Score: " + score + "/" + rounds);
if (score === 5) {
print("🏆 Perfect Memory!");
} else if (score >= 3) {
print("🎉 Great Memory!");
} else {
print("💪 Keep practicing!");
}
print("");
print("Press Run to play again.");
isRunning = false;
});
</script>
</body>
</html>