-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.html
More file actions
195 lines (171 loc) · 6.2 KB
/
game.html
File metadata and controls
195 lines (171 loc) · 6.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Word Flasher Game</title>
<style>
body {
margin: 0;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
.flash {
position: absolute;
top: 40%;
font-size: 32pt;
opacity: 0;
}
#status {
position: absolute;
top: 10px;
font-size: 16pt;
font-weight: bold;
}
#controlPanel {
display: flex;
justify-content: center;
gap: 10px;
margin-top: 20px;
position: absolute;
bottom: 20px;
}
button {
padding: 10px;
font-size: 16px;
cursor: pointer;
}
#summary {
display: none;
position: absolute;
top: 50%;
transform: translateY(-50%);
text-align: center;
font-size: 20pt;
font-weight: bold;
}
#restartButton {
display: none;
margin-top: 90px;
padding: 10px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<div id="status">Word Bank: 1 | Speed: 1.0s</div>
<div id="flashArea" class="flash"></div>
<div id="summary"></div>
<div id="controlPanel">
<button id="startButton">Start Game</button>
</div>
<button id="restartButton">Restart Game</button>
<script>
const wordBanks = ["Words_1.txt", "Words_2.txt", "Words_3.txt", "Words_4.txt", "Words_5.txt"];
let currentWordBankIndex = 0;
let currentSpeed = 1;
const minSpeed = 0.4;
const speedDecrement = 0.1;
const interval = 0.8;
let wordsInterval, holdInterval, wordHistory = [], currentIndex = 0, isPaused = false;
let currentWordBank = [];
let isCyclingSpeeds = false;
const flashArea = document.getElementById("flashArea");
const statusDisplay = document.getElementById("status");
const summaryDisplay = document.getElementById("summary");
const restartButton = document.getElementById("restartButton");
async function fetchWords(file) {
const response = await fetch(file);
const text = await response.text();
return text.split('\n').map(word => word.trim()).filter(word => word.length > 0);
}
function updateStatus() {
statusDisplay.textContent = `Word Bank: ${currentWordBankIndex + 1} | Speed: ${currentSpeed.toFixed(1)}s`;
}
function flashWords() {
clearInterval(wordsInterval);
clearInterval(holdInterval);
wordsInterval = setInterval(() => {
if (currentIndex >= wordHistory.length) {
const word = currentWordBank[Math.floor(Math.random() * currentWordBank.length)];
wordHistory.push(word);
}
const word = wordHistory[currentIndex++];
flashArea.textContent = word;
flashArea.style.opacity = 1;
holdInterval = setTimeout(() => {
flashArea.style.opacity = 0;
}, currentSpeed * 1000);
}, (interval + currentSpeed) * 1000);
}
async function startGame() {
currentWordBankIndex = 0;
currentSpeed = 1;
currentWordBank = await fetchWords(wordBanks[currentWordBankIndex]);
wordHistory = [];
currentIndex = 0;
isPaused = false;
isCyclingSpeeds = false; // Reset the cycling state
updateStatus();
flashWords();
cycleSpeeds();
// Replace the Start Game button with the Give In button
const controlPanel = document.getElementById("controlPanel");
controlPanel.innerHTML = '<button id="giveInButton">Give In!!</button>';
document.getElementById("giveInButton").addEventListener("click", endGame);
}
async function cycleSpeeds() {
if (isCyclingSpeeds) return; // Prevent multiple cycles from running
isCyclingSpeeds = true;
while (currentSpeed > minSpeed) {
await new Promise(resolve => setTimeout(resolve, 10000)); // Wait 10 seconds
currentSpeed -= speedDecrement;
updateStatus();
flashWords();
}
currentWordBankIndex++;
if (currentWordBankIndex < wordBanks.length) {
currentSpeed = 1;
currentWordBank = await fetchWords(wordBanks[currentWordBankIndex]);
wordHistory = [];
currentIndex = 0;
updateStatus();
flashWords();
isCyclingSpeeds = false;
cycleSpeeds(); // Start the next cycle
} else {
endGame();
}
}
function endGame() {
clearInterval(wordsInterval);
clearInterval(holdInterval);
flashArea.style.opacity = 0; // Hide the current word
summaryDisplay.textContent = `You gave in at Word Bank: ${currentWordBankIndex + 1}, Speed: ${currentSpeed.toFixed(1)}s`;
summaryDisplay.style.display = "block"; // Show the summary on the screen
statusDisplay.style.display = "none"; // Hide the status
flashArea.style.display = "none"; // Hide the word display
document.getElementById("controlPanel").style.display = "none"; // Hide the controls
restartButton.style.display = "block"; // Show the restart button
}
function restartGame() {
// Reset the game state
summaryDisplay.style.display = "none"; // Hide the summary
restartButton.style.display = "none"; // Hide the restart button
statusDisplay.style.display = "block"; // Show the status
flashArea.style.display = "block"; // Show the word display
document.getElementById("controlPanel").style.display = "flex"; // Show the controls
// Start a new game
startGame();
}
document.getElementById("startButton").addEventListener("click", startGame);
restartButton.addEventListener("click", restartGame);
</script>
</body>
</html>