Private
Public Access
1
0

game ends after x mines

This commit is contained in:
2016-11-18 19:28:52 +01:00
parent 0d2ac0fb33
commit 165889346e
3 changed files with 27 additions and 3 deletions

View File

@@ -35,8 +35,7 @@
{% endif %}
<main>
{% block fos_user_content %}
{% endblock fos_user_content %}
{% block fos_user_content %}{% endblock fos_user_content %}
<canvas id="demo-canvas"></canvas>
</main>

View File

@@ -28,6 +28,22 @@ class MineSeeker extends React.Component {
return text;
}
/** game end control */
makeGameEndIfItEnds(bluePoints, redPoints) {
var redWins = redPoints > 3,
blueWins = bluePoints > 3;
if (redWins || blueWins) {
this.refs.gridControl.setState({
overlay: true,
overlayTitle: (redWins ? 'Red' : 'Blue') + " wins the game!",
overlaySubTitle: "Play again!"
});
this.refs.gridControl.state.sound.won.play();
}
}
/** after rendering */
componentDidMount() {
/** Create Websocket w/ Bahnhof.js */
@@ -95,6 +111,12 @@ class MineSeeker extends React.Component {
this.refs.gridControl.refs.userControl.state.bombSelected = payload.data.bomb;
this.refs.gridControl.stepEvent(payload.data.coords);
/** End-game control */
this.makeGameEndIfItEnds(
this.refs.gridControl.refs.userControl.refs.blue.state.mines,
this.refs.gridControl.refs.userControl.refs.red.state.mines
);
}
} else {
@@ -158,6 +180,9 @@ class MineSeeker extends React.Component {
: 0
);
/** End-game control */
this.makeGameEndIfItEnds(bluePoints, redPoints);
this.state.session
.publish(this.state.channel, {
'coords': coords,