bugfix points problem in the end #16
This commit is contained in:
@@ -28,6 +28,27 @@ class MineSeeker extends React.Component {
|
||||
return text;
|
||||
}
|
||||
|
||||
/** STEP */
|
||||
makePointsCalcAndStep(coords) {
|
||||
let users = this.refs.gridControl.refs.userControl,
|
||||
activePlayer = users.state.activePlayer ? 'blue' : 'red',
|
||||
inactivePlayer = users.state.activePlayer ? 'red' : 'blue',
|
||||
redPoints = activePlayer === 'red'
|
||||
? users.refs[activePlayer].state.mines
|
||||
: users.refs[inactivePlayer].state.mines,
|
||||
bluePoints = activePlayer === 'blue'
|
||||
? users.refs[activePlayer].state.mines
|
||||
: users.refs[inactivePlayer].state.mines;
|
||||
|
||||
this.refs.gridControl.stepEvent(coords);
|
||||
|
||||
let mineCache = this.refs.gridControl.state.foundUserMineCache;
|
||||
redPoints += activePlayer === 'red' ? mineCache : 0;
|
||||
bluePoints += activePlayer === 'blue' ? mineCache : 0;
|
||||
|
||||
return {red: bluePoints, blue: redPoints};
|
||||
}
|
||||
|
||||
/** THE END */
|
||||
makeGameEndIfItEnds(bluePoints, redPoints) {
|
||||
var redWins = redPoints > 2,
|
||||
@@ -129,13 +150,12 @@ class MineSeeker extends React.Component {
|
||||
console.warn('Opponent stepped: Auto-Step process');
|
||||
|
||||
this.refs.gridControl.refs.userControl.setState({bombSelected: payload.data.bomb});
|
||||
this.refs.gridControl.stepEvent(payload.data.coords);
|
||||
|
||||
/** STEP */
|
||||
let points = this.makePointsCalcAndStep(payload.data.coords);
|
||||
|
||||
/** THE END */
|
||||
this.makeGameEndIfItEnds(
|
||||
this.refs.gridControl.refs.userControl.refs.blue.state.mines,
|
||||
this.refs.gridControl.refs.userControl.refs.red.state.mines
|
||||
);
|
||||
this.makeGameEndIfItEnds(points.blue, points.red);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -202,30 +222,19 @@ class MineSeeker extends React.Component {
|
||||
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
|
||||
);
|
||||
/** STEP */
|
||||
let points = this.makePointsCalcAndStep(coords);
|
||||
|
||||
/** THE END */
|
||||
this.makeGameEndIfItEnds(bluePoints, redPoints);
|
||||
this.makeGameEndIfItEnds(points.blue, points.red);
|
||||
|
||||
this.state.session
|
||||
.publish(this.state.channel, {
|
||||
'coords': coords,
|
||||
'player': activePlayer,
|
||||
'bomb': this.refs.gridControl.refs.userControl.state.bombSelected,
|
||||
'redPoints': redPoints,
|
||||
'bluePoints': bluePoints
|
||||
'redPoints': points.red,
|
||||
'bluePoints': points.blue
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user