
How the Game Works
Key Features:
Customizing the game involves replacing the current images (tree and fire) with different elements or modifying the gameplay logic to suit your needs. Here’s how you can do it:
Step 1: Prepare New Images
Step 2: Place the Images
Step 3: Update the Code
Replace Actions (e.g., Change Button Purpose)
Code:
function plantTree() {
const emptyTiles = tiles.filter(tile => !tile.hasTree && !tile.hasFire);
if (emptyTiles.length > 0) {
const randomTile = emptyTiles[Math.floor(Math.random() * emptyTiles.length)];
randomTile.hasTree = true;
randomTile.element.classList.add(‘plant’);
randomTile.element.querySelector(‘img’).src = ‘images/flower.png’; // Replace tree with flower
}
}
Introduce new game mechanics by adding more elements. For example:
Code:
function addAnimal() {
const emptyTiles = tiles.filter(tile => !tile.hasTree && !tile.hasFire);
if (emptyTiles.length > 0) {
const randomTile = emptyTiles[Math.floor(Math.random() * emptyTiles.length)];
randomTile.hasAnimal = true;
const animalImage = document.createElement(‘img’);
animalImage.src = ‘images/animal.png’;
animalImage.alt = ‘Animal’;
randomTile.element.appendChild(animalImage);
}
}
Change the grid size in the CSS:
.game-container {
grid-template-columns: repeat(6, 1fr); /* 6 columns for a larger grid */
}
Update the createBoard() function to match the new grid size:
for (let i = 0; i < 36; i++) { // For a 6×6 grid
// Tile creation logic
}
Modify the probability of fires or other events:
Locate the checkForFires() function:
if (Math.random() < 0.3) { // 30% chance to ignite a fire
igniteFire();
}
Change 0.3 to a higher or lower value to adjust the frequency of fires.
Implement a scoring system that rewards players for planting trees and extinguishing fires. Each successful action will award points, incentivizing players to perform these tasks efficiently.
Details:
Implement a score tracker. Add a score display to the HTML:
<div id=”scoreBoard”>Score: 0</div>
Update the score in JavaScript when trees are planted or fires extinguished:
let score = 0;
function updateScore(points) {
score += points;
document.getElementById(‘scoreBoard’).innerText = `Score: ${score}`;
}
Sample Code for the Scoring System:
let score = 0;
function plantTree() {
score += 10; // Añade 10 puntos por cada árbol plantado
updateScoreDisplay();
}
function extinguishFire() {
score += 20; // Añade 20 puntos por cada incendio extinguido
updateScoreDisplay();
}
function updateScoreDisplay() {
document.getElementById(‘score’).textContent = `Puntuación: ${score}`;
}
Change the background or colors in the CSS:
body {
background-color: #f0e68c; /* Change to a sand-like theme */
}
.tile {
background-color: #ffd700; /* Golden tiles */
}
Add a timer to increase the game’s challenge level. Players must complete their tasks within a time limit, which will add an extra layer of pressure and excitement.
Details:
Code for the Timer:
let timeLeft = 60; Time in seconds
function startTimer() {
const timerInterval = setInterval(() => {
if (timeLeft > 0) {
timeLeft–;
updateTimerDisplay();
} else {
clearInterval(timerInterval);
endGame();
}
}, 1000);
}
function updateTimerDisplay() {
document.getElementById(‘timer’).textContent = ‘Tiempo Restante: ${timeLeft}s’;
}
function endGame() {
alert(‘Time is up! End of the game.’);
}
It introduces visual animations for the actions of planting trees and extinguishing fires, making the game more engaging and dynamic.
Details: