Skip to content

Commit

Permalink
Merge pull request #1118 from Aditi22Bansal/main
Browse files Browse the repository at this point in the history
Shadow clone game
  • Loading branch information
Durgesh4993 authored Aug 9, 2024
2 parents 5b7472b + 0a53c8c commit 3dd11e8
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
17 changes: 17 additions & 0 deletions SinglePlayer - Games/Shadow clone/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shadow Clone</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="game-container">
<div id="player"></div>
</div>
<button id="clone-button">Create Clone</button>
<button id="reset-button">Reset</button>
<script src="script.js"></script>
</body>
</html>
63 changes: 63 additions & 0 deletions SinglePlayer - Games/Shadow clone/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
document.addEventListener('DOMContentLoaded', () => {
const player = document.getElementById('player');
const gameContainer = document.getElementById('game-container');
const cloneButton = document.getElementById('clone-button');
const resetButton = document.getElementById('reset-button');
let clones = [];

let playerPosition = { x: 10, y: 10 };
let moveDistance = 10;

function updatePlayerPosition() {
player.style.left = playerPosition.x + 'px';
player.style.top = playerPosition.y + 'px';
}

function createClone() {
const clone = document.createElement('div');
clone.classList.add('clone');
clone.style.left = playerPosition.x + 'px';
clone.style.top = playerPosition.y + 'px';
gameContainer.appendChild(clone);
clones.push(clone);
}

function resetGame() {
playerPosition = { x: 10, y: 10 };
updatePlayerPosition();
clones.forEach(clone => gameContainer.removeChild(clone));
clones = [];
}

function movePlayer(e) {
switch (e.key) {
case 'ArrowUp':
if (playerPosition.y - moveDistance >= 0) {
playerPosition.y -= moveDistance;
}
break;
case 'ArrowDown':
if (playerPosition.y + moveDistance <= gameContainer.clientHeight - player.clientHeight) {
playerPosition.y += moveDistance;
}
break;
case 'ArrowLeft':
if (playerPosition.x - moveDistance >= 0) {
playerPosition.x -= moveDistance;
}
break;
case 'ArrowRight':
if (playerPosition.x + moveDistance <= gameContainer.clientWidth - player.clientWidth) {
playerPosition.x += moveDistance;
}
break;
}
updatePlayerPosition();
}

document.addEventListener('keydown', movePlayer);
cloneButton.addEventListener('click', createClone);
resetButton.addEventListener('click', resetGame);

updatePlayerPosition();
});
45 changes: 45 additions & 0 deletions SinglePlayer - Games/Shadow clone/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
body {
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
background-color: #282c34;
color: white;
font-family: Arial, sans-serif;
}

#game-container {
position: relative;
width: 500px;
height: 500px;
background-color: #444;
border: 2px solid #fff;
margin-top: 20px;
}

#player, .clone {
position: absolute;
width: 20px;
height: 20px;
background-color: #61dafb;
}

#clone-button, #reset-button {
margin: 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}

#clone-button {
background-color: #61dafb;
border: none;
color: #282c34;
}

#reset-button {
background-color: #ff6f61;
border: none;
color: #fff;
}

0 comments on commit 3dd11e8

Please sign in to comment.