Skip to content

Commit 5f83d64

Browse files
committed
Added plant alive feedback is plant is alive when simulation reaches end of days
1 parent 2b24f6e commit 5f83d64

2 files changed

Lines changed: 71 additions & 15 deletions

File tree

src/plantGlucoseSimulation.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export class PlantGlucoseSimulation {
9595
isLightOnRequestedInNextCycle: boolean = false;
9696
isLightOffRequestedInNextCycle: boolean = false;
9797
numDays: number = 20;
98+
targetDays: number = 20;
9899
numLightOptions: number = 2;
99100
lightSwitch: any;
100101
waterSwitch: WaterSwitch;
@@ -158,7 +159,7 @@ export class PlantGlucoseSimulation {
158159
showLineGlucoseStored: boolean = true, showWater: boolean = true,
159160
enableInputControls: boolean = true) {
160161
this.draw = SVG(elementId);
161-
this.numDays = numDays;
162+
this.numDays = this.targetDays = numDays;
162163
this.numLightOptions = numLightOptions;
163164
this.showWater = showWater;
164165
this.enableInputControls = enableInputControls;
@@ -206,6 +207,7 @@ export class PlantGlucoseSimulation {
206207
}
207208
this.resetSimulation();
208209
this.setInputValues(this.playSequence[0]);
210+
this.enableControlButtons();
209211
}
210212
}
211213

@@ -311,8 +313,7 @@ export class PlantGlucoseSimulation {
311313
} else {
312314
this.dayDisplayCorner.updateDayText('Day ' + this.currentDayNumber);
313315

314-
if (this.numWaterNextCycle != null &&
315-
this.numWaterNextCycle != this.numWaterThisCycle) {
316+
if (this.numWaterNextCycle != null && this.numWaterNextCycle != this.numWaterThisCycle) {
316317
this.updateNumWaterThisCycle(this.numWaterNextCycle);
317318
this.waterSwitch.hideWaitImage();
318319
}
@@ -819,7 +820,11 @@ export class PlantGlucoseSimulation {
819820
handleSimulationEnded() {
820821
this.addEvent('simulationEnded');
821822
this.pauseSimulation();
822-
this.simulationEndFeedback.showSimulationEnded();
823+
if (this.currentDayNumber === this.targetDays + 1) {
824+
this.simulationEndFeedback.showPlantAlive();
825+
} else {
826+
this.simulationEndFeedback.showSimulationEnded();
827+
}
823828
this.disableControlButtons();
824829
this.saveStudentWork();
825830
}

src/simulationEndFeedback.ts

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import * as SVG from "svg.js";
55
* either by completing the entire duration, or the plant dying midway.
66
* @author Hiroki Terashima
77
* @author Geoffrey Kwan
8+
* @author Jonathan Lim-Breitbart
89
*/
910
export class SimulationEndFeedback {
1011
draw: SVG;
12+
plantAliveRect: SVG;
13+
plantAliveText: SVG;
1114
plantDiedRect: SVG;
1215
plantDiedText: SVG;
1316
simulationEndedRect: SVG;
@@ -20,20 +23,56 @@ export class SimulationEndFeedback {
2023
constructor(draw: SVG) {
2124
this.draw = draw;
2225

23-
this.simulationEndedRect = this.draw.rect(500, 100).x(250).y(400)
24-
.fill('lightblue').stroke({width:2})
25-
.opacity(1).attr({ 'fill-opacity': 1 }).hide();
26+
this.simulationEndedRect = this.draw
27+
.rect(500, 100)
28+
.x(250)
29+
.y(400)
30+
.fill("lightblue")
31+
.stroke({ width: 2 })
32+
.opacity(1)
33+
.attr({ "fill-opacity": 1 })
34+
.hide();
2635

27-
this.simulationEndedText = this.draw.text('Simulation ended')
28-
.x(315).y(410).font({size: 48}).hide();
36+
this.simulationEndedText = this.draw
37+
.text("Simulation ended")
38+
.x(315)
39+
.y(410)
40+
.font({ size: 48 })
41+
.hide();
2942

30-
this.plantDiedRect = this.draw.rect(500, 100).x(250).y(400)
31-
.fill('#FF0000').stroke({width:2}).opacity(1).attr({
32-
'fill-opacity': 1
33-
}).hide();
43+
this.plantAliveRect = this.draw
44+
.rect(500, 100)
45+
.x(250)
46+
.y(400)
47+
.fill("#33FF00")
48+
.stroke({ width: 2 })
49+
.opacity(1)
50+
.attr({ "fill-opacity": 1 })
51+
.hide();
3452

35-
this.plantDiedText = this.draw.text('The plant has died')
36-
.x(300).y(410).font({size: 48, fill: 'white'}).hide();
53+
this.plantAliveText = this.draw
54+
.text("The plant is alive")
55+
.x(315)
56+
.y(410)
57+
.font({ size: 48 })
58+
.hide();
59+
60+
this.plantDiedRect = this.draw
61+
.rect(500, 100)
62+
.x(250)
63+
.y(400)
64+
.fill("#FF0000")
65+
.stroke({ width: 2 })
66+
.opacity(1)
67+
.attr({ "fill-opacity": 1 })
68+
.hide();
69+
70+
this.plantDiedText = this.draw
71+
.text("The plant has died")
72+
.x(300)
73+
.y(410)
74+
.font({ size: 48, fill: "white" })
75+
.hide();
3776
}
3877

3978
/**
@@ -44,6 +83,8 @@ export class SimulationEndFeedback {
4483
this.plantDiedText.hide();
4584
this.simulationEndedRect.hide();
4685
this.simulationEndedText.hide();
86+
this.plantAliveRect.hide();
87+
this.plantAliveText.hide();
4788
}
4889

4990
/**
@@ -65,4 +106,14 @@ export class SimulationEndFeedback {
65106
this.simulationEndedRect.show();
66107
this.simulationEndedText.show();
67108
}
109+
110+
/**
111+
* Shows plant alive feedback and bring it to the front
112+
*/
113+
showPlantAlive() {
114+
this.plantAliveRect.front();
115+
this.plantAliveText.front();
116+
this.plantAliveRect.show();
117+
this.plantAliveText.show();
118+
}
68119
}

0 commit comments

Comments
 (0)