Private
Public Access
1
0

bugfix points problem in the end #16

This commit is contained in:
2016-11-20 11:53:41 +01:00
parent c2b10d202a
commit 4c99df0b40

View File

@@ -28,6 +28,27 @@ class MineSeeker extends React.Component {
return text; 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 */ /** THE END */
makeGameEndIfItEnds(bluePoints, redPoints) { makeGameEndIfItEnds(bluePoints, redPoints) {
var redWins = redPoints > 2, var redWins = redPoints > 2,
@@ -129,13 +150,12 @@ class MineSeeker extends React.Component {
console.warn('Opponent stepped: Auto-Step process'); console.warn('Opponent stepped: Auto-Step process');
this.refs.gridControl.refs.userControl.setState({bombSelected: payload.data.bomb}); 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 */ /** THE END */
this.makeGameEndIfItEnds( this.makeGameEndIfItEnds(points.blue, points.red);
this.refs.gridControl.refs.userControl.refs.blue.state.mines,
this.refs.gridControl.refs.userControl.refs.red.state.mines
);
} }
} else { } else {
@@ -202,30 +222,19 @@ class MineSeeker extends React.Component {
if (this.refs.gridControl.checkFieldHasBeenNeverClicked(coords[0], coords[1])) { if (this.refs.gridControl.checkFieldHasBeenNeverClicked(coords[0], coords[1])) {
/** Player step and it is the current player */ /** Player step and it is the current player */
if (activePlayer === this.refs.gridControl.state.webPlayer) { if (activePlayer === this.refs.gridControl.state.webPlayer) {
this.refs.gridControl.stepEvent(coords); /** STEP */
let points = this.makePointsCalcAndStep(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
);
/** THE END */ /** THE END */
this.makeGameEndIfItEnds(bluePoints, redPoints); this.makeGameEndIfItEnds(points.blue, points.red);
this.state.session this.state.session
.publish(this.state.channel, { .publish(this.state.channel, {
'coords': coords, 'coords': coords,
'player': activePlayer, 'player': activePlayer,
'bomb': this.refs.gridControl.refs.userControl.state.bombSelected, 'bomb': this.refs.gridControl.refs.userControl.state.bombSelected,
'redPoints': redPoints, 'redPoints': points.red,
'bluePoints': bluePoints 'bluePoints': points.blue
}); });
} }
} }