Skip to content
The Chat Archive
minimax-m1· MiniMax LMArena Human Preference 140K

napisz mi kod gry w wężą

  1. User

    napisz mi kod gry w wężą

  2. Assistant

    Oto przykładowy kod gry "Wąż" w HTML/JS/CSS w jednym pliku, z nowoczesnym interfejsem:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Wąż Retro</title>
        <style>
            body {
                margin: 0;
                padding: 20px;
                display: flex;
                flex-direction: column;
                align-items: center;
                background: #121212;
                color: #fff;
                font-family: 'Arial', sans-serif;
            }
    
            canvas {
                border: 2px solid #00ff88;
                border-radius: 5px;
                box-shadow: 0 0 15px #00ff88;
            }
    
            #score {
                font-size: 24px;
                margin: 20px 0;
                color: #00ff88;
            }
        </style>
    </head>
    <body>
        <div id="score">Wynik: 0</div>
        <canvas id="game" width="400" height="400"></canvas>
    
        <script>
            const canvas = document.getElementById('game');
            const ctx = canvas.getContext('2d');
            const scoreElement = document.getElementById('score');
            
            const gridSize = 20;
            let snake = [
                {x: 10, y: 10},
                {x: 9, y: 10},
                {x: 8, y: 10}
            ];
            let food = generateFood();
            let dx = 1;
            let dy = 0;
            let score = 0;
            let gameSpeed = 100;
            let gameLoop;
    
            function generateFood() {
                let newFood;
                do {
                    newFood = {
                        x: Math.floor(Math.random() * (canvas.width/gridSize)),
                        y: Math.floor(Math.random() * (canvas.height/gridSize))
                    };
                } while (snake.some(segment => segment.x === newFood.x && segment.y === newFood.y));
                return newFood;
            }
    
            function drawSnake() {
                snake.forEach((segment, index) => {
                    ctx.fillStyle = `hsl(${index * 10}, 100%, 50%)`;
                    ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize-1, gridSize-1);
                });
            }
    
            function drawFood() {
                ctx.fillStyle = '#ff3366';
                ctx.beginPath();
                ctx.arc(
                    food.x * gridSize + gridSize/2,
                    food.y * gridSize + gridSize/2,
                    gridSize/2 - 2,
                    0,
                    Math.PI * 2
                );
                ctx.fill();
            }
    
            function moveSnake() {
                const head = {x: snake[0].x + dx, y: snake[0].y + dy};
                snake.unshift(head);
    
                if (head.x === food.x && head.y === food.y) {
                    score += 10;
                    scoreElement.textContent = `Wynik: ${score}`;
                    food = generateFood();
                    if (gameSpeed > 50) gameSpeed -= 2;
                    clearInterval(gameLoop);
                    gameLoop = setInterval(gameStep, gameSpeed);
                } else {
                    snake.pop();
                }
    
                // Kolizje
                if (
                    head.x < 0 || head.x >= canvas.width/gridSize ||
                    head.y < 0 || head.y >= canvas.height/gridSize ||
                    snake.slice(1).some(segment => segment.x === head.x && segment.y === head.y)
                ) {
                    gameOver();
                }
            }
    
            function gameStep() {
                ctx.fillStyle = '#121212';
                ctx.fillRect(0, 0, canvas.width, canvas.height);
                
                moveSnake();
                drawSnake();
                drawFood();
            }
    
            function gameOver() {
                clearInterval(gameLoop);
                ctx.fillStyle = 'rgba(0,0,0,0.75)';
                ctx.fillRect(0, 0, canvas.width, canvas.height);
                ctx.fillStyle = '#fff';
                ctx.font = '30px Arial';
                ctx.textAlign = 'center';
                ctx.fillText('Koniec gry!', canvas.width/2, canvas.height/2);
                ctx.font = '20px Arial';
                ctx.fillText(`Wynik końcowy: ${score}`, canvas.width/2, canvas.height/2 + 30);
            }
    
            document.addEventListener('keydown', e => {
                switch(e.key) {
                    case 'ArrowUp': if (dy !== 1) { dx = 0; dy = -1; } break;
                    case 'ArrowDown': if (dy !== -1) { dx = 0; dy = 1; } break;
                    case 'ArrowLeft': if (dx !== 1) { dx = -1; dy = 0; } break;
                    case 'ArrowRight': if (dx !== -1) { dx = 1; dy = 0; } break;
                }
            });
    
            // Start gry
            gameLoop = setInterval(gameStep, gameSpeed);
        </script>
    </body>
    </html>
    

    Ta implementacja zawiera:

    1. Nowoczesny interfejs z neonowym stylem
    2. System punktacji
    3. Rosnącą prędkość wraz z punktami
    4. Kolizje ze ścianami i własnym ciałem
    5. Losowo generowaną jedzenie
    6. Animowane przejścia kolorów dla węża
    7. Podświetlane jedzenie
    8. Mechanizm zakończenia gry

    Aby uruchomić:

    1. Zapisz jako plik .html
    2. Otwórz w przeglądarce
    3. Steruj strzałkami

    Wąż rośnie po zjadaniu różowego jedzenia, a prędkość stopniowo się zwiększa. Gra kończy się przy kolizji ze ścianą lub własnym ciałem.

  3. User

    napisz mi kod gry w węża w html

  4. Assistant

    Oto kompletny kod gry w węża w HTML:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Gra w Węża</title>
        <style>
            body {
                display: flex;
                flex-direction: column;
                align-items: center;
                background-color: #f0f0f0;
                font-family: Arial, sans-serif;
            }
            canvas {
                border: 3px solid #333;
                background-color: #fff;
            }
            #score {
                font-size: 24px;
                margin: 10px;
            }
        </style>
    </head>
    <body>
        <h1>Gra w Węża</h1>
        <div id="score">Wynik: 0</div>
        <canvas id="gameCanvas" width="400" height="400"></canvas>
        <p>Użyj strzałek do sterowania wężem</p>
    
        <script>
            // Pobranie elementów
            const canvas = document.getElementById('gameCanvas');
            const ctx = canvas.getContext('2d');
            const scoreElement = document.getElementById('score');
            
            // Stałe gry
            const gridSize = 20;
            const tileCount = canvas.width / gridSize;
            
            // Zmienne gry
            let snake = [
                { x: 10, y: 10 }
            ];
            let food = generateFood();
            let dx = 1;
            let dy = 0;
            let score = 0;
            let gameSpeed = 100;
            let gameInterval;
            let isGameOver = false;
    
            // Rozpoczęcie gry
            startGame();
    
            function startGame() {
                // Kierunek początkowy - w prawo
                dx = 1;
                dy = 0;
                
                // Uruchomienie pętli gry
                gameInterval = setInterval(gameLoop, gameSpeed);
                
                // Dodanie nasłuchiwania klawiatury
                document.addEventListener('keydown', changeDirection);
            }
    
            function gameLoop() {
                if (isGameOver) return;
                
                moveSnake();
                checkCollision();
                checkFood();
                
                // Czyszczenie canvasa
                ctx.fillStyle = 'white';
                ctx.fillRect(0, 0, canvas.width, canvas.height);
                
                // Rysowanie węża
                drawSnake();
                
                // Rysowanie jedzenia
                drawFood();
            }
    
            function moveSnake() {
                // Utworzenie nowej głowy
                const head = { x: snake[0].x + dx, y: snake[0].y + dy };
                snake.unshift(head);
                
                // Usunięcie ogona, chyba że zjadł jedzenie
                if (!checkFoodEaten()) {
                    snake.pop();
                }
            }
    
            function checkFoodEaten() {
                if (snake[0].x === food.x && snake[0].y === food.y) {
                    // Zwiększenie wyniku
                    score += 10;
                    scoreElement.textContent = `Wynik: ${score}`;
                    
                    // Generowanie nowego jedzenia
                    food = generateFood();
                    
                    return true;
                }
                return false;
            }
    
            function checkCollision() {
                const head = snake[0];
                
                // Kolizja ze ścianą
                if (head.x < 0 || head.x >= tileCount || head.y < 0 || head.y >= tileCount) {
                    gameOver();
                }
                
                // Kolizja z samym sobą
                for (let i = 1; i < snake.length; i++) {
                    if (head.x === snake[i].x && head.y === snake[i].y) {
                        gameOver();
                    }
                }
            }
    
            function gameOver() {
                isGameOver = true;
                clearInterval(gameInterval);
                
                // Wyświetlenie komunikatu game over
                ctx.fillStyle = 'black';
                ctx.font = '30px Arial';
                ctx.textAlign = 'center';
                ctx.fillText('Koniec Gry!', canvas.width / 2, canvas.height / 2);
                ctx.font = '20px Arial';
                ctx.fillText(`Wynik końcowy: ${score}`, canvas.width / 2, canvas.height / 2 + 30);
                ctx.fillText('Odśwież stronę, aby zagrać ponownie', canvas.width / 2, canvas.height / 2 + 60);
            }
    
            function changeDirection(event) {
                const LEFT_KEY = 37;
                const RIGHT_KEY = 39;
                const UP_KEY = 38;
                const DOWN_KEY = 40;
                
                if (isGameOver) return;
                
                const keyPressed = event.keyCode;
                const goingUp = dy === -1;
                const goingDown = dy === 1;
                const goingRight = dx === 1;
                const goingLeft = dx === -1;
                
                if (keyPressed === LEFT_KEY && !goingRight) {
                    dx = -1;
                    dy = 0;
                }
                if (keyPressed === UP_KEY && !goingDown) {
                    dx = 0;
                    dy = -1;
                }
                if (keyPressed === RIGHT_KEY && !goingLeft) {
                    dx = 1;
                    dy = 0;
                }
                if (keyPressed === DOWN_KEY && !goingUp) {
                    dx = 0;
                    dy = 1;
                }
            }
    
            function drawSnake() {
                snake.forEach((segment, index) => {
                    // Inny kolor dla głowy
                    if (index === 0) {
                        ctx.fillStyle = 'darkgreen';
                    } else {
                        ctx.fillStyle = 'green';
                    }
                    
                    ctx.fillRect(
                        segment.x * gridSize, 
                        segment.y * gridSize, 
                        gridSize - 1, 
                        gridSize - 1
                    );
                });
            }
    
            function drawFood() {
                ctx.fillStyle = 'red';
                ctx.fillRect(
                    food.x * gridSize, 
                    food.y * gridSize, 
                    gridSize - 1, 
                    gridSize - 1
                );
            }
    
            function generateFood() {
                // Generowanie losowej pozycji dla jedzenia
                let newFood;
                let foodOnSnake;
                
                do {
                    foodOnSnake = false;
                    newFood = {
                        x: Math.floor(Math.random() * tileCount),
                        y: Math.floor(Math.random() * tileCount)
                    };
                    
                    // Sprawdzenie czy jedzenie jest na wężu
                    for (let segment of snake) {
                        if (segment.x === newFood.x && segment.y === newFood.y) {
                            foodOnSnake = true;
                            break;
                        }
                    }
                } while (foodOnSnake);
                
                return newFood;
            }
        </script>
    </body>
    </html>
    

    Aby uruchomić grę:

    1. Skopiuj powyższy kod do pliku z rozszerzeniem .html
    2. Otwórz plik w przeglądarce internetowej
    3. Steruj wężem za pomocą strzałek na klawiaturze

    Gra polega na zjadaniu czerwonych kropek (jedzenia), co powoduje wydłużanie się węża i zwiększanie wyniku. Gra kończy się, gdy wąż uderzy w ścianę lub w siebie.

  5. User

    pokaż mi zdjęcie vw amarok canyon

  6. Assistant

    Oto zdjęcie Volkswagena Amarok Canyon:

    [image: VW Amarok Canyon] open

    Źródło: Volkswagen Newsroom

    Amarok Canyon to specjalna edycja popularnego pickupa Volkswagena, charakteryzująca się:

    • Wyróżniającym się designem terenowym
    • Wysoką przeprawowością
    • Luksusowym wyposażeniem
    • Napędem na 4 koła
    • Silnikami diesla o zwiększonej mocy

    Jeśli szukasz innego rocznika lub konkretnej wersji, daj znać.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.