Skip to content

Commit

Permalink
Added plant alive feedback is plant is alive when simulation reaches …
Browse files Browse the repository at this point in the history
…end of days
  • Loading branch information
breity committed Jan 26, 2021
1 parent 2b24f6e commit 5f83d64
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 15 deletions.
13 changes: 9 additions & 4 deletions src/plantGlucoseSimulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class PlantGlucoseSimulation {
isLightOnRequestedInNextCycle: boolean = false;
isLightOffRequestedInNextCycle: boolean = false;
numDays: number = 20;
targetDays: number = 20;
numLightOptions: number = 2;
lightSwitch: any;
waterSwitch: WaterSwitch;
Expand Down Expand Up @@ -158,7 +159,7 @@ export class PlantGlucoseSimulation {
showLineGlucoseStored: boolean = true, showWater: boolean = true,
enableInputControls: boolean = true) {
this.draw = SVG(elementId);
this.numDays = numDays;
this.numDays = this.targetDays = numDays;
this.numLightOptions = numLightOptions;
this.showWater = showWater;
this.enableInputControls = enableInputControls;
Expand Down Expand Up @@ -206,6 +207,7 @@ export class PlantGlucoseSimulation {
}
this.resetSimulation();
this.setInputValues(this.playSequence[0]);
this.enableControlButtons();
}
}

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

if (this.numWaterNextCycle != null &&
this.numWaterNextCycle != this.numWaterThisCycle) {
if (this.numWaterNextCycle != null && this.numWaterNextCycle != this.numWaterThisCycle) {
this.updateNumWaterThisCycle(this.numWaterNextCycle);
this.waterSwitch.hideWaitImage();
}
Expand Down Expand Up @@ -819,7 +820,11 @@ export class PlantGlucoseSimulation {
handleSimulationEnded() {
this.addEvent('simulationEnded');
this.pauseSimulation();
this.simulationEndFeedback.showSimulationEnded();
if (this.currentDayNumber === this.targetDays + 1) {
this.simulationEndFeedback.showPlantAlive();
} else {
this.simulationEndFeedback.showSimulationEnded();
}
this.disableControlButtons();
this.saveStudentWork();
}
Expand Down
73 changes: 62 additions & 11 deletions src/simulationEndFeedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import * as SVG from "svg.js";
* either by completing the entire duration, or the plant dying midway.
* @author Hiroki Terashima
* @author Geoffrey Kwan
* @author Jonathan Lim-Breitbart
*/
export class SimulationEndFeedback {
draw: SVG;
plantAliveRect: SVG;
plantAliveText: SVG;
plantDiedRect: SVG;
plantDiedText: SVG;
simulationEndedRect: SVG;
Expand All @@ -20,20 +23,56 @@ export class SimulationEndFeedback {
constructor(draw: SVG) {
this.draw = draw;

this.simulationEndedRect = this.draw.rect(500, 100).x(250).y(400)
.fill('lightblue').stroke({width:2})
.opacity(1).attr({ 'fill-opacity': 1 }).hide();
this.simulationEndedRect = this.draw
.rect(500, 100)
.x(250)
.y(400)
.fill("lightblue")
.stroke({ width: 2 })
.opacity(1)
.attr({ "fill-opacity": 1 })
.hide();

this.simulationEndedText = this.draw.text('Simulation ended')
.x(315).y(410).font({size: 48}).hide();
this.simulationEndedText = this.draw
.text("Simulation ended")
.x(315)
.y(410)
.font({ size: 48 })
.hide();

this.plantDiedRect = this.draw.rect(500, 100).x(250).y(400)
.fill('#FF0000').stroke({width:2}).opacity(1).attr({
'fill-opacity': 1
}).hide();
this.plantAliveRect = this.draw
.rect(500, 100)
.x(250)
.y(400)
.fill("#33FF00")
.stroke({ width: 2 })
.opacity(1)
.attr({ "fill-opacity": 1 })
.hide();

this.plantDiedText = this.draw.text('The plant has died')
.x(300).y(410).font({size: 48, fill: 'white'}).hide();
this.plantAliveText = this.draw
.text("The plant is alive")
.x(315)
.y(410)
.font({ size: 48 })
.hide();

this.plantDiedRect = this.draw
.rect(500, 100)
.x(250)
.y(400)
.fill("#FF0000")
.stroke({ width: 2 })
.opacity(1)
.attr({ "fill-opacity": 1 })
.hide();

this.plantDiedText = this.draw
.text("The plant has died")
.x(300)
.y(410)
.font({ size: 48, fill: "white" })
.hide();
}

/**
Expand All @@ -44,6 +83,8 @@ export class SimulationEndFeedback {
this.plantDiedText.hide();
this.simulationEndedRect.hide();
this.simulationEndedText.hide();
this.plantAliveRect.hide();
this.plantAliveText.hide();
}

/**
Expand All @@ -65,4 +106,14 @@ export class SimulationEndFeedback {
this.simulationEndedRect.show();
this.simulationEndedText.show();
}

/**
* Shows plant alive feedback and bring it to the front
*/
showPlantAlive() {
this.plantAliveRect.front();
this.plantAliveText.front();
this.plantAliveRect.show();
this.plantAliveText.show();
}
}

0 comments on commit 5f83d64

Please sign in to comment.