Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Squid Game 2</title>
- <style>
- body {
- font-family: Arial, sans-serif;
- }
- #squid {
- position: fixed;
- top: 10px;
- left: 50%;
- transform: translateX(-50%);
- width: 100px;
- height: 100px;
- background-color: red;
- border-radius: 50%;
- }
- #squid.active {
- background-color: blue;
- }
- .user {
- position: absolute;
- bottom: 20px;
- width: 50px;
- height: 50px;
- background-color: blue;
- text-align: center;
- line-height: 50px;
- color: white;
- font-weight: bold;
- }
- .x {
- background-color: gray !important;
- }
- .status {
- position: absolute;
- width: 200px;
- text-align: center;
- color: red;
- font-weight: bold;
- }
- #controls {
- position: fixed;
- bottom: 20px;
- left: 50%;
- transform: translateX(-50%);
- display: flex;
- gap: 10px;
- }
- button {
- padding: 10px 20px;
- font-size: 16px;
- }
- #message {
- display: none;
- text-align: center;
- margin-top: 20px;
- font-size: 18px;
- font-weight: bold;
- }
- </style>
- </head>
- <body>
- <div id="squid"></div>
- <div class="user" id="user1">P1</div>
- <div class="status" id="status1" style="left: 10%; bottom: 80px;">Player 1 - Normal</div>
- <div class="user" id="user2">P2</div>
- <div class="status" id="status2" style="left: 70%; bottom: 80px;">Player 2 - Normal</div>
- <div id="message"></div>
- <div id="controls">
- <button id="walk">Walk</button>
- <button id="stop" disabled>Stop</button>
- <button id="reset" style="display: none;">Reset</button>
- </div>
- <script>
- document.addEventListener("DOMContentLoaded", () => {
- const users = Array.from(document.querySelectorAll(".user"));
- const statuses = Array.from(document.querySelectorAll(".status"));
- const squid = document.getElementById("squid");
- const walkBtn = document.getElementById("walk");
- const stopBtn = document.getElementById("stop");
- const resetBtn = document.getElementById("reset");
- const gameMessage = document.getElementById("message");
- let squidActive = false;
- let moveInterval = null;
- let walking = false;
- let gameEnded = false;
- const MIN_SPEED = 0.8;
- const userSpeeds = {};
- const penaltyTurns = {};
- // Start Walking
- function walkPlayers() {
- if (gameEnded || squidActive || walking) return;
- walking = true;
- walkBtn.disabled = true;
- stopBtn.disabled = false;
- moveInterval = setInterval(() => {
- users.forEach((user, index) => {
- const userId = user.id;
- const currentBottom = parseInt(user.style.bottom || "20px", 10);
- if (penaltyTurns[userId] || user.classList.contains("x")) return;
- // Move player forward
- const newPosition = currentBottom + userSpeeds[userId];
- user.style.bottom = `${newPosition}px`;
- // Check if player reached the finish line
- if (newPosition >= window.innerHeight - 100) {
- clearInterval(moveInterval);
- declareWinner(user.id);
- }
- });
- }, 50);
- }
- // Stop Players
- function stopPlayers() {
- if (!walking) return;
- walking = false;
- walkBtn.disabled = false;
- stopBtn.disabled = true;
- clearInterval(moveInterval);
- // Mark players as not moving
- users.forEach((user) => {
- user.dataset.moving = "false";
- });
- }
- // Toggle Squid State
- function toggleSquid() {
- if (gameEnded) return;
- squidActive = !squidActive;
- squid.classList.toggle("active", squidActive);
- if (squidActive) {
- // Check moving players
- users.forEach((user, index) => {
- const isMoving = user.dataset.moving === "true";
- const userId = user.id;
- const status = statuses[index];
- if (isMoving && !penaltyTurns[userId]) {
- user.classList.add("x");
- penaltyTurns[userId] = 2;
- userSpeeds[userId] = Math.max(userSpeeds[userId] / 2, MIN_SPEED);
- status.textContent = `Player ${index + 1} - Penalty - Slow Movement`;
- }
- });
- } else {
- // Reduce penalties
- users.forEach((user, index) => {
- const userId = user.id;
- const status = statuses[index];
- if (penaltyTurns[userId]) {
- penaltyTurns[userId]--;
- if (penaltyTurns[userId] === 0) {
- user.classList.remove("x");
- delete penaltyTurns[userId];
- status.textContent = `Player ${index + 1} - Normal`;
- }
- }
- });
- }
- }
- // Declare Winner
- function declareWinner(userId) {
- gameEnded = true;
- gameMessage.textContent = `🎉 Player ${userId.toUpperCase()} Wins!`;
- gameMessage.style.display = "block";
- walkBtn.disabled = true;
- stopBtn.disabled = true;
- resetBtn.style.display = "block";
- }
- // Reset Game
- function resetGame() {
- gameEnded = false;
- gameMessage.style.display = "none";
- resetBtn.style.display = "none";
- users.forEach((user, index) => {
- user.classList.remove("x");
- user.style.bottom = "20px";
- user.dataset.moving = "false";
- userSpeeds[user.id] = Math.random() * 3 + 1;
- statuses[index].textContent = `Player ${index + 1} - Normal`;
- });
- // Re-enable walk button
- walkBtn.disabled = false;
- stopBtn.disabled = true;
- startGame();
- }
- // Initialize Game
- function startGame() {
- users.forEach((user) => {
- userSpeeds[user.id] = Math.random() * 3 + 1;
- user.style.left = `${Math.random() * 80 + 10}%`;
- });
- setInterval(toggleSquid, Math.random() * 5000 + 2000);
- }
- // Event Listeners
- walkBtn.addEventListener("click", () => {
- if (squidActive) {
- // Trigger penalty if squid is active
- users.forEach((user, index) => {
- user.classList.add("x");
- const status = statuses[index];
- penaltyTurns[user.id] = 2;
- userSpeeds[user.id] = Math.max(userSpeeds[user.id] / 2, MIN_SPEED);
- status.textContent = `Player ${index + 1} - Penalty - Slow Movement`;
- });
- } else {
- walkPlayers();
- // Mark players as moving
- users.forEach((user) => {
- user.dataset.moving = "true";
- });
- }
- });
- stopBtn.addEventListener("click", stopPlayers);
- resetBtn.addEventListener("click", resetGame);
- // Start Game
- startGame();
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement