-
Notifications
You must be signed in to change notification settings - Fork 1
/
peer_teaching_roleplay_game.html
422 lines (391 loc) · 15.9 KB
/
peer_teaching_roleplay_game.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
<!DOCTYPE html>
<html>
<head>
<title>Wildlife Conservation Game</title>
<style>
.section {
border: 1px solid black;
margin: 10px;
padding: 10px;
}
.poacher-section {
border: 1px solid black;
margin: 10px;
padding: 10px;
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
}
.money-text {
font-weight: bold;
text-align: center;
font-size: 30px;
}
.population-text {
font-weight: bold;
text-align: center;
font-size: 18px;
}
.description {
font-weight: bold;
font-size: 16px;
}
.poacher-content {
width: 80%;
text-align: left;
}
.image-container {
width: 20%;
}
.money-bag {
position: absolute;
cursor: pointer;
}
.animal-container {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
}
.animal-section {
width: 23%;
margin: 0.40%;
padding: 8px;
border: 1px solid black;
}
.conservationist-section {
border: 1px solid black;
margin: 10px;
padding: 10px;
position: relative;
display: flex;
flex-direction: column;
align-items: center;
}
</style>
</head>
<body>
<h1>Wildlife Conservation Game</h1>
<!-- Animals Section -->
<div class="animal-container">
<div class="animal-section" id="tigers-section">
<h2>Tigers</h2>
<div class="image-container"> <img src="Malayan_Tiger.png" class="" width="139.40" height="160.00" alt=""/> </div>
<div id="tigerPopulation">Tiger Population: 150</div>
<label for="tigerValue">Tiger Produce Value: </label>
<input type="number" id="tigerValue" value="100">
<label for="tigerValue">M</label>
<h3>Animal Variables</h3>
<table>
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
<tr>
<td>Young Population</td>
<td><input type="number" id="youngPopulation1" value="75"></td>
</tr>
<tr>
<td>Adult Population</td>
<td><input type="number" id="adultPopulation1" value="75"></td>
</tr>
<tr>
<td>Maturity Rate (%)</td>
<td><input type="number" id="maturityRate1" value="20"></td>
</tr>
<tr>
<td>Survival Rate (%)</td>
<td><input type="number" id="survivalRate1" value="75"></td>
</tr>
<tr>
<td>Fertility Rate</td>
<td><input type="number" id="fertilityRate1" value="0.3"></td>
</tr>
</table>
<button onclick="calculateNextBatch('tigerPopulation', 'youngPopulation1', 'adultPopulation1', 'maturityRate1', 'survivalRate1', 'fertilityRate1', 'tigerResult')">Calculate Next Batch</button>
<div id="tigerResult"></div>
</div>
<div class="animal-section" id="slow lorises-section">
<h2>Slow Lorises</h2>
<div class="image-container"> <img src="Slow_Loris.png" class="" width="139.40" height="160.00" alt=""/> </div>
<div id="slow lorisesPopulation">Slow Lorises Population: 3000</div>
<label for="slow lorisesValue">Slow Lorises Produce Value: </label>
<input type="number" id="slow lorisesValue" value="100">
<label for="slow lorisesValue">M</label>
<h3>Animal Variables</h3>
<table>
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
<tr>
<td>Young Population</td>
<td><input type="number" id="youngPopulation2" value="1500"></td>
</tr>
<tr>
<td>Adult Population</td>
<td><input type="number" id="adultPopulation2" value="1500"></td>
</tr>
<tr>
<td>Maturity Rate (%)</td>
<td><input type="number" id="maturityRate2" value="50"></td>
</tr>
<tr>
<td>Survival Rate (%)</td>
<td><input type="number" id="survivalRate2" value="76"></td>
</tr>
<tr>
<td>Fertility Rate</td>
<td><input type="number" id="fertilityRate2" value="0.85"></td>
</tr>
</table>
<button onclick="calculateNextBatch('slow lorisesPopulation', 'youngPopulation2', 'adultPopulation2', 'maturityRate2', 'survivalRate2', 'fertilityRate2', 'slow lorisesResult')">Calculate Next Batch</button>
<div id="slow lorisesResult"></div>
</div>
<div class="animal-section" id="bulbul-section">
<h2>Bulbul</h2>
<div class="image-container"> <img src="Bulbul.png" class="" width="139.40" height="160.00" alt=""/> </div>
<div id="bulbulPopulation">Bulbul Population: 1500</div>
<label for="bulbulValue">Bulbul Produce Value: </label>
<input type="number" id="bulbulValue" value="100">
<label for="bulbulValue">M</label>
<h3>Animal Variables</h3>
<table>
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
<tr>
<td>Young Population</td>
<td><input type="number" id="youngPopulation3" value="750"></td>
</tr>
<tr>
<td>Adult Population</td>
<td><input type="number" id="adultPopulation3" value="750"></td>
</tr>
<tr>
<td>Maturity Rate (%)</td>
<td><input type="number" id="maturityRate3" value="75"></td>
</tr>
<tr>
<td>Survival Rate (%)</td>
<td><input type="number" id="survivalRate3" value="60"></td>
</tr>
<tr>
<td>Fertility Rate</td>
<td><input type="number" id="fertilityRate3" value="0.89"></td>
</tr>
</table>
<button onclick="calculateNextBatch('bulbulPopulation', 'youngPopulation3', 'adultPopulation3', 'maturityRate3', 'survivalRate3', 'fertilityRate3','bulbulResult')">Calculate Next Batch</button>
<div id="bulbulResult"></div>
</div>
<div class="animal-section" id="sambar deer-section">
<h2>Sambar Deer</h2>
<div class="image-container"> <img src="Sambar_deer.png" class="" width="139.40" height="160.00" alt=""/> </div>
<div id="sambar deerPopulation">Sambar Deer Population: 200</div>
<label for="sambar deerValue">Sambar Deer Produce Value: </label>
<input type="number" id="sambar deerValue" value="100">
<label for="sambar deerValue">M</label>
<h3>Animal Variables</h3>
<table>
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
<tr>
<td>Young Population</td>
<td><input type="number" id="youngPopulation4" value="100"></td>
</tr>
<tr>
<td>Adult Population</td>
<td><input type="number" id="adultPopulation4" value="100"></td>
</tr>
<tr>
<td>Maturity Rate (%)</td>
<td><input type="number" id="maturityRate4" value="50"></td>
</tr>
<tr>
<td>Survival Rate (%)</td>
<td><input type="number" id="survivalRate4" value="80"></td>
</tr>
<tr>
<td>Fertility Rate</td>
<td><input type="number" id="fertilityRate4" value="0.2"></td>
</tr>
</table>
<button onclick="calculateNextBatch('sambar deerPopulation', 'youngPopulation4', 'adultPopulation4', 'maturityRate4', 'survivalRate4', 'fertilityRate4','sambar deerResult')">Calculate Next Batch</button>
<div id="sambar deerResult"></div>
</div>
</div>
<!-- Poachers Section -->
<div class="poacher-section" ondragover="allowDrop(event)" ondrop="drop(event)">
<div class="poacher-content">
<h2 style="text-align: center;">Poachers</h2>
<div class="money-text" id="poacherMoney">Money: $1000M</div>
<h3>Hunt Action</h3>
<h4> Revenue is roughly calculated by having a larger Dice Result against the Critical Roll.<br>
(The Animal's Population also affects the result)</h4>
<label for="criticalRoll">Critical Roll:</label>
<input type="number" id="criticalRoll" value="5">
<br>
<br>
<label for="diceResult">Dice Result (1-20):</label>
<input type="number" id="diceResult" min="1" max="20">
<br>
<br>
<label for="moneyInvested">Money Invested:</label>
<input type="number" id="moneyInvested" min="0">
<br>
<label for="animalSelect">Select an animal to hunt: </label>
<select id="animalSelect">
<option value="tiger">tiger</option>
<option value="slow lorises">slow lorises</option>
<option value="bulbul">bulbul</option>
<option value="sambar deer">sambar deer</option>
</select>
<br>
<button onclick="hunt()">Go Hunting</button>
<br>
<br>
<div id="huntResult"></div>
</div>
<div class="image-container"> <img src="Money_Bag_Transparent_Clip_Art_Image.png" class="money-bag" draggable="true" ondragstart="dragStart(event)" width="139.40" height="160.00" alt=""/> </div>
</div>
<!-- Conservationists Section -->
<div class="conservationist-section">
<h2>Conservationists</h2>
<label for="conservationalistFunds">Funds: </label>
<input type="number" id="conservationalistFunds" value="100">
<label for="conservationalistFunds"></label>
<br>
<br>
<label for="publicAwareness">Public Support (Arbitrary Value): </label>
<input type="number" id="publicAwareness" value="50">
<br>
<br>
<button onclick="raiseFunds()">Raise Funds</button>
<br>
</div>
<script>
// Initialize poacher money and tiger population
var poacherMoney = 1000;
// var tigerPopulation = 100;
// var tigerPrice = 100; // Price of a tiger in the black market
function updatePoacherMoney() {
document.getElementById('poacherMoney').innerHTML = "Money: $" + poacherMoney + "M";
// document.getElementById('poacherTigerPopulation').innerHTML = "Tiger Population: " + tigerPopulation;
}
function hunt() {
var moneyInvested = parseFloat(document.getElementById('moneyInvested').value);
if (moneyInvested > poacherMoney || moneyInvested < 0) {
alert("Invalid money invested. Please enter a value between 0 and " + poacherMoney);
return;
}
var criticalRoll = parseFloat(document.getElementById('criticalRoll').value);
var diceResult = parseFloat(document.getElementById('diceResult').value);
var animalsKilled = 0;
var moneyChange = 0;
var huntingSuccessRate = 0;
var precentageMoneyLost = 0;
//get targetPopulation based on animalSelect
var animalSelect = document.getElementById('animalSelect');
var animalIndex = animalSelect.selectedIndex + 1;
var selectedOption = animalSelect.options[animalIndex - 1].value;
var targetAdultPopulationString = "adultPopulation" + animalIndex;
var targetAdultPopulation = parseFloat(document.getElementById(targetAdultPopulationString).value);
var targetYoungPopulation = parseFloat(document.getElementById("youngPopulation"+animalIndex).value);
var targetPrice = parseFloat(document.getElementById(selectedOption+"Value").value);
var targetFertility = parseFloat(document.getElementById("fertilityRate"+animalIndex).value);
if (diceResult >= criticalRoll) {
// The new equation for huntingSuccessRate
huntingSuccessRate = 0.02 + 0.15 * Math.pow((diceResult - criticalRoll + 4.2) / 18, 1.66);
// Apply a concave function influenced by the money spent
var moneyEffect = Math.min(moneyInvested, 10000) / 10000;
huntingSuccessRate = huntingSuccessRate + (0.51 - huntingSuccessRate) * Math.pow(moneyEffect, 0.5);
// Number of tigers killed is now based on the percentage of the tiger population
animalsKilled = Math.round(huntingSuccessRate * targetAdultPopulation);
// Update poacher money and tiger population
moneyChange = Math.round(animalsKilled * targetPrice);
} else {
// No tigers are killed if diceResult < criticalRoll
animalsKilled = 0;
// Losses incurred between 0.2 to 0.9 depending on how much lower the roll is
precentageMoneyLost = (0.9 - 0.7 * (criticalRoll - diceResult) / (criticalRoll - 1));
if (diceResult === 1) {
// If it's a nat 1, they only keep 4.2% of the money invested
precentageMoneyLost = 0.042;
}
moneyChange = -Math.round(moneyInvested * (1 - precentageMoneyLost));
}
poacherMoney += moneyChange;
youngKilled = Math.round(animalsKilled * 0.6 * targetFertility);
updatePoacherMoney();
document.getElementById('huntResult').innerText = selectedOption + " killed: " + animalsKilled + ".\nYoung died: " + youngKilled + ".\nMoney Change: $" + moneyChange + "M.";
updateAnimalValues("youngPopulation"+animalIndex, "adultPopulation"+animalIndex, selectedOption+"Result", selectedOption+"Population", targetYoungPopulation - youngKilled, targetAdultPopulation - animalsKilled);
}
function calculateNextBatch(totalPopulation, youngPopID, adultPopID, matureRateID, survivalRateID, fertilityRateID, resultID) {
// Get values from input fields
youngPopulation = parseFloat(document.getElementById(youngPopID).value);
adultPopulation = parseFloat(document.getElementById(adultPopID).value);
maturityRate = parseFloat(document.getElementById(matureRateID).value);
survivalRate = parseFloat(document.getElementById(survivalRateID).value);
fertilityRate = parseFloat(document.getElementById(fertilityRateID).value);
// Calculate next batch
var newAdults = youngPopulation * (maturityRate / 100);
var newYoung = Math.round(adultPopulation * fertilityRate / 2);
var survivingAdults = adultPopulation * (survivalRate / 100);
var survivingYoung = youngPopulation * (survivalRate / 100);
youngPopulation = Math.floor(survivingYoung + newYoung - newAdults);
adultPopulation = Math.floor(survivingAdults + newAdults);
// tigerPopulation = Math.floor(youngPopulation + adultPopulation);
// Update display values
updateAnimalValues(youngPopID, adultPopID, resultID, totalPopulation, youngPopulation, adultPopulation);
updatePoacherMoney(); // to update the tiger population displayed in the Poachers section
}
function updateAnimalValues(youngPopID, adultPopID, resultID, totalPopulation, youngPopulation, adultPopulation) {
document.getElementById(youngPopID).value = youngPopulation;
document.getElementById(adultPopID).value = adultPopulation;
document.getElementById(resultID).innerHTML = "New Adult Population: " + adultPopulation + ",\nNew Young Population: " + youngPopulation;
var oldTotalPopulation = document.getElementById(totalPopulation).innerText.split(" ").splice(0, 2);
document.getElementById(totalPopulation).innerHTML = oldTotalPopulation.join(" ") + " " + (youngPopulation + adultPopulation);
}
function dragStart(event) {
console.log("Drag started");
event.dataTransfer.setData("text/plain", event.target.outerHTML);
}
function allowDrop(event) {
event.preventDefault();
}
function drop(event) {
event.preventDefault();
const dropTarget = event.target.closest('.poacher-section');
// Debug the bounding rectangle and client coordinates
const rect = dropTarget.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
const newBag = document.createElement('img');
console.log("newBag:", newBag); // Debug log
newBag.src = 'Money_Bag_Transparent_Clip_Art_Image.png';
newBag.className = 'money-bag';
newBag.width = 69.7;
newBag.height = 80;
newBag.style.position = 'absolute';
newBag.style.left = `${x}px`;
newBag.style.top = `${y}px`;
// Attach click event for deletion
newBag.addEventListener('click', function() {
dropTarget.removeChild(newBag);
});
dropTarget.appendChild(newBag);
}
function raiseFunds() {
const funds = parseFloat(document.getElementById('conservationalistFunds').value);
const publicAwareness = parseFloat(document.getElementById('publicAwareness').value);
// Your logic here to calculate new funds based on critical roll and public awareness
newFunds = funds + publicAwareness;
// Update the fundResult div with the result
document.getElementById('conservationalistFunds').value = newFunds;
}
</script>
</body>
</html>