Skip to content

Commit fdb568e

Browse files
committed
- minor clean up
1 parent fe45596 commit fdb568e

File tree

1 file changed

+12
-55
lines changed

1 file changed

+12
-55
lines changed

games/death_by_ai.html

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,13 @@
1919
<body class="bg-gradient-to-r from-gray-900 to-black text-white min-h-screen flex items-center justify-center">
2020
<div id="appContainer" class="container mx-auto p-4 max-w-2xl"></div>
2121
<script>const appContainer = document.getElementById('appContainer');
22-
let currentRound = 0;
23-
let playerScore = 0;
24-
let streak = 0;
25-
let difficulty = 'medium';
26-
let playerName = '';
27-
let playerAvatar = '😀';
28-
let timerInterval;
29-
let timeLeft = 60;
30-
let xp = 0;
31-
let scenarioType = 'AI generated';
32-
let isSpeedrun = false;
33-
let speedrunTime = 0;
34-
let speedrunInterval;
35-
let roundStartTime;
36-
let totalSpeedrunTime = 0;
37-
const backgrounds = ['from-gray-900 to-black', 'from-blue-900 to-black', 'from-green-900 to-black', 'from-red-900 to-black', 'from-purple-900 to-black'];
38-
const randomUsernames = ['SurvivalGuru', 'LuckyEscaper', 'DeathDefier', 'ChanceChaser', 'FateChallenger', 'RiskTaker', 'DangerDodger', 'ThrillerThriver', 'AdventureAce', 'PerilPro'];
39-
const scenarioTopics = ['Natural Disaster', 'Wildlife Encounter', 'Urban Emergency', 'Historical Event', 'Sci-Fi Situation', 'Supernatural Occurrence', 'Medical Crisis', 'Extreme Sport Accident', 'Espionage Mission', 'Post-Apocalyptic Scenario', 'Ancient Civilization Discovery', 'Virtual Reality Glitch', 'Time Travel Mishap', 'Underwater Exploration', 'Space Exploration Crisis', 'Parallel Universe Incident', 'Mythological Creature Encounter', 'Psychological Thriller', 'Haunted Location', 'Survival Game Show'];
40-
const avatars = ['😀', '😎', '🤠', '🧐', '🥸', '🤓', '👻', '💀', '👽', '🤖', '🦸', '🧙', '🧛', '🧟', '🥷', '🦹', '🧑‍🚀', '🧝', '🧞', '🧜'];
22+
let currentRound = 0, playerScore = 0, streak = 0, difficulty = 'medium', playerName = '', playerAvatar = '😀',
23+
timerInterval, timeLeft = 60, xp = 0, scenarioType = 'AI generated', isSpeedrun = false, roundStartTime,
24+
totalSpeedrunTime = 0;
25+
const backgrounds = ['from-gray-900 to-black', 'from-blue-900 to-black', 'from-green-900 to-black', 'from-red-900 to-black', 'from-purple-900 to-black'],
26+
randomUsernames = ['SurvivalGuru', 'LuckyEscaper', 'DeathDefier', 'ChanceChaser', 'FateChallenger', 'RiskTaker', 'DangerDodger', 'ThrillerThriver', 'AdventureAce', 'PerilPro'],
27+
scenarioTopics = ['Natural Disaster', 'Wildlife Encounter', 'Urban Emergency', 'Historical Event', 'Sci-Fi Situation', 'Supernatural Occurrence', 'Medical Crisis', 'Extreme Sport Accident', 'Espionage Mission', 'Post-Apocalyptic Scenario', 'Ancient Civilization Discovery', 'Virtual Reality Glitch', 'Time Travel Mishap', 'Underwater Exploration', 'Space Exploration Crisis', 'Parallel Universe Incident', 'Mythological Creature Encounter', 'Psychological Thriller', 'Haunted Location', 'Survival Game Show'],
28+
avatars = ['😀', '😎', '🤠', '🧐', '🥸', '🤓', '👻', '💀', '👽', '🤖', '🦸', '🧙', '🧛', '🧟', '🥷', '🦹', '🧑‍🚀', '🧝', '🧞', '🧜'];
4129

4230
function startGame() {
4331
currentRound = 0;
@@ -49,7 +37,7 @@
4937

5038
function renderCharacterCreation() {
5139
const unlockedAvatars = avatars.slice(0, Math.min(10 + Math.floor(xp / 100), avatars.length));
52-
appContainer.innerHTML = `<div class="text-center bg-gray-800 bg-opacity-90 p-8 rounded-lg shadow-lg"><h2 class="text-3xl mb-4 text-green-400 font-bold">Create Your Character</h2><input id="player-name" class="bg-gray-700 text-white px-4 py-2 rounded focus:outline-none focus:ring-2 focus:ring-green-500 w-full mb-4" placeholder="Enter your name (optional)" value="${randomUsernames[Math.floor(Math.random() * randomUsernames.length)]}"><div class="mb-4"><label class="block mb-2 font-semibold">Choose your avatar:</label><div class="flex justify-center flex-wrap">${avatars.map((emoji, index) => `<button class="avatar-btn text-2xl p-2 m-1 rounded ${emoji === playerAvatar ? 'bg-green-500' : 'bg-gray-600'} ${index >= unlockedAvatars.length ? 'opacity-50 cursor-not-allowed' : ''}" data-emoji="${emoji}" ${index >= unlockedAvatars.length ? 'disabled' : ''} title="${index >= unlockedAvatars.length ? 'Unlock at ' + (index * 100) + ' XP' : ''}">${index >= unlockedAvatars.length ? '🔒' : emoji}</button>`).join('')}</div></div><div class="mb-4"><label class="block mb-2 font-semibold">Scenario Type:</label><select id="scenario-type" class="bg-gray-700 text-white px-4 py-2 rounded focus:outline-none focus:ring-2 focus:ring-green-500 w-full"><option value="AI generated">AI generated</option><option value="Custom">Custom</option></select></div><div class="mb-4"><label class="block mb-2 font-semibold">Game Mode:</label><select id="game-mode" class="bg-gray-700 text-white px-4 py-2 rounded focus:outline-none focus:ring-2 focus:ring-green-500 w-full"><option value="normal">Normal</option><option value="speedrun">Speedrun</option></select></div><button id="start-game" class="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out transform hover:scale-105 w-full mb-4">Start Game</button><button id="how-to-play" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out transform hover:scale-105 w-full">How to Play</button><p class="mt-4 text-xl font-bold">XP: ${xp}</p></div>`;
40+
appContainer.innerHTML = `<div class="text-center bg-gray-800 bg-opacity-90 p-8 rounded-lg shadow-lg"><h2 class="text-3xl mb-4 text-green-400 font-bold">Create Your Character</h2><input id="player-name" class="bg-gray-700 text-white px-4 py-2 rounded focus:outline-none focus:ring-2 focus:ring-green-500 w-full mb-4" placeholder="Enter your name (optional)" value="${randomUsernames[Math.floor(Math.random() * randomUsernames.length)]}"><div class="mb-4"><label class="block mb-2 font-semibold">Choose your avatar:</label><div class="flex justify-center flex-wrap">${avatars.map((emoji, index) => `<button class="avatar-btn text-2xl p-2 m-1 rounded ${emoji === playerAvatar ? 'bg-green-500' : 'bg-gray-600'}${index >= unlockedAvatars.length ? ' opacity-50 cursor-not-allowed' : ''}" data-emoji="${emoji}"${index >= unlockedAvatars.length ? ' disabled' : ''} title="${index >= unlockedAvatars.length ? 'Unlock at ' + (index * 100) + ' XP' : ''}">${index >= unlockedAvatars.length ? '🔒' : emoji}</button>`).join('')}</div></div><div class="mb-4"><label class="block mb-2 font-semibold">Scenario Type:</label><select id="scenario-type" class="bg-gray-700 text-white px-4 py-2 rounded focus:outline-none focus:ring-2 focus:ring-green-500 w-full"><option value="AI generated">AI generated</option><option value="Custom">Custom</option></select></div><div class="mb-4"><label class="block mb-2 font-semibold">Game Mode:</label><select id="game-mode" class="bg-gray-700 text-white px-4 py-2 rounded focus:outline-none focus:ring-2 focus:ring-green-500 w-full"><option value="normal">Normal</option><option value="speedrun">Speedrun</option></select></div><button id="start-game" class="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out transform hover:scale-105 w-full mb-4">Start Game</button><button id="how-to-play" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out transform hover:scale-105 w-full">How to Play</button><p class="mt-4 text-xl font-bold">XP: ${xp}</p></div>`;
5341
document.querySelectorAll('.avatar-btn:not([disabled])').forEach(btn => btn.addEventListener('click', (e) => {
5442
document.querySelectorAll('.avatar-btn').forEach(b => b.classList.remove('bg-green-500'));
5543
e.target.classList.add('bg-green-500');
@@ -75,12 +63,7 @@
7563
async function nextRound() {
7664
if (currentRound < 5) {
7765
currentRound++;
78-
let scenario;
79-
if (scenarioType === 'Custom') {
80-
scenario = await promptForCustomScenario();
81-
} else {
82-
scenario = await generateScenario();
83-
}
66+
let scenario = scenarioType === 'Custom' ? await promptForCustomScenario() : await generateScenario();
8467
renderPromptInput(scenario);
8568
} else {
8669
renderScoreboard();
@@ -91,8 +74,7 @@
9174
return new Promise((resolve) => {
9275
appContainer.innerHTML = `<div class="text-center bg-gray-800 bg-opacity-90 p-8 rounded-lg shadow-lg"><h2 class="text-3xl mb-4 text-green-400 font-bold">Enter Custom Scenario</h2><textarea id="custom-scenario" class="bg-gray-700 text-white px-4 py-2 rounded focus:outline-none focus:ring-2 focus:ring-green-500 w-full h-32 mb-4" placeholder="Enter your custom scenario..."></textarea><button id="submit-scenario" class="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out transform hover:scale-105 w-full">Submit</button></div>`;
9376
document.getElementById('submit-scenario').addEventListener('click', () => {
94-
const customScenario = document.getElementById('custom-scenario').value || "You find yourself in a mysterious and dangerous situation.";
95-
resolve(customScenario);
77+
resolve(document.getElementById('custom-scenario').value || "You find yourself in a mysterious and dangerous situation.");
9678
});
9779
});
9880
}
@@ -187,16 +169,7 @@
187169
xp += 5;
188170
}
189171
localStorage.setItem('deathByAIXP', xp.toString());
190-
appContainer.innerHTML = `<div class="text-center bg-gray-800 bg-opacity-90 p-8 rounded-lg shadow-lg opacity-0 transition-opacity duration-1000" id="fate-container">
191-
<h2 class="text-3xl mb-4 text-green-400 font-bold">Your Fate</h2>
192-
<p class="text-xl mb-4 font-semibold">${fate.explanation}</p>
193-
<p class="text-2xl font-bold ${fate.survived ? 'text-green-400' : 'text-red-400'}">${fate.survived ? 'You survived!' : 'You died!'}</p>
194-
${isSpeedrun ? `
195-
<p class="text-xl mb-4 font-semibold">Round Time: ${roundTime.toFixed(2)}s</p>
196-
<p class="text-xl mb-4 font-semibold">Total Speedrun Time: ${totalSpeedrunTime.toFixed(2)}s</p>
197-
` : ''}
198-
<button id="next-round" class="mt-4 bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out transform hover:scale-105 w-full">Next Round</button>
199-
</div>`;
172+
appContainer.innerHTML = `<div class="text-center bg-gray-800 bg-opacity-90 p-8 rounded-lg shadow-lg opacity-0 transition-opacity duration-1000" id="fate-container"><h2 class="text-3xl mb-4 text-green-400 font-bold">Your Fate</h2><p class="text-xl mb-4 font-semibold">${fate.explanation}</p><p class="text-2xl font-bold ${fate.survived ? 'text-green-400' : 'text-red-400'}">${fate.survived ? 'You survived!' : 'You died!'}</p>${isSpeedrun ? `<p class="text-xl mb-4 font-semibold">Round Time: ${roundTime.toFixed(2)}s</p><p class="text-xl mb-4 font-semibold">Total Speedrun Time: ${totalSpeedrunTime.toFixed(2)}s</p>` : ''}<button id="next-round" class="mt-4 bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out transform hover:scale-105 w-full">Next Round</button></div>`;
200173
setTimeout(() => {
201174
document.getElementById('fate-container').classList.remove('opacity-0');
202175
}, 100);
@@ -213,28 +186,12 @@ <h2 class="text-3xl mb-4 text-green-400 font-bold">Your Fate</h2>
213186
function renderScoreboard() {
214187
const highScore = Math.max(playerScore, parseInt(localStorage.getItem('deathByAIHighScore') || '0'));
215188
localStorage.setItem('deathByAIHighScore', highScore.toString());
216-
217189
let speedrunHighScore = parseFloat(localStorage.getItem('deathByAISpeedrunHighScore') || '999999');
218190
if (isSpeedrun && totalSpeedrunTime < speedrunHighScore) {
219191
speedrunHighScore = totalSpeedrunTime;
220192
localStorage.setItem('deathByAISpeedrunHighScore', speedrunHighScore.toString());
221193
}
222-
223-
appContainer.innerHTML = `
224-
<div class="text-center bg-gray-800 bg-opacity-90 p-8 rounded-lg shadow-lg">
225-
<h2 class="text-3xl mb-4 text-green-400 font-bold">Game Over</h2>
226-
<p class="text-2xl mb-2 font-semibold">${playerName} ${playerAvatar}</p>
227-
<p class="text-xl mb-4 font-semibold">Your final score: ${playerScore}/5</p>
228-
<p class="text-xl mb-4 font-semibold">High Score: ${highScore}/5</p>
229-
${isSpeedrun ? `
230-
<p class="text-xl mb-4 font-semibold">Total Speedrun Time: ${totalSpeedrunTime.toFixed(2)}s</p>
231-
<p class="text-xl mb-4 font-semibold">Speedrun High Score: ${speedrunHighScore.toFixed(2)}s</p>
232-
` : ''}
233-
<p class="text-xl mb-4 font-bold">XP: ${xp}</p>
234-
<button id="new-game" class="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out transform hover:scale-105 w-full mb-4">New Game</button>
235-
<button id="how-to-play" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out transform hover:scale-105 w-full">How to Play</button>
236-
</div>`;
237-
194+
appContainer.innerHTML = `<div class="text-center bg-gray-800 bg-opacity-90 p-8 rounded-lg shadow-lg"><h2 class="text-3xl mb-4 text-green-400 font-bold">Game Over</h2><p class="text-2xl mb-2 font-semibold">${playerName} ${playerAvatar}</p><p class="text-xl mb-4 font-semibold">Your final score: ${playerScore}/5</p><p class="text-xl mb-4 font-semibold">High Score: ${highScore}/5</p>${isSpeedrun ? `<p class="text-xl mb-4 font-semibold">Total Speedrun Time: ${totalSpeedrunTime.toFixed(2)}s</p><p class="text-xl mb-4 font-semibold">Speedrun High Score: ${speedrunHighScore.toFixed(2)}s</p>` : ''}<p class="text-xl mb-4 font-bold">XP: ${xp}</p><button id="new-game" class="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out transform hover:scale-105 w-full mb-4">New Game</button><button id="how-to-play" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out transform hover:scale-105 w-full">How to Play</button></div>`;
238195
document.getElementById('new-game').addEventListener('click', startGame);
239196
document.getElementById('how-to-play').addEventListener('click', showTutorial);
240197
}

0 commit comments

Comments
 (0)