Size şık ve modern tasarımlı bir yılan oyunu hazırlayayım! İşte HTML, CSS ve JavaScript ile yapılmış güzel bir oyun:
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Şık Yılan Oyunu</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
color: white;
}
.game-container {
text-align: center;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 30px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.2);
}
h1 {
margin-bottom: 20px;
font-size: 2.5em;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.score-board {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
font-size: 1.2em;
font-weight: bold;
}
#gameCanvas {
border: 3px solid rgba(255, 255, 255, 0.3);
border-radius: 15px;
background: rgba(0, 0, 0, 0.2);
box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.3);
}
.controls {
margin-top: 20px;
font-size: 1.1em;
}
.control-info {
margin-top: 10px;
opacity: 0.8;
font-size: 0.9em;
}
.game-over {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(0, 0, 0, 0.8);
color: white;
padding: 30px;
border-radius: 15px;
text-align: center;
display: none;
backdrop-filter: blur(10px);
}
.restart-btn {
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border: none;
color: white;
padding: 15px 30px;
font-size: 1.1em;
border-radius: 25px;
cursor: pointer;
margin-top: 15px;
transition: transform 0.2s;
}
.restart-btn:hover {
transform: scale(1.05);
}
</style>
</head>
<body>
<div class="game-container">
<h1>🐍 Şık Yılan Oyunu</h1>
<div class="score-board">
<div>Skor: <span id="score">0</span></div>
<div>En Yüksek: <span id="highScore">0</span></div>
</div>
<canvas id="gameCanvas" width="400" height="400"></canvas>
<div class="controls">
<div>WASD veya Ok tuşları ile oynayın</div>
<div class="control-info">Elmaları toplayın ve büyüyün! 🍎</div>
</div>
<div class="game-over" id="gameOver">
<h2>Oyun Bitti! 💀</h2>
<p>Final Skorunuz: <span id="finalScore">0</span></p>
<button class="restart-btn" onclick="restartGame()">Tekrar Oyna</button>
</div>
</div>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
const scoreElement = document.getElementById('score');
const highScoreElement = document.getElementById('highScore');
const gameOverElement = document.getElementById('gameOver');
const finalScoreElement = document.getElementById('finalScore');
// Oyun değişkenleri
const gridSize = 20;
const tileCount = canvas.width / gridSize;
let snake = [
{x: 10, y: 10}
];
let food = {};
let dx = 0;
let dy = 0;
let score = 0;
let highScore = localStorage.getItem('snakeHighScore') || 0;
highScoreElement.textContent = highScore;
// Rastgele yemek konumu
function randomFood() {
food = {
x: Math.floor(Math.random() * tileCount),
y: Math.floor(Math.random() * tileCount)
};
}
// Oyunu çiz
function drawGame() {
// Arka planı temizle
ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Yılanı çiz (gradyan efekti)
snake.forEach((segment, index) => {
const gradient = ctx.createRadialGradient(
segment.x * gridSize + gridSize/2,
segment.y * gridSize + gridSize/2,
0,
segment.x * gridSize + gridSize/2,
segment.y * gridSize + gridSize/2,
gridSize/2
);
if (index === 0) {
// Kafa - daha parlak
gradient.addColorStop(0, '#4ecdc4');
gradient.addColorStop(1, '#44a08d');
} else {
// Vücut - daha koyu
gradient.addColorStop(0, '#667eea');
gradient.addColorStop(1, '#764ba2');
}
ctx.fillStyle = gradient;
ctx.fillRect(segment.x * gridSize + 2, segment.y * gridSize + 2, gridSize - 4, gridSize - 4);
ctx.strokeStyle = 'rgba(255, 255, 255, 0.3)';
ctx.lineWidth = 1;
ctx.strokeRect(segment.x * gridSize + 2, segment.y * gridSize + 2, gridSize - 4, gridSize - 4);
});
// Yemeği çiz (elma)
const foodGradient = ctx.createRadialGradient(
food.x * gridSize + gridSize/2,
food.y * gridSize + gridSize/2,
0,
food.x * gridSize + gridSize/2,
food.y * gridSize + gridSize/2,
gridSize/2
);
foodGradient.addColorStop(0, '#ff6b6b');
foodGradient.addColorStop(1, '#ee5a24');
ctx.fillStyle = foodGradient;
ctx.fillRect(food.x * gridSize + 2, food.y * gridSize + 2, gridSize - 4, gridSize - 4);
ctx.strokeStyle = 'rgba(255, 255, 255, 0.5)';
ctx.strokeRect(food.x * gridSize + 2, food.y * gridSize + 2, gridSize - 4, gridSize - 4);
}
// Yılanı hareket ettir
function moveSnake() {
const head = {x: snake[0].x + dx, y: snake[0].y + dy};
// Duvara çarpma kontrolü
if (head.x < 0 || head.x >= tileCount || head.y < 0 || head.y >= tileCount) {
gameOver();
return;
}
// Kendine çarpma kontrolü
for (let segment of snake) {
if (head.x === segment.x && head.y === segment.y) {
gameOver();
return;
}
}
snake.unshift(head);
// Yemek yeme kontrolü
if (head.x === food.x && head.y === food.y) {
score += 10;
scoreElement.textContent = score;
randomFood();
} else {
snake.pop();
}
}
// Oyun bitişi
function gameOver() {
if (score > highScore) {
highScore = score;
localStorage.setItem('snakeHighScore', highScore);
highScoreElement.textContent = highScore;
}
finalScoreElement.textContent = score;
gameOverElement.style.display = 'block';
}
// Oyunu yeniden başlat
function restartGame() {
snake = [{x: 10, y: 10}];
dx = 0;
dy = 0;
score = 0;
scoreElement.textContent = score;
gameOverElement.style.display = 'none';
randomFood();
}
// Klavye kontrolü
document.addEventListener('keydown', (e) => {
if (gameOverElement.style.display === 'block') return;
switch(e.key) {
case 'ArrowUp':
case 'w':
case 'W':
if (dy !== 1) { dx = 0; dy = -1; }
break;
case 'ArrowDown':
case 's':
case 'S':
if (dy !== -1) { dx = 0; dy = 1; }
break;
case 'ArrowLeft':
case 'a':
case 'A':
if (dx !== 1) { dx = -1; dy = 0; }
break;
case 'ArrowRight':
case 'd':
case 'D':
if (dx !== -1) { dx = 1; dy = 0; }
break;
}
});
// Oyun döngüsü
function gameLoop() {
drawGame();
moveSnake();
}
// Oyunu başlat
randomFood();
setInterval(gameLoop, 120);
</script>
</body>
</html>
Bu yılan oyunu şu özelliklere sahip:
🎨 Tasarım Özellikleri:
- Modern cam efekti (glassmorphism) tasarım
- Gradyan renkler ve geçişler
- Yumuşak gölgeler ve kenar yuvarlaklıkları
- Yılan için parlak gradyan efektler
🎮 Oyun Özellikleri:
- WASD veya ok tuşları ile kontrol
- Skor sistemi ve en yüksek skor kaydı
- Yeniden oynama özelliği
- Responsive tasarım
Bu kodu bir .html dosyası olarak kaydedin ve tarayıcınızda açın. Hemen oynamaya başlayabilirsiniz! Oyun tamamen çevrimdışı çalışır ve skorlarınızı hatırlar.