Advertisement
This is comment for paste
GPT-4 vs Llama-3 vs Claude
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Code created by Claude Sonnet 3.5:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Two-Player Line Game</title>
- <style>
- body {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100vh;
- margin: 0;
- font-family: Arial, sans-serif;
- }
- #gameContainer {
- width: 600px;
- height: 300px;
- position: relative;
- overflow: hidden;
- }
- #player1, #player2 {
- position: absolute;
- top: 0;
- height: 100%;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 48px;
- color: white;
- }
- #player1 {
- left: 0;
- background-color: red;
- }
- #player2 {
- right: 0;
- background-color: blue;
- }
- #divider {
- position: absolute;
- top: 0;
- width: 4px;
- height: 100%;
- background-color: black;
- }
- #instructions {
- position: absolute;
- bottom: 10px;
- text-align: center;
- width: 100%;
- }
- </style>
- </head>
- <body>
- <div id="gameContainer">
- <div id="player1"></div>
- <div id="player2"></div>
- <div id="divider"></div>
- <div id="instructions">Player 1: Press 'A' | Player 2: Press 'L'</div>
- </div>
- <script>
- const gameContainer = document.getElementById('gameContainer');
- const player1 = document.getElementById('player1');
- const player2 = document.getElementById('player2');
- const divider = document.getElementById('divider');
- let gameWidth = gameContainer.offsetWidth;
- let dividerPosition = gameWidth / 2;
- let isMoving = false;
- let moveDirection = 0;
- let moveSpeed = 1;
- function updateGame() {
- player1.style.width = `${dividerPosition}px`;
- player2.style.width = `${gameWidth - dividerPosition}px`;
- divider.style.left = `${dividerPosition}px`;
- player1.textContent = dividerPosition > 0 ? 'A' : '';
- player2.textContent = dividerPosition < gameWidth ? 'L' : '';
- if (dividerPosition <= 0 || dividerPosition >= gameWidth) {
- endGame();
- }
- }
- function startMoving() {
- if (!isMoving) {
- isMoving = true;
- moveDirection = Math.random() > 0.5 ? 1 : -1;
- moveDivider();
- }
- }
- function moveDivider() {
- if (isMoving) {
- dividerPosition += moveDirection * moveSpeed;
- updateGame();
- requestAnimationFrame(moveDivider);
- }
- }
- function stopMoving() {
- if (isMoving) {
- isMoving = false;
- setTimeout(startMoving, 1000);
- }
- }
- function endGame() {
- isMoving = false;
- alert(dividerPosition <= 0 ? "Player 2 (L) wins!" : "Player 1 (A) wins!");
- }
- document.addEventListener('keydown', (event) => {
- if (event.key.toLowerCase() === 'a' && moveDirection > 0) {
- stopMoving();
- } else if (event.key.toLowerCase() === 'l' && moveDirection < 0) {
- stopMoving();
- }
- });
- updateGame();
- setTimeout(startMoving, 1000);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement