Private
Public Access
1
0

show left mines after end #2 && reduce network traffic && better active field checking method

This commit is contained in:
2016-11-19 12:09:05 +01:00
parent 25cc3910f5
commit 2cb38f2681
4 changed files with 154 additions and 126 deletions

View File

@@ -28,19 +28,25 @@ class MineSeeker extends React.Component {
return text;
}
/** game end control */
/** THE END */
makeGameEndIfItEnds(bluePoints, redPoints) {
var redWins = redPoints > 2,
blueWins = bluePoints > 2;
if (redWins || blueWins) {
this.refs.gridControl.state.sound.won.play();
this.refs.gridControl.setState({
overlay: true,
overlayTitle: (redWins ? 'Red' : 'Blue') + " wins the game!",
overlaySubTitle: "Play again!"
});
this.refs.gridControl.state.sound.won.play();
this.refs.gridControl.showLeftMines();
this.refs.gridControl.refs.userControl.setState({ activePlayer: false});
this.refs.gridControl.refs.userControl.refs.red.setState({ active: false });
this.refs.gridControl.refs.userControl.refs.blue.setState({ active: false });
}
}
@@ -107,7 +113,7 @@ class MineSeeker extends React.Component {
this.refs.gridControl.refs.userControl.setState({bombSelected: payload.data.bomb});
this.refs.gridControl.stepEvent(payload.data.coords);
/** End-game control */
/** THE END */
this.makeGameEndIfItEnds(
this.refs.gridControl.refs.userControl.refs.blue.state.mines,
this.refs.gridControl.refs.userControl.refs.red.state.mines
@@ -159,33 +165,36 @@ class MineSeeker extends React.Component {
onClick(coords) {
var activePlayer = this.refs.gridControl.refs.userControl.state.activePlayer ? 'blue' : 'red';
/** Player step and it is the current player */
if (activePlayer === this.refs.gridControl.state.webPlayer) {
this.refs.gridControl.stepEvent(coords);
/** if the clicked field is NEVER CLICKED */
if (this.refs.gridControl.checkFieldHasBeenNeverClicked(coords[0], coords[1])) {
/** Player step and it is the current player */
if (activePlayer === this.refs.gridControl.state.webPlayer) {
this.refs.gridControl.stepEvent(coords);
var mineCache = this.refs.gridControl.state.foundUserMineCache,
redPoints = this.refs.gridControl.refs.userControl.refs.red.state.mines + (
this.refs.gridControl.refs.userControl.refs.red.state.active
? mineCache
: 0
),
bluePoints = this.refs.gridControl.refs.userControl.refs.blue.state.mines + (
this.refs.gridControl.refs.userControl.refs.blue.state.active
? mineCache
: 0
);
var mineCache = this.refs.gridControl.state.foundUserMineCache,
redPoints = this.refs.gridControl.refs.userControl.refs.red.state.mines + (
this.refs.gridControl.refs.userControl.refs.red.state.active
? mineCache
: 0
),
bluePoints = this.refs.gridControl.refs.userControl.refs.blue.state.mines + (
this.refs.gridControl.refs.userControl.refs.blue.state.active
? mineCache
: 0
);
/** End-game control */
this.makeGameEndIfItEnds(bluePoints, redPoints);
/** THE END */
this.makeGameEndIfItEnds(bluePoints, redPoints);
this.state.session
.publish(this.state.channel, {
'coords': coords,
'player': activePlayer,
'bomb': this.refs.gridControl.refs.userControl.state.bombSelected,
'redPoints': redPoints,
'bluePoints': bluePoints
});
this.state.session
.publish(this.state.channel, {
'coords': coords,
'player': activePlayer,
'bomb': this.refs.gridControl.refs.userControl.state.bombSelected,
'redPoints': redPoints,
'bluePoints': bluePoints
});
}
}
}