krying
Version:
krying — games hub, AI, movies, and tools
466 lines (389 loc) • 14 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kobran - Color Matcher</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: 32rem;
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;
}
.start-screen {
text-align: center;
}
.start-screen h3 {
color: white;
font-size: 1.25rem;
margin-bottom: 1.5rem;
}
.instructions {
color: rgba(255, 255, 255, 0.8);
margin-bottom: 2rem;
line-height: 1.5;
}
.instructions p {
margin-bottom: 0.5rem;
}
.color-display {
margin-bottom: 1.5rem;
}
.color-box {
width: 12rem;
height: 12rem;
margin: 0 auto 1rem;
border-radius: 0.5rem;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}
.color-name {
font-size: 2.5rem;
font-weight: bold;
color: white;
margin-bottom: 0.5rem;
}
.color-question {
color: rgba(255, 255, 255, 0.6);
}
.answer-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
max-width: 24rem;
margin: 0 auto 1.5rem;
}
.answer-btn {
padding: 1rem;
border: none;
border-radius: 0.5rem;
font-size: 1.125rem;
font-weight: bold;
cursor: pointer;
transition: all 0.2s ease;
color: white;
}
.match-btn {
background: #16a34a;
}
.match-btn:hover {
background: #15803d;
}
.no-match-btn {
background: #dc2626;
}
.no-match-btn:hover {
background: #b91c1c;
}
.streak-indicator {
text-align: center;
margin-top: 1rem;
}
.streak-text {
color: #f59e0b;
font-weight: bold;
}
.bonus-text {
color: rgba(255, 255, 255, 0.8);
margin-left: 0.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;
margin: 0 0.5rem;
}
.btn:hover {
background: rgba(255, 255, 255, 0.3);
}
.btn-green {
background: #16a34a;
}
.btn-green:hover {
background: #15803d;
}
.btn-yellow {
background: #ca8a04;
}
.btn-yellow:hover {
background: #a16207;
}
.btn-red {
background: #dc2626;
}
.btn-red:hover {
background: #b91c1c;
}
.controls {
display: flex;
justify-content: center;
margin-top: 1.5rem;
}
.game-over {
text-align: center;
margin-bottom: 1.5rem;
padding: 1.5rem;
background: rgba(59, 130, 246, 0.2);
border: 1px solid rgba(59, 130, 246, 0.3);
border-radius: 0.5rem;
}
.game-over h3 {
color: white;
font-size: 1.5rem;
margin-bottom: 0.5rem;
}
.game-over-stats {
color: rgba(255, 255, 255, 0.8);
line-height: 1.5;
}
.game-over-stats p {
margin-bottom: 0.5rem;
}
.final-score {
font-weight: bold;
color: white;
}
.instructions-footer {
text-align: center;
color: rgba(255, 255, 255, 0.6);
font-size: 0.875rem;
margin-top: 1.5rem;
}
.instructions-footer p {
margin-bottom: 0.25rem;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<div class="game-card">
<h1 class="game-title">🎨 Color Matcher</h1>
<div class="game-stats">
<span>Score: <span id="score">0</span></span>
<span>⏱️ <span id="timeLeft">30</span>s</span>
<span>Streak: <span id="streak">0</span></span>
</div>
<div id="startScreen" class="start-screen">
<h3>How to Play</h3>
<div class="instructions">
<p>A color will be displayed with a color name</p>
<p>Click "MATCH" if the color matches the name</p>
<p>Click "NO MATCH" if they don't match</p>
<p>Be fast and accurate for bonus points!</p>
<p>Have Fun!</p>
</div>
<button class="btn btn-green" onclick="startGame()">▶️ Start Game</button>
</div>
<div id="gameScreen" class="hidden">
<div class="color-display">
<div class="color-box" id="colorBox"></div>
<div class="color-name" id="colorName"></div>
<div class="color-question">Does the color match the name?</div>
</div>
<div class="answer-buttons">
<button class="answer-btn match-btn" onclick="handleAnswer(true)">
MATCH
<span style="margin-left: 0.5rem; font-size: 0.875rem; opacity: 0.75;">(1)</span>
</button>
<button class="answer-btn no-match-btn" onclick="handleAnswer(false)">
NO MATCH
<span style="margin-left: 0.5rem; font-size: 0.875rem; opacity: 0.75;">(2)</span>
</button>
</div>
<div id="streakIndicator" class="streak-indicator" style="display: none;">
<div class="streak-text">
🔥 <span id="streakCount">0</span> Streak!
<span class="bonus-text">+<span id="bonusPoints">0</span> bonus points</span>
</div>
</div>
<div class="controls">
<button class="btn btn-yellow" onclick="pauseGame()">⏸️ Pause</button>
<button class="btn" onclick="resetGame()">🔄 Reset</button>
</div>
</div>
<div id="gameOverScreen" class="hidden">
<div class="game-over">
<h3>Time's Up!</h3>
<div class="game-over-stats">
<p>Final Score: <span class="final-score" id="finalScore">0</span></p>
<p>Best Streak: <span class="final-score" id="bestStreak">0</span></p>
<p id="averageScore" style="display: none;">Average per second: <span id="avgPerSecond">0</span> points</p>
</div>
</div>
<div class="controls">
<button class="btn btn-green" onclick="startGame()">▶️ Play Again</button>
<button class="btn" onclick="resetToStart()">🔄 Reset</button>
</div>
</div>
<div class="instructions-footer">
<p>Use keys 1 and 2 for quick answers!</p>
<p>Higher streaks = more bonus points!</p>
</div>
</div>
<script>
const COLORS = [
{ name: 'Red', hex: '#ef4444' },
{ name: 'Blue', hex: '#3b82f6' },
{ name: 'Green', hex: '#10b981' },
{ name: 'Yellow', hex: '#f59e0b' },
{ name: 'Purple', hex: '#8b5cf6' },
{ name: 'Pink', hex: '#ec4899' },
{ name: 'Orange', hex: '#f97316' },
{ name: 'Cyan', hex: '#06b6d4' }
];
let currentColor = null;
let colorName = '';
let isMatching = false;
let score = 0;
let timeLeft = 30;
let isPlaying = false;
let gameOver = false;
let streak = 0;
let bestStreak = 0;
let gameTimer = null;
function generateRound() {
const targetColor = COLORS[Math.floor(Math.random() * COLORS.length)];
isMatching = Math.random() < 0.5;
const nameColor = isMatching ? targetColor : COLORS[Math.floor(Math.random() * COLORS.length)];
currentColor = targetColor;
colorName = nameColor.name;
document.getElementById('colorBox').style.backgroundColor = targetColor.hex;
document.getElementById('colorName').textContent = nameColor.name;
}
function handleAnswer(selectedMatch) {
if (!isPlaying || gameOver) return;
const isCorrect = selectedMatch === isMatching;
if (isCorrect) {
score += (10 + streak * 2);
streak++;
bestStreak = Math.max(bestStreak, streak);
updateStreakDisplay();
} else {
streak = 0;
hideStreakDisplay();
}
updateDisplay();
setTimeout(generateRound, 300);
}
function updateDisplay() {
document.getElementById('score').textContent = score;
document.getElementById('timeLeft').textContent = timeLeft;
document.getElementById('streak').textContent = streak;
}
function updateStreakDisplay() {
if (streak > 0) {
document.getElementById('streakCount').textContent = streak;
document.getElementById('bonusPoints').textContent = streak * 2;
document.getElementById('streakIndicator').style.display = 'block';
}
}
function hideStreakDisplay() {
document.getElementById('streakIndicator').style.display = 'none';
}
function startGame() {
score = 0;
streak = 0;
timeLeft = 30;
isPlaying = true;
gameOver = false;
showScreen('gameScreen');
generateRound();
updateDisplay();
hideStreakDisplay();
// Start timer
gameTimer = setInterval(() => {
timeLeft--;
updateDisplay();
if (timeLeft <= 0) {
endGame();
}
}, 1000);
}
function pauseGame() {
isPlaying = false;
clearInterval(gameTimer);
}
function resetGame() {
clearInterval(gameTimer);
isPlaying = false;
gameOver = false;
score = 0;
streak = 0;
timeLeft = 30;
updateDisplay();
hideStreakDisplay();
showScreen('startScreen');
}
function resetToStart() {
clearInterval(gameTimer);
bestStreak = 0;
resetGame();
}
function endGame() {
isPlaying = false;
gameOver = true;
clearInterval(gameTimer);
document.getElementById('finalScore').textContent = score;
document.getElementById('bestStreak').textContent = bestStreak;
if (score > 0) {
const avgPerSecond = (score / 30).toFixed(1);
document.getElementById('avgPerSecond').textContent = avgPerSecond;
document.getElementById('averageScore').style.display = 'block';
}
showScreen('gameOverScreen');
}
function showScreen(screenId) {
['startScreen', 'gameScreen', 'gameOverScreen'].forEach(id => {
document.getElementById(id).classList.add('hidden');
});
document.getElementById(screenId).classList.remove('hidden');
}
document.addEventListener('keydown', (e) => {
if (!isPlaying || gameOver) return;
if (e.key === '1') {
handleAnswer(true);
} else if (e.key === '2') {
handleAnswer(false);
}
});
updateDisplay();
</script>
</body>
</html>