Advertisement
jaldpsd
Jun 21st, 2024
49
0
Never
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!
  1. Code created by Claude Sonnet 3.5:
  2.  
  3. <!DOCTYPE html>
  4. <html lang="en">
  5. <head>
  6. <meta charset="UTF-8">
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>Two-Player Line Game</title>
  9. <style>
  10. body {
  11. display: flex;
  12. justify-content: center;
  13. align-items: center;
  14. height: 100vh;
  15. margin: 0;
  16. font-family: Arial, sans-serif;
  17. }
  18. #gameContainer {
  19. width: 600px;
  20. height: 300px;
  21. position: relative;
  22. overflow: hidden;
  23. }
  24. #player1, #player2 {
  25. position: absolute;
  26. top: 0;
  27. height: 100%;
  28. display: flex;
  29. align-items: center;
  30. justify-content: center;
  31. font-size: 48px;
  32. color: white;
  33. }
  34. #player1 {
  35. left: 0;
  36. background-color: red;
  37. }
  38. #player2 {
  39. right: 0;
  40. background-color: blue;
  41. }
  42. #divider {
  43. position: absolute;
  44. top: 0;
  45. width: 4px;
  46. height: 100%;
  47. background-color: black;
  48. }
  49. #instructions {
  50. position: absolute;
  51. bottom: 10px;
  52. text-align: center;
  53. width: 100%;
  54. }
  55. </style>
  56. </head>
  57. <body>
  58. <div id="gameContainer">
  59. <div id="player1"></div>
  60. <div id="player2"></div>
  61. <div id="divider"></div>
  62. <div id="instructions">Player 1: Press 'A' | Player 2: Press 'L'</div>
  63. </div>
  64.  
  65. <script>
  66. const gameContainer = document.getElementById('gameContainer');
  67. const player1 = document.getElementById('player1');
  68. const player2 = document.getElementById('player2');
  69. const divider = document.getElementById('divider');
  70.  
  71. let gameWidth = gameContainer.offsetWidth;
  72. let dividerPosition = gameWidth / 2;
  73. let isMoving = false;
  74. let moveDirection = 0;
  75. let moveSpeed = 1;
  76.  
  77. function updateGame() {
  78. player1.style.width = `${dividerPosition}px`;
  79. player2.style.width = `${gameWidth - dividerPosition}px`;
  80. divider.style.left = `${dividerPosition}px`;
  81.  
  82. player1.textContent = dividerPosition > 0 ? 'A' : '';
  83. player2.textContent = dividerPosition < gameWidth ? 'L' : '';
  84.  
  85. if (dividerPosition <= 0 || dividerPosition >= gameWidth) {
  86. endGame();
  87. }
  88. }
  89.  
  90. function startMoving() {
  91. if (!isMoving) {
  92. isMoving = true;
  93. moveDirection = Math.random() > 0.5 ? 1 : -1;
  94. moveDivider();
  95. }
  96. }
  97.  
  98. function moveDivider() {
  99. if (isMoving) {
  100. dividerPosition += moveDirection * moveSpeed;
  101. updateGame();
  102. requestAnimationFrame(moveDivider);
  103. }
  104. }
  105.  
  106. function stopMoving() {
  107. if (isMoving) {
  108. isMoving = false;
  109. setTimeout(startMoving, 1000);
  110. }
  111. }
  112.  
  113. function endGame() {
  114. isMoving = false;
  115. alert(dividerPosition <= 0 ? "Player 2 (L) wins!" : "Player 1 (A) wins!");
  116. }
  117.  
  118. document.addEventListener('keydown', (event) => {
  119. if (event.key.toLowerCase() === 'a' && moveDirection > 0) {
  120. stopMoving();
  121. } else if (event.key.toLowerCase() === 'l' && moveDirection < 0) {
  122. stopMoving();
  123. }
  124. });
  125.  
  126. updateGame();
  127. setTimeout(startMoving, 1000);
  128. </script>
  129. </body>
  130. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement