-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1371 from PrAyAg9/main
#1370 Solved - Awesome Game Added - Nature Simulation
- Loading branch information
Showing
3 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Nature Simulation Game</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div id="game"> | ||
<h1>Nature Simulation Game</h1> | ||
<div id="ecosystem"></div> | ||
<button id="addPlant">Add Plant</button> | ||
<button id="addAnimal">Add Animal</button> | ||
<div id="stats"></div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
let ecosystem = []; | ||
let water = 100; | ||
let food = 100; | ||
let turns = 0; | ||
const maxTurns = 20; | ||
|
||
const ecosystemDiv = document.getElementById('ecosystem'); | ||
const statsDiv = document.getElementById('stats'); | ||
|
||
document.getElementById('addPlant').addEventListener('click', () => { | ||
if (water >= 10) { | ||
const plant = { type: 'plant', growth: Math.random() * 10 }; | ||
ecosystem.push(plant); | ||
water -= 10; | ||
updateEcosystem(); | ||
} else { | ||
alert("Not enough water!"); | ||
} | ||
}); | ||
|
||
document.getElementById('addAnimal').addEventListener('click', () => { | ||
if (food >= 10) { | ||
const animal = { type: 'animal', hunger: Math.random() * 10 }; | ||
ecosystem.push(animal); | ||
food -= 10; | ||
updateEcosystem(); | ||
} else { | ||
alert("Not enough food!"); | ||
} | ||
}); | ||
|
||
function updateEcosystem() { | ||
ecosystemDiv.innerHTML = ''; | ||
ecosystem.forEach(species => { | ||
const div = document.createElement('div'); | ||
div.className = 'species ' + species.type; | ||
div.innerText = species.type === 'plant' ? '🌱' : '🐾'; | ||
ecosystemDiv.appendChild(div); | ||
}); | ||
updateStats(); | ||
} | ||
|
||
function updateStats() { | ||
statsDiv.innerHTML = `Water: ${water} | Food: ${food} | Species Count: ${ecosystem.length} | Turns: ${turns}`; | ||
checkWinLose(); | ||
} | ||
|
||
function checkWinLose() { | ||
if (water <= 0 || food <= 0) { | ||
alert("You have lost! The ecosystem has collapsed."); | ||
resetGame(); | ||
} else if (turns >= maxTurns) { | ||
alert("Congratulations! You have maintained the ecosystem successfully."); | ||
resetGame(); | ||
} | ||
} | ||
|
||
function resetGame() { | ||
ecosystem = []; | ||
water = 100; | ||
food = 100; | ||
turns = 0; | ||
updateEcosystem(); | ||
} | ||
|
||
function randomEvent() { | ||
const event = Math.random(); | ||
if (event < 0.3) { | ||
water -= 20; // Drought | ||
alert("A drought has occurred! Water reduced by 20."); | ||
} else if (event < 0.6) { | ||
water += 20; // Abundant rain | ||
alert("Abundant rain! Water increased by 20."); | ||
} else if (event < 0.9) { | ||
food += 10; // Food bounty | ||
alert("A food bounty has occurred! Food increased by 10."); | ||
} else { | ||
// No event | ||
alert("No significant events this turn."); | ||
} | ||
} | ||
|
||
// Simulate resource consumption and turns | ||
setInterval(() => { | ||
if (turns < maxTurns) { | ||
if (water > 0) water -= 1; | ||
if (food > 0) food -= 1; | ||
turns += 1; | ||
randomEvent(); // Trigger a random event every turn | ||
updateStats(); | ||
} | ||
}, 5000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #121212; /* Black background */ | ||
color: #ffffff; /* White text for contrast */ | ||
text-align: center; | ||
margin: 0; | ||
padding: 20px; | ||
} | ||
|
||
#game { | ||
max-width: 800px; /* Limit the width of the game */ | ||
margin: 0 auto; /* Center the game */ | ||
padding: 20px; | ||
border: 2px solid #ffffff; /* White border */ | ||
border-radius: 10px; | ||
background-color: #1e1e1e; /* Darker background for the game area */ | ||
} | ||
|
||
#ecosystem { | ||
display: flex; | ||
justify-content: center; | ||
margin: 20px; | ||
} | ||
|
||
.species { | ||
width: 50px; | ||
height: 50px; | ||
margin: 5px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
border-radius: 5px; | ||
font-size: 24px; | ||
} | ||
|
||
.plant { | ||
background-color: #4caf50; /* Green for plants */ | ||
} | ||
|
||
.animal { | ||
background-color: #ff9800; /* Orange for animals */ | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
margin: 5px; | ||
border: none; | ||
border-radius: 5px; | ||
background-color: #007bff; /* Blue button */ | ||
color: white; | ||
cursor: pointer; | ||
font-size: 16px; | ||
transition: background-color 0.3s; | ||
} | ||
|
||
button:hover { | ||
background-color: #0056b3; /* Darker blue on hover */ | ||
} | ||
|
||
#stats { | ||
margin-top: 20px; | ||
font-size: 18px; | ||
background-color: #333; /* Dark background for stats */ | ||
padding: 10px; | ||
border-radius: 5px; | ||
} |