Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a new game dodge teh blocks #4752

Merged
merged 6 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Games/Dodge the Blocks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Dodge the Blocks Game

"Dodge the Blocks" is a simple and fun web-based game where the player controls a character that must avoid falling blocks. The goal is to survive as long as possible without being hit by the blocks.

## Table of Contents

- [Demo](#demo)
- [Installation](#installation)
- [How to Play](#how-to-play)
- [Technologies Used](#technologies-used)
- [Contributing](#contributing)
- [License](#license)

## Demo

You can see a live demo of the game [here](#). (Add your live demo link here)

## Installation

To run this game locally, follow these steps:


## How to Play

1. Open the game in your web browser.
2. Use the left and right arrow keys to move the player left and right.
3. Avoid the falling blocks.
4. Try to survive as long as possible. Your score increases with time.
5. If a block hits the player, the game is over, and your final score will be displayed.

## Technologies Used

- HTML
- CSS
- JavaScript

## Contributing

Contributions are welcome! If you have any suggestions or improvements, feel free to submit a pull request or open an issue.

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
16 changes: 16 additions & 0 deletions Games/Dodge the Blocks/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dodge the Blocks</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="gameContainer">
<div id="player"></div>
</div>
<div id="score">Score: 0</div>
<script src="script.js"></script>
</body>
</html>
57 changes: 57 additions & 0 deletions Games/Dodge the Blocks/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const gameContainer = document.getElementById('gameContainer');
const player = document.getElementById('player');
const scoreDisplay = document.getElementById('score');

let score = 0;
let gameOver = false;

// Player movement
document.addEventListener('keydown', (e) => {
const left = parseInt(window.getComputedStyle(player).getPropertyValue('left'));
if (e.key === 'ArrowLeft' && left > 0) {
player.style.left = left - 10 + 'px';
} else if (e.key === 'ArrowRight' && left < 270) {
player.style.left = left + 10 + 'px';
}
});

// Generate blocks
function createBlock() {
const block = document.createElement('div');
block.classList.add('block');
block.style.left = Math.floor(Math.random() * 270) + 'px';
gameContainer.appendChild(block);

// Collision detection
const blockInterval = setInterval(() => {
const blockTop = parseInt(window.getComputedStyle(block).getPropertyValue('top'));
const playerLeft = parseInt(window.getComputedStyle(player).getPropertyValue('left'));
const playerRight = playerLeft + 30;
const blockLeft = parseInt(block.style.left);
const blockRight = blockLeft + 30;

if (blockTop > 470 && blockTop < 500 && playerLeft < blockRight && playerRight > blockLeft) {
gameOver = true;
alert('Game Over! Final Score: ' + score);
clearInterval(blockInterval);
location.reload();
}
}, 10);

// Remove block after it falls
setTimeout(() => {
block.remove();
}, 3000);
}

// Update score
function updateScore() {
if (!gameOver) {
score++;
scoreDisplay.textContent = 'Score: ' + score;
setTimeout(updateScore, 1000);
}
}

updateScore();
setInterval(createBlock, 1500);
49 changes: 49 additions & 0 deletions Games/Dodge the Blocks/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}

#gameContainer {
position: relative;
width: 300px;
height: 500px;
background-color: #fff;
border: 2px solid #000;
overflow: hidden;
}

#player {
position: absolute;
width: 30px;
height: 30px;
background-color: #3498db;
bottom: 10px;
left: 135px;
}

.block {
position: absolute;
width: 30px;
height: 30px;
background-color: #e74c3c;
animation: fall 3s linear infinite;
}

@keyframes fall {
0% {
top: -30px;
}
100% {
top: 500px;
}
}

#score {
margin-top: 20px;
font-size: 24px;
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,14 @@ This repository also provides one such platforms where contributers come over an
| [Modulo_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Modulo_Game) |
| [Alien_Invasion](https://github.com/kunjgit/GameZone/tree/main/Games/Alien_Invasion) |
| [Drawing_App](https://github.com/kunjgit/GameZone/tree/main/Games/Drawing_app) |

| [Dodge_the_Blocks](https://github.com/kunjgit/GameZone/tree/main/Games/Dodge_the_Blocks) |


|[Town-Rise](https://github.com/kunjgit/GameZone/tree/main/Games/Town_Rise_Game)|
| [IKnowYou-Mind-Reading-Game](https://github.com/kunjgit/GameZone/tree/main/Games/IKnowYou-Mind-Reading-Game) |
|[Color Swap](https://github.com/kunjgit/GameZone/tree/main/Games/Color_Swap)|

| [Catch_the_falling_Stars](https://github.com/kunjgit/GameZone/tree/main/Games/Catch_the_falling_Stars) |
|[Town-Rise](https://github.com/kunjgit/GameZone/tree/main/Games/Town_Rise_Game)|
| [IKnowYou-Mind-Reading-Game](https://github.com/kunjgit/GameZone/tree/main/Games/IKnowYou-Mind-Reading-Game) |
Expand Down
Binary file added assets/images/Screenshot 2024-07-06 200816.png
1911aditi marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.