UNPKG

krying

Version:

krying — games hub, AI, movies, and tools

507 lines (422 loc) • 16 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Kobran - Guess The Word</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: linear-gradient(135deg, #581c87, #1e3a8a, #3730a3); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; } .game-card { background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 0.75rem; padding: 1.5rem; width: 100%; max-width: 28rem; backdrop-filter: blur(10px); } .game-title { color: white; text-align: center; font-size: 1.5rem; font-weight: bold; margin-bottom: 1rem; } .game-stats { display: flex; justify-content: space-between; color: white; margin-bottom: 1.5rem; } .game-board { display: grid; grid-template-rows: repeat(6, 1fr); gap: 0.5rem; margin-bottom: 1.5rem; } .word-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.5rem; } .letter-tile { width: 3rem; height: 3rem; border: 2px solid rgba(255, 255, 255, 0.3); border-radius: 0.25rem; display: flex; align-items: center; justify-content: center; font-size: 1.125rem; font-weight: bold; color: white; transition: all 0.3s ease; } .tile-empty { background: rgba(255, 255, 255, 0.1); } .tile-current { background: rgba(255, 255, 255, 0.2); border-color: rgba(255, 255, 255, 0.5); } .tile-correct { background: #10b981; border-color: #10b981; } .tile-present { background: #f59e0b; border-color: #f59e0b; } .tile-absent { background: #6b7280; border-color: #6b7280; } .virtual-keyboard { margin-bottom: 1.5rem; } .keyboard-row { display: flex; justify-content: center; gap: 0.25rem; margin-bottom: 0.5rem; } .key { background: rgba(255, 255, 255, 0.2); border: none; color: white; border-radius: 0.25rem; cursor: pointer; font-size: 0.75rem; font-weight: 500; transition: all 0.2s ease; height: 2rem; min-width: 2rem; display: flex; align-items: center; justify-content: center; } .key:hover:not(:disabled) { background: rgba(255, 255, 255, 0.3); } .key-wide { padding: 0 0.75rem; } .key-correct { background: #10b981; } .key-present { background: #f59e0b; } .key-absent { background: #6b7280; } .controls { display: flex; justify-content: center; gap: 1rem; margin-bottom: 1.5rem; } .btn { background: rgba(255, 255, 255, 0.2); border: 1px solid rgba(255, 255, 255, 0.3); color: white; padding: 0.5rem 1rem; border-radius: 0.375rem; cursor: pointer; font-weight: 500; transition: all 0.2s ease; } .btn:hover { background: rgba(255, 255, 255, 0.3); } .win-message, .lose-message { text-align: center; padding: 1rem; border-radius: 0.5rem; margin-bottom: 1rem; } .win-message { background: rgba(16, 185, 129, 0.2); border: 1px solid rgba(16, 185, 129, 0.3); } .lose-message { background: rgba(239, 68, 68, 0.2); border: 1px solid rgba(239, 68, 68, 0.3); } .message-title { font-weight: bold; margin-bottom: 0.5rem; display: flex; align-items: center; justify-content: center; gap: 0.5rem; } .win-title { color: #10b981; } .lose-title { color: #ef4444; } .message-content { color: rgba(255, 255, 255, 0.8); } .instructions { text-align: center; color: rgba(255, 255, 255, 0.6); font-size: 0.875rem; line-height: 1.4; } .color-guide { text-align: center; color: rgba(255, 255, 255, 0.6); font-size: 0.75rem; margin-top: 1rem; } .color-guide p { margin-bottom: 0.25rem; } .hidden { display: none; } </style> </head> <body> <div class="game-card"> <h1 class="game-title">📝 Guess The Word 🤔</h1> <div class="game-stats"> <span>Games: <span id="gamesPlayed">0</span></span> <span>Win Rate: <span id="winRate">0</span>%</span> <span>Streak: <span id="winStreak">0</span></span> </div> <div class="game-board" id="gameBoard"></div> <div id="winMessage" class="win-message hidden"> <div class="message-title win-title"> ✅ Congratulations! You Won! </div> <div class="message-content"> <p>You guessed it in <span id="guessCount">0</span> tries!</p> <p>Score: <span id="finalScore">0</span></p> </div> </div> <div id="loseMessage" class="lose-message hidden"> <div class="message-title lose-title"> ❌ Game Over! Better Luck Next Time! </div> <div class="message-content"> <p>The word was: <span id="correctWord" style="font-weight: bold; color: white;"></span></p> </div> </div> <div class="virtual-keyboard" id="keyboard"></div> <div class="controls"> <button class="btn" onclick="newGame()">🔄 New Word</button> </div> <div class="instructions"> <p>Guess the 5-letter word in 6 tries</p> </div> <div class="color-guide"> <p>🟩 Green: Correct letter in the correct position</p> <p>🟨 Yellow: Correct letter, but it is in the wrong position</p> <p>⬜ Gray: Letter not is not in the word</p> </div> </div> <script> const WORDS = [ 'REACT', 'APPLE', 'BEACH', 'CHAIR', 'DANCE', 'EAGLE', 'FLAME', 'GRAPE', 'HOUSE', 'JOKER', 'KNIFE', 'LIGHT', 'MOUSE', 'NIGHT', 'OCEAN', 'PIANO', 'QUEEN', 'ROBOT', 'SNAKE', 'TIGER', 'UNCLE', 'VOICE', 'WHALE', 'ZEBRA', 'BREAD', 'CLOUD', 'DREAM', 'EARTH', 'FIELD', 'GLASS', 'HEART', 'IMAGE', 'MUSIC', 'PHONE', 'SMILE', 'STONE', 'SWEET', 'WATER', 'WORLD', 'YOUTH' ]; const KEYBOARD_LAYOUT = [ ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'], ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'], ['ENTER', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', 'BACKSPACE'] ]; const MAX_GUESSES = 6; const WORD_LENGTH = 5; let targetWord = ''; let guesses = []; let currentGuess = ''; let currentRow = 0; let gameState = 'playing'; let gamesPlayed = 0; let gamesWon = 0; let keyStates = {}; function initializeGame() { targetWord = WORDS[Math.floor(Math.random() * WORDS.length)]; guesses = Array(MAX_GUESSES).fill(''); currentGuess = ''; currentRow = 0; gameState = 'playing'; keyStates = {}; renderBoard(); renderKeyboard(); hideMessages(); updateStats(); } function renderBoard() { const board = document.getElementById('gameBoard'); board.innerHTML = ''; for (let row = 0; row < MAX_GUESSES; row++) { const rowElement = document.createElement('div'); rowElement.className = 'word-row'; for (let col = 0; col < WORD_LENGTH; col++) { const tile = document.createElement('div'); tile.className = 'letter-tile'; let letter = ''; let tileClass = 'tile-empty'; if (row < currentRow) { letter = guesses[row][col] || ''; tileClass = getLetterState(letter, col, guesses[row]); } else if (row === currentRow) { letter = currentGuess[col] || ''; tileClass = letter ? 'tile-current' : 'tile-empty'; } tile.classList.add(tileClass); tile.textContent = letter; rowElement.appendChild(tile); } board.appendChild(rowElement); } } function renderKeyboard() { const keyboard = document.getElementById('keyboard'); keyboard.innerHTML = ''; KEYBOARD_LAYOUT.forEach(row => { const rowElement = document.createElement('div'); rowElement.className = 'keyboard-row'; row.forEach(key => { const keyElement = document.createElement('button'); keyElement.className = 'key'; keyElement.onclick = () => handleKeyPress(key); if (key === 'ENTER' || key === 'BACKSPACE') { keyElement.classList.add('key-wide'); keyElement.textContent = key === 'BACKSPACE' ? '⌫' : key; } else { keyElement.textContent = key; } const state = keyStates[key]; if (state) { keyElement.classList.add(`key-${state}`); } if (gameState !== 'playing') { keyElement.disabled = true; } rowElement.appendChild(keyElement); }); keyboard.appendChild(rowElement); }); } function getLetterState(letter, position, word) { if (!word) return 'tile-empty'; const targetLetter = targetWord[position]; if (letter === targetLetter) { return 'tile-correct'; } else if (targetWord.includes(letter)) { return 'tile-present'; } else { return 'tile-absent'; } } function updateKeyStates() { for (let i = 0; i < currentRow; i++) { const guess = guesses[i]; if (!guess) continue; for (let j = 0; j < guess.length; j++) { const letter = guess[j]; const state = getLetterState(letter, j, guess); const currentState = keyStates[letter]; if (!currentState || (state === 'tile-correct') || (state === 'tile-present' && currentState !== 'correct')) { keyStates[letter] = state.replace('tile-', ''); } } } } function handleKeyPress(key) { if (gameState !== 'playing') return; if (key === 'ENTER') { submitGuess(); } else if (key === 'BACKSPACE') { currentGuess = currentGuess.slice(0, -1); } else if (key.match(/[A-Z]/) && currentGuess.length < WORD_LENGTH) { currentGuess += key; } renderBoard(); } function submitGuess() { if (currentGuess.length !== WORD_LENGTH) return; if (!WORDS.includes(currentGuess)) { return; } guesses[currentRow] = currentGuess; if (currentGuess === targetWord) { gameState = 'won'; gamesWon++; gamesPlayed++; showWinMessage(); } else if (currentRow === MAX_GUESSES - 1) { gameState = 'lost'; gamesPlayed++; showLoseMessage(); } else { currentRow++; } currentGuess = ''; updateKeyStates(); renderBoard(); renderKeyboard(); updateStats(); } function showWinMessage() { document.getElementById('guessCount').textContent = currentRow + 1; const score = Math.max(0, (MAX_GUESSES - currentRow) * 100 + 200); document.getElementById('finalScore').textContent = score; document.getElementById('winMessage').classList.remove('hidden'); } function showLoseMessage() { document.getElementById('correctWord').textContent = targetWord; document.getElementById('loseMessage').classList.remove('hidden'); } function hideMessages() { document.getElementById('winMessage').classList.add('hidden'); document.getElementById('loseMessage').classList.add('hidden'); } function updateStats() { document.getElementById('gamesPlayed').textContent = gamesPlayed; const winRate = gamesPlayed > 0 ? Math.round((gamesWon / gamesPlayed) * 100) : 0; document.getElementById('winRate').textContent = winRate; document.getElementById('winStreak').textContent = gamesWon; } function newGame() { initializeGame(); } document.addEventListener('keydown', (e) => { const key = e.key.toUpperCase(); if (key === 'ENTER') { handleKeyPress('ENTER'); } else if (key === 'BACKSPACE') { handleKeyPress('BACKSPACE'); } else if (key.match(/[A-Z]/)) { handleKeyPress(key); } e.preventDefault(); }); initializeGame(); </script> </body> </html>