Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes regarding winning/losing #128

Merged
merged 6 commits into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface IProps { }
export interface IState {
week: number;
name: string;
gameOver: boolean;
playerStats: PlayerStats;
currentEvent: IEvent;
eventTracker: EventTracker;
Expand All @@ -36,6 +37,7 @@ const emptyMinigame: IMinigame = {
};

export default class App extends React.Component<IProps, IState> {
static readonly maxWeeks: number = 5;
private choiceManager: ChoicesManager;
private eventManager: EventsManager;
private minigameManager: MinigamesManager;
Expand Down Expand Up @@ -66,6 +68,7 @@ export default class App extends React.Component<IProps, IState> {
this.state = {
week: 0,
name: "P1",
gameOver: false,
playerStats: playerStats,
currentEvent: firstEvent,
eventTracker: eventTracker,
Expand All @@ -75,30 +78,36 @@ export default class App extends React.Component<IProps, IState> {

makeChoice = (choice: IChoice) => {
if (choice.minigame === "") {
let gameOver = false;
this.state.playerStats.applyStatChanges(choice.statChanges, choice.dlogo);

if (this.state.week >= 2 && this.state.playerStats.getGpa() < 1.0) {
// Losing condition
this.state.eventTracker.queueFollowUpEvent(
this.eventManager.get("LoseEvent")
);
} else if (this.state.week > 5) {
// Winning condition if not losing
this.state.eventTracker.queueFollowUpEvent(
this.eventManager.get("WinEvent")
);
if (choice.followUp === "" && this.state.week > App.maxWeeks) {
if (this.state.playerStats.getGpa() >= 1.0) {
// Winning condition
this.state.eventTracker.queueFollowUpEvent(
this.eventManager.get("WinEvent")
);
} else {
// Lose condition is everything else
this.state.eventTracker.queueFollowUpEvent(
this.eventManager.get("LoseEvent")
);
}
gameOver = true;
} else if (choice.followUp !== "") {
// The game isn't ending and there is a follow up event
this.state.eventTracker.queueFollowUpEvent(
this.eventManager.get(choice.followUp)
);
}

let nextEvent = this.state.eventTracker.getNextEvent(this.state.week + 1);
let weekDelta = (choice.followUp !== "" ? 0 : 1);
let nextEvent = this.state.eventTracker.getNextEvent(weekDelta + this.state.week);

this.setState(prevState => {
return {
week: prevState.week + 1,
week: prevState.week + weekDelta,
gameOver: gameOver,
playerStats: prevState.playerStats,
currentEvent: nextEvent,
eventTracker: prevState.eventTracker,
Expand All @@ -120,6 +129,7 @@ export default class App extends React.Component<IProps, IState> {
this.setState(prevState => {
return {
week: prevState.week,
gameOver: false,
playerStats: prevState.playerStats,
currentEvent: minigameEvent,
eventTracker: prevState.eventTracker,
Expand All @@ -135,6 +145,7 @@ export default class App extends React.Component<IProps, IState> {
this.setState(prevState => {
return {
week: prevState.week + 1,
gameOver: false,
playerStats: prevState.playerStats,
currentEvent: nextEvent,
eventTracker: prevState.eventTracker,
Expand Down Expand Up @@ -168,6 +179,15 @@ export default class App extends React.Component<IProps, IState> {
transform: "scale(" + scale + ")",
};

const ggButt = this.state.gameOver && (
<button
className="this-align-center choice-btn-70 nes-btn"
onClick={() => window.location.reload(false)}
>
Play Again?
</button>
);

return (
<div id="app" >
<div id="game-container" style={style} className="nes-container is-ubc-alt-blue has-box-shadow">
Expand All @@ -192,6 +212,8 @@ export default class App extends React.Component<IProps, IState> {
<p id="prompt" className="this-align-center">
{currentEvent.prompt}
</p>

{ggButt}
<Choices
choices={currentEvent.choices}
mgr={this.choiceManager}
Expand All @@ -204,4 +226,4 @@ export default class App extends React.Component<IProps, IState> {
</div>
);
}
}
}
Binary file added src/assets/losing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/winning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 20 additions & 17 deletions src/choices.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,56 +120,59 @@
},
"Arts": {
"answer": "Arts",
"followUp": "",
"followUp": "PickResidenceEvent",
"statChanges": [50, 2.0, 100],
"minigame": "",
"dlogo": ["ARTS", "#522E91", "#FFFFFF"],
"btnStyle": "arts"
},
"Forestry": {
"answer": "Forestry",
"followUp": "",
"statChanges": [100, 2.0, 100],
"Forestry":
{
"answer":"Forestry",
"followUp":"PickResidenceEvent",
"statChanges":[100, 2.0, 100],
"minigame": "",
"dlogo": ["FORE", "#162A00", "#FFFFFF"],
"btnStyle": "fore"
},
"Commerce": {
"answer": "Commerce",
"followUp": "",
"statChanges": [100, 2.0, 100],
"Commerce":
{
"answer":"Commerce",
"followUp":"PickResidenceEvent",
"statChanges":[100, 2.0, 100],
"minigame": "",
"dlogo": ["COMM", "#8D8D8D", "#FFFFFF"],
"btnStyle": "comm"
},
"Kinesiology": {
"answer": "Kinesiology",
"followUp": "",
"statChanges": [100, 2.0, 100],
"Kinesiology":
{
"answer":"Kinesiology",
"followUp":"PickResidenceEvent",
"statChanges":[100, 2.0, 100],
"minigame": "",
"dlogo": ["KIN", "#228B22", "#FFFFFF"],
"btnStyle": "kin"
},

"ApScience": {
"answer": "Applied Science",
"followUp": "",
"followUp": "PickResidenceEvent",
"statChanges": [0, 4.0, 100],
"minigame": "",
"dlogo": ["APSC", "#B20E22", "#FFFFFF"],
"btnStyle": "apsc"
},
"Science": {
"answer": "Science",
"followUp": "",
"followUp": "PickResidenceEvent",
"statChanges": [50, 3.0, 100],
"minigame": "",
"dlogo": ["SCIE", "#3498DB", "#FFFFFF"],
"btnStyle": "scie"
},
"LFS": {
"answer": "Land and Food Systems",
"followUp": "",
"followUp": "PickResidenceEvent",
"statChanges": [100, 2.0, 100],
"minigame": "",
"dlogo": ["LFS", "#000000", "#FFFFFF"],
Expand Down Expand Up @@ -266,4 +269,4 @@
"minigame": "",
"btnStyle": ""
}
}
}
3 changes: 2 additions & 1 deletion src/components/hud/ProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from "react";
import App from "../../App";

interface IProps {
week: number;
}

export default function ProgressBar(props: IProps) {
return <progress id="progress-bar" className="nes-progress is-success float-right" value={props.week} max="5" />;
return <progress id="progress-bar" className="nes-progress is-success float-right" value={props.week} max={App.maxWeeks} />;
}
6 changes: 3 additions & 3 deletions src/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,18 @@
},
"WinEvent": {
"prompt": "You win! You have survived!",
"imgPath": "",
"imgPath": "winning.png",
"choices": [],
"hasBottomBoxBorder": true,
"hasInnerFill": true,
"gamePlayMode": "GameOver"
},
"LoseEvent": {
"prompt": "Game over. You lose.",
"imgPath": "",
"imgPath": "losing.png",
"choices": [],
"hasBottomBoxBorder": true,
"hasInnerFill": true,
"gamePlayMode": "GameOver"
}
}
}
4 changes: 1 addition & 3 deletions src/game-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"MidtermEvent"
],
"followUp": [
"LandingEvent",
"PickFacultyEvent",
"PickResidenceEvent"
"LandingEvent", "PickFacultyEvent"
],
"seasonal": [
["ImagineDayEvent"],
Expand Down