Commit 12f92c6c authored by Matthew Odle's avatar Matthew Odle

add game over conditions

parent de9546cc
import React from 'react';
export class GameOver extends React.Component {
render(props) {
return <div className="gameover">
<h3>They're all dead, Jim</h3>
</div>
}
}
......@@ -3,6 +3,7 @@ import React from 'react';
import { Building } from './building';
import { Stock } from './stock';
import { Villager } from './villager';
import { GameOver } from './game-over';
export class Village extends React.Component {
......@@ -383,7 +384,20 @@ export class Village extends React.Component {
this.updateAllVillagers(villagers);
}
checkGameEndConditions = () => {
const villagers = this.state.villagers.slice();
let everyoneIsDead = true;
villagers.map( villager => villager.assignment === 'DEAD' && everyoneIsDead ? everyoneIsDead = true : everyoneIsDead = false);
this.setState({
gameOver: everyoneIsDead,
});
}
tick = () => {
this.checkGameEndConditions();
if (this.state.gameOver) {
return;
}
const buildings = this.props.buildings.slice();
this.manageProductionBuildings(buildings);
this.manageVillagerConditions();
......@@ -418,6 +432,7 @@ export class Village extends React.Component {
<h3>Score: { Math.floor(this.state.score / 1000) }</h3>
{/* <button type="button" id="restart" onClick={() => this.props.restart()}>Restart</button> */}
</div>
{this.state.gameOver ? <GameOver /> : null}
</div>
<div className="management">
<div className="buildings">
......
......@@ -22,8 +22,8 @@ const knobsAndLevers = {
villagerClothed: true,
clothingDegradeRate: 1,
clothingWarmthDecayReduction: 5,
baseWarmthDecayRate: 10,
clothingWarmthDecayReduction: 2,
baseWarmthDecayRate: 2,
warmthReplenishThreshold: 10,
warmthPerFirewood: 80,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment