stwórz grę labirynt
- User
stwórz grę labirynt
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
stwórz grę labirynt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Oto kompletny kod gry labirynt w jednym pliku HTML. Gra posiada nowoczesny interfejs i jest gotowa do natychmiastowego uruchomienia:
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<title>Labirynt - Gra</title>
<style>
body {
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
min-height: 100vh;
font-family: 'Segoe UI', sans-serif;
color: #e6e6e6;
}
h1 {
margin: 20px 0;
color: #00ff9d;
text-shadow: 0 0 10px rgba(0, 255, 157, 0.5);
}
#gameCanvas {
border: 2px solid #00ff9d;
border-radius: 8px;
box-shadow: 0 0 20px rgba(0, 255, 157, 0.3);
margin: 20px 0;
}
.instructions {
max-width: 600px;
text-align: center;
margin: 15px 0;
color: #a0a0a0;
}
</style>
</head>
<body>
<h1>Labirynt</h1>
<canvas id="gameCanvas" width="500" height="500"></canvas>
<div class="instructions">
<p>Użyj strzałek do poruszania się. Dotarcie do zielonego pola oznacza zwycięstwo!</p>
</div>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
const cellSize = 50;
const player = { x: 1, y: 1 };
const exit = { x: 8, y: 8 };
let gameWon = false;
const maze = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 1, 0, 1],
[1, 0, 1, 0, 0, 0, 1, 0, 0, 1],
[1, 0, 1, 1, 1, 1, 1, 0, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 1, 1, 0, 1, 1, 0, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 0, 0, 1, 1, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
];
function drawMaze() {
ctx.fillStyle = '#0a0a1a';
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let y = 0; y < maze.length; y++) {
for (let x = 0; x < maze[y].length; x++) {
if (maze[y][x] === 1) {
ctx.fillStyle = '#2a2a4a';
ctx.fillRect(x * cellSize, y * cellSize, cellSize, cellSize);
}
}
}
// Rysowanie wyjścia
ctx.fillStyle = '#00ff9d';
ctx.beginPath();
ctx.arc(
exit.x * cellSize + cellSize/2,
exit.y * cellSize + cellSize/2,
cellSize/3,
0,
Math.PI * 2
);
ctx.fill();
}
function drawPlayer() {
ctx.fillStyle = '#ff3e3e';
ctx.beginPath();
ctx.arc(
player.x * cellSize + cellSize/2,
player.y * cellSize + cellSize/2,
cellSize/3,
0,
Math.PI * 2
);
ctx.fill();
ctx.strokeStyle = '#ff9d9d';
ctx.lineWidth = 2;
ctx.stroke();
}
function checkWin() {
if (player.x === exit.x && player.y === exit.y) {
gameWon = true;
ctx.fillStyle = 'rgba(0, 0, 0, 0.7)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.font = '40px Segoe UI';
ctx.fillStyle = '#00ff9d';
ctx.textAlign = 'center';
ctx.fillText('Gratulacje!', canvas.width/2, canvas.height/2);
}
}
function gameLoop() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawMaze();
drawPlayer();
checkWin();
requestAnimationFrame(gameLoop);
}
document.addEventListener('keydown', (e) => {
if (gameWon) return;
const key = e.key;
let newX = player.x;
let newY = player.y;
switch(key) {
case 'ArrowUp': newY--; break;
case 'ArrowDown': newY++; break;
case 'ArrowLeft': newX--; break;
case 'ArrowRight': newX++; break;
}
if (
newX >= 0 && newX < maze[0].length &&
newY >= 0 && newY < maze.length &&
maze[newY][newX] === 0
) {
player.x = newX;
player.y = newY;
}
});
gameLoop();
</script>
</body>
</html>
Ta implementacja zawiera:
Aby uruchomić grę, wystarczy zapisać kod jako plik HTML i otworzyć w przeglądarce. Gracz porusza się strzałkami klawiatury, a celem jest dotarcie do zielonego pola.