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

Added new game Eco Warrior #4995

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
50 changes: 50 additions & 0 deletions Games/Eco_Warrior/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Eco Warrior

## Overview

Eco Warrior is an educational and engaging game designed to raise awareness about environmental conservation. Players take on the role of an eco-warrior whose mission is to clean up litter, plant trees, and restore ecosystems. The game is designed to be both fun and educational, teaching players the importance of keeping the environment clean and green.

## How to Play

- **Objective**: Clean up all the litter within the given time to advance to the next level. Additionally, plant trees to increase your impact score and improve the environment.
- **Energy**: Start with 100 energy points. Cleaning litter and planting trees consume energy. Energy regenerates over time.
- **Score**: Earn points by cleaning litter and planting trees. Higher scores unlock upgrades and allow you to progress to higher levels.
- **Timer**: Each level has a countdown timer. Clean up all the litter before the time runs out to complete the level. The time available increases with each subsequent level.

## Game Elements

- **Litter**: Click on litter items scattered around the game area to clean them up. Each piece of litter cleaned increases your score.
- **Trees**: Plant trees to improve your score and the environment. Planting a tree costs 10 energy points.
- **Upgrades**: Accumulate 50 points to purchase an upgrade that increases your energy regeneration rate.

## Levels

The game consists of multiple levels, each progressively more challenging:
- **Level 1**: Start with 10 pieces of litter and 60 seconds to clean them up.
- **Subsequent Levels**: Each new level adds 5 more pieces of litter and increases the timer by 10 seconds. The challenge increases as you progress, requiring more strategic use of energy and time.

## Game Over

If you fail to clean up all the litter within the given time, the game will display a "Game Over" message and reset. Try again to beat your previous scores and advance further.

## Screenshots

![Treasure Hunt](../../assets/images/Eco_Warrior.png)

## Try It Out

You can try out the game by opening the `index.html` file in your web browser.

## Educational Impact

Eco Warrior aims to educate players about the importance of environmental conservation. By simulating the cleanup process and tree planting, players learn the value of these actions in a fun and interactive way. The game encourages players to think about real-world environmental issues and how they can contribute to a cleaner, greener planet.

## Gameplay Tips

- **Manage Energy**: Keep an eye on your energy levels. Avoid running out of energy by allowing time for regeneration.
- **Strategize**: Plan your moves to efficiently clean up litter and plant trees without wasting energy.
- **Upgrade Wisely**: Use your score to purchase upgrades that will help you in higher levels by increasing your energy regeneration rate.

## Credits

Eco Warrior was created to raise awareness about environmental conservation. Thank you for playing and contributing to a cleaner, greener planet.
Binary file added Games/Eco_Warrior/assets/litter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Games/Eco_Warrior/assets/tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 118 additions & 0 deletions Games/Eco_Warrior/game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
let energy = 100;
let score = 0;
let level = 1;
let litterCount = 10;
let energyRegenRate = 1;
let timer;
let timeLeft = 60;

const energyElement = document.getElementById('energy');
const scoreElement = document.getElementById('score');
const levelElement = document.getElementById('level');
const timerElement = document.getElementById('timer');
const plantTreeButton = document.getElementById('plant-tree');
const upgradeButton = document.getElementById('upgrade');
const litterContainer = document.getElementById('litter');
const treesContainer = document.getElementById('trees');

function updateStats() {
energyElement.textContent = energy;
scoreElement.textContent = score;
levelElement.textContent = level;
timerElement.textContent = timeLeft;
plantTreeButton.disabled = energy < 10;
upgradeButton.disabled = score < 50;
}

function createLitter() {
for (let i = 0; i < litterCount; i++) {
const litter = document.createElement('div');
litter.classList.add('litter');
litter.style.top = `${Math.random() * 350}px`;
litter.style.left = `${Math.random() * 750}px`;

litter.addEventListener('click', () => {
litter.remove();
score += 10;
updateStats();
checkLevelCompletion();
});

litterContainer.appendChild(litter);
}
}

function checkLevelCompletion() {
if (litterContainer.children.length === 0) {
clearInterval(timer);
alert('Level Completed! Starting next level.');
level++;
litterCount += 5;
timeLeft = 60 + (level - 1) * 10;
createLitter();
startTimer();
updateStats();
}
}

function plantTree() {
if (energy < 10) return;

const tree = document.createElement('div');
tree.classList.add('tree');
tree.style.top = `${Math.random() * 350}px`;
tree.style.left = `${Math.random() * 750}px`;

treesContainer.appendChild(tree);
energy -= 10;
score += 20;
updateStats();
}

function upgrade() {
if (score < 50) return;
score -= 50;
energyRegenRate += 0.5;
updateStats();
}

function startTimer() {
timer = setInterval(() => {
if (timeLeft > 0) {
timeLeft--;
updateStats();
} else {
clearInterval(timer);
alert('Game Over! You ran out of time.');
resetGame();
}
}, 1000);
}

function resetGame() {
energy = 100;
score = 0;
level = 1;
litterCount = 10;
energyRegenRate = 1;
timeLeft = 60;
litterContainer.innerHTML = '';
treesContainer.innerHTML = '';
createLitter();
startTimer();
updateStats();
}

plantTreeButton.addEventListener('click', plantTree);
upgradeButton.addEventListener('click', upgrade);

setInterval(() => {
if (energy < 100) {
energy = Math.min(100, energy + energyRegenRate);
updateStats();
}
}, 1000);

createLitter();
startTimer();
updateStats();
34 changes: 34 additions & 0 deletions Games/Eco_Warrior/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Eco Warrior</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="game-container">
<header>
<h1>Eco Warrior</h1>
<div id="stats">
<p>Energy: <span id="energy">100</span></p>
<p>Score: <span id="score">0</span></p>
<p>Level: <span id="level">1</span></p>
<p>Time Left: <span id="timer">60</span>s</p>
</div>
</header>
<div id="game-area">
<div id="instructions">
<p>Clean up the litter by clicking on it. Plant trees to increase your impact score. Energy regenerates over time.</p>
</div>
<div id="litter"></div>
<div id="trees"></div>
</div>
<footer>
<button id="plant-tree">Plant Tree (-10 Energy)</button>
<button id="upgrade" disabled>Upgrade: Energy Booster (-50 Score)</button>
</footer>
</div>
<script src="game.js"></script>
</body>
</html>
93 changes: 93 additions & 0 deletions Games/Eco_Warrior/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #e0f7fa;
}

#game-container {
width: 800px;
max-width: 100%;
border: 2px solid #00897b;
border-radius: 10px;
background-color: #ffffff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
overflow: hidden;
}

header {
background-color: #004d40;
color: white;
padding: 20px;
text-align: center;
}

#stats {
display: flex;
justify-content: space-around;
background-color: #00796b;
padding: 10px;
border-radius: 10px;
margin-top: 10px;
}

#game-area {
position: relative;
padding: 20px;
height: 400px;
background-color: #c8e6c9;
border-radius: 10px;
}

#instructions {
margin-bottom: 20px;
background-color: #80cbc4;
padding: 10px;
border-radius: 5px;
text-align: center;
color: white;
font-weight: bold;
}

footer {
background-color: #004d40;
color: white;
text-align: center;
padding: 10px;
}

button {
background-color: #00796b;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 5px;
}

button:disabled {
background-color: #004d40;
cursor: not-allowed;
}

.litter, .tree {
position: absolute;
width: 40px;
height: 40px;
cursor: pointer;
background-size: cover;
background-repeat: no-repeat;
}

.litter {
background-image: url('assets/litter.png');
}

.tree {
background-image: url('assets/tree.png');
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ This repository also provides one such platforms where contributers come over an
|[Snake_Gun_Water](https://github.com/kunjgit/GameZone/tree/main/Games/Snake_Gun_Water)|
|[Tether](https://github.com/kunjgit/GameZone/tree/main/Games/Tether)|
|[Rock Paper Scissors Lizard Spock Game](./Games/Rock_Paper_Scissors_Lizard_Spock_Game)|

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

</center>
Expand Down
Binary file added assets/images/Eco_Warrior.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading