-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame3.js
58 lines (51 loc) · 1.43 KB
/
game3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
let water = 100;
let soil = 100;
let energy = 100;
let sustainability = 0;
function updateStats() {
document.getElementById('water').innerText = water;
document.getElementById('soil').innerText = soil;
document.getElementById('energy').innerText = energy;
document.getElementById('sustainability').innerText = sustainability;
}
function plantCrops() {
if (water > 10 && soil > 10) {
water -= 10;
soil -= 10;
sustainability += 5;
setMessage("You planted crops sustainably!");
} else {
setMessage("Not enough water or soil health to plant crops.");
}
updateStats();
}
function installSolar() {
if (energy > 20) {
energy -= 20;
sustainability += 15;
setMessage("You installed solar panels, great for sustainability!");
} else {
setMessage("Not enough energy to install solar panels.");
}
updateStats();
}
function harvestRainwater() {
water += 15;
sustainability += 10;
setMessage("You harvested rainwater, conserving resources!");
updateStats();
}
function useFertilizer() {
if (soil > 10) {
soil -= 20;
sustainability -= 5;
setMessage("You used chemical fertilizer, not sustainable!");
} else {
setMessage("Not enough soil health to use fertilizer.");
}
updateStats();
}
function setMessage(msg) {
document.getElementById('message').innerText = msg;
}
updateStats();