Spaces:
Running
Running
File size: 12,528 Bytes
2e483ce |
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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enhanced Robotic Hangman</title>
<style>
:root {
--neon-blue: #00f3ff;
--neon-pink: #ff00ff;
--dark-gray: #1a1a1a;
--light-gray: #333;
--robot-color: #4ae;
}
body {
margin: 0;
min-height: 100vh;
background: var(--dark-gray);
color: var(--neon-blue);
font-family: 'Courier New', monospace;
padding: 20px;
}
.game-container {
max-width: 1000px;
margin: 0 auto;
display: grid;
grid-template-columns: 300px 1fr;
gap: 20px;
}
.sidebar {
background: var(--light-gray);
padding: 20px;
border-radius: 10px;
border: 2px solid var(--neon-blue);
box-shadow: 0 0 10px var(--neon-blue);
}
.main-game {
background: var(--light-gray);
padding: 20px;
border-radius: 10px;
border: 2px solid var(--neon-blue);
box-shadow: 0 0 10px var(--neon-blue);
}
.difficulty-btns {
display: grid;
gap: 10px;
margin-bottom: 20px;
}
button {
background: transparent;
border: 1px solid var(--neon-blue);
color: var(--neon-blue);
padding: 10px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s;
font-family: 'Courier New', monospace;
}
button:hover {
background: var(--neon-blue);
color: var(--dark-gray);
box-shadow: 0 0 10px var(--neon-blue);
}
.robot-display {
font-family: monospace;
white-space: pre;
color: var(--robot-color);
text-shadow: 0 0 5px var(--robot-color);
margin: 20px 0;
}
.word-display {
font-size: 2.5em;
text-align: center;
margin: 20px 0;
letter-spacing: 10px;
text-shadow: 0 0 5px var(--neon-blue);
}
.keyboard {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
gap: 5px;
margin: 20px 0;
}
.keyboard button {
aspect-ratio: 1;
font-size: 1.2em;
}
.keyboard button.used {
opacity: 0.5;
cursor: not-allowed;
}
.stats {
margin-top: 20px;
padding: 10px;
border: 1px solid var(--neon-pink);
border-radius: 5px;
}
.message {
text-align: center;
height: 2em;
color: var(--neon-pink);
}
@keyframes neonFlicker {
0%, 19%, 21%, 23%, 25%, 54%, 56%, 100% {
text-shadow: 0 0 5px var(--neon-blue),
0 0 10px var(--neon-blue),
0 0 20px var(--neon-blue);
}
20%, 22%, 24%, 55% {
text-shadow: none;
}
}
.neon-text {
animation: neonFlicker 2s infinite;
}
@media (max-width: 768px) {
.game-container {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="game-container">
<div class="sidebar">
<h2 class="neon-text">DIFFICULTY</h2>
<div class="difficulty-btns">
<button data-diff="easy">EASY</button>
<button data-diff="medium">MEDIUM</button>
<button data-diff="hard">HARD</button>
</div>
<h2 class="neon-text">STATS</h2>
<div class="stats">
<p>Wins: <span id="wins">0</span></p>
<p>Losses: <span id="losses">0</span></p>
<p>Current Streak: <span id="streak">0</span></p>
</div>
<button id="hint-btn">GET HINT</button>
<button id="new-game-btn">NEW GAME</button>
</div>
<div class="main-game">
<div class="robot-display"></div>
<div class="word-display"></div>
<div class="message"></div>
<div class="keyboard"></div>
</div>
</div>
<script>
const words = {
easy: [
{ word: 'BOT', hint: 'Automated program', category: 'TECH' },
{ word: 'RAM', hint: 'Computer memory', category: 'TECH' },
{ word: 'CPU', hint: 'Brain of computer', category: 'TECH' },
{ word: 'APP', hint: 'Mobile software', category: 'TECH' },
{ word: 'WEB', hint: 'Internet pages', category: 'TECH' },
{ word: 'NET', hint: 'Type of network', category: 'TECH' },
{ word: 'USB', hint: 'Connection type', category: 'TECH' },
{ word: 'LED', hint: 'Light type', category: 'TECH' },
{ word: 'API', hint: 'Interface for developers', category: 'TECH' },
{ word: 'HTML', hint: 'Markup language', category: 'TECH' }
],
medium: [
{ word: 'ROBOT', hint: 'Mechanical being', category: 'TECH' },
{ word: 'CYBER', hint: 'Digital realm', category: 'TECH' },
{ word: 'LASER', hint: 'Light beam', category: 'TECH' },
{ word: 'PIXEL', hint: 'Screen dot', category: 'TECH' },
{ word: 'VIRUS', hint: 'Malicious software', category: 'TECH' },
{ word: 'CACHE', hint: 'Data storage', category: 'TECH' },
{ word: 'GAMER', hint: 'Video player', category: 'TECH' },
{ word: 'CLOUD', hint: 'Internet storage', category: 'TECH' },
{ word: 'EMAIL', hint: 'Electronic message', category: 'TECH' },
{ word: 'SMART', hint: 'Intelligent device', category: 'TECH' }
],
hard: [
{ word: 'ANDROID', hint: 'Mobile OS', category: 'TECH' },
{ word: 'QUANTUM', hint: 'Smallest unit', category: 'SCIENCE' },
{ word: 'NETWORK', hint: 'Connected systems', category: 'TECH' },
{ word: 'PROGRAM', hint: 'Software code', category: 'TECH' },
{ word: 'COMPILE', hint: 'Code process', category: 'TECH' },
{ word: 'ROUTING', hint: 'Data path', category: 'TECH' },
{ word: 'ENCRYPT', hint: 'Secure data', category: 'TECH' },
{ word: 'ANALYZE', hint: 'Examine data', category: 'TECH' },
{ word: 'BACKEND', hint: 'Server side code', category: 'TECH' },
{ word: 'FRONTEND', hint: 'User interface code', category: 'TECH' }
]
};
class HangmanGame {
constructor() {
this.difficulty = 'medium';
this.word = '';
this.hint = '';
this.guessed = new Set();
this.remaining = 6;
this.stats = { wins: 0, losses: 0, streak: 0 };
this.gameActive = true;
this.previousWords = new Set();
this.initElements();
this.initEvents();
this.newGame();
}
initElements() {
this.robotDisplay = document.querySelector('.robot-display');
this.wordDisplay = document.querySelector('.word-display');
this.keyboard = document.querySelector('.keyboard');
this.message = document.querySelector('.message');
this.createKeyboard();
}
initEvents() {
document.querySelectorAll('[data-diff]').forEach(btn => {
btn.addEventListener('click', () => {
this.difficulty = btn.dataset.diff;
this.newGame();
});
});
document.getElementById('hint-btn').addEventListener('click', () => this.showHint());
document.getElementById('new-game-btn').addEventListener('click', () => this.newGame());
}
createKeyboard() {
for (let i = 65; i <= 90; i++) {
const btn = document.createElement('button');
btn.textContent = String.fromCharCode(i);
btn.addEventListener('click', (e) => this.handleGuess(e.target));
this.keyboard.appendChild(btn);
}
}
newGame() {
const wordPool = words[this.difficulty];
let wordData;
do {
wordData = wordPool[Math.floor(Math.random() * wordPool.length)];
} while (this.previousWords.has(wordData.word));
this.previousWords.add(wordData.word);
if (this.previousWords.size > 5) { // To prevent too large set
this.previousWords.clear();
}
this.word = wordData.word;
this.hint = wordData.hint;
this.guessed.clear();
this.remaining = 6;
this.gameActive = true;
this.keyboard.querySelectorAll('button').forEach(btn => {
btn.classList.remove('used');
btn.disabled = false;
});
this.updateDisplays();
this.message.textContent = '';
}
handleGuess(button) {
if (!this.gameActive) return;
const letter = button.textContent;
if (this.guessed.has(letter)) return;
this.guessed.add(letter);
button.classList.add('used');
button.disabled = true;
if (!this.word.includes(letter)) {
this.remaining--;
}
this.updateDisplays();
this.checkGameEnd();
}
updateDisplays() {
this.wordDisplay.textContent = [...this.word]
.map(letter => this.guessed.has(letter) ? letter : '_')
.join(' ');
this.updateRobot();
}
updateRobot() {
const stages = [
`
/\\___/\\
( o o )
( =^= )
(______)`,
`
/\\___/\\
( x o )
( =^= )
(______)`,
`
/\\___/\\
( x x )
( =^= )
(______)`,
`
/\\___/\\
( x x )
( =-= )
(______)`,
`
/\\___/\\
( x x )
( =-= )
(__-___)`,
`
/\\___/\\
( x x )
( =-= )
(_____)`
];
this.robotDisplay.textContent = stages[6 - this.remaining];
}
showHint() {
this.message.textContent = this.hint;
setTimeout(() => this.message.textContent = '', 3000);
}
checkGameEnd() {
const won = [...this.word].every(letter => this.guessed.has(letter));
const lost = this.remaining === 0;
if (won) {
this.stats.wins++;
this.stats.streak++;
this.message.textContent = '🤖 MISSION ACCOMPLISHED';
this.gameActive = false;
} else if (lost) {
this.stats.losses++;
this.stats.streak = 0;
this.message.textContent = `🤖 SYSTEM FAILURE - WORD WAS: ${this.word}`;
this.gameActive = false;
}
this.updateStats();
}
updateStats() {
document.getElementById('wins').textContent = this.stats.wins;
document.getElementById('losses').textContent = this.stats.losses;
document.getElementById('streak').textContent = this.stats.streak;
}
}
new HangmanGame();
</script>
</body>
</html> |