Private
Public Access
1
0

bugfix changePlayer after bomb explosion

This commit is contained in:
2016-11-07 23:40:11 +01:00
parent d797012d51
commit b6076d082b

View File

@@ -156,7 +156,15 @@ class GridControl extends React.Component {
} }
/** set __ACTIVE__ player in the UserControl !!!! */ /** set __ACTIVE__ player in the UserControl !!!! */
changePlayer(userControl, activePlayer, inactivePlayer) { changePlayer(idx, max, currentObject) {
var userControl = this.refs.userControl,
activePlayer = userControl.state.activePlayer ? 'blue' : 'red',
inactivePlayer = userControl.state.activePlayer ? 'red' : 'blue';
if (
userControl.state.bombSelected && idx === (max - 1) ||
!idx && !userControl.state.bombSelected && currentObject !== 'm'
) {
userControl.setState({ userControl.setState({
activePlayer: userControl.state.activePlayer ? 0 : 1 activePlayer: userControl.state.activePlayer ? 0 : 1
}); });
@@ -169,6 +177,7 @@ class GridControl extends React.Component {
active: true active: true
}); });
} }
}
/** /**
* Show all fields that needed after click * Show all fields that needed after click
@@ -242,13 +251,6 @@ class GridControl extends React.Component {
? 'warning' ? 'warning'
: 'mine' : 'mine'
].play(); ].play();
/**
* TODO Csak az utolsó iterációnál kell usert váltani!! --> 10.)
*/
if (this.refs.userControl.state.bombSelected) {
this.changePlayer(userControl, activePlayer, inactivePlayer);
}
} }
/** set current image in field */ /** set current image in field */
@@ -258,13 +260,6 @@ class GridControl extends React.Component {
} else { } else {
this.state.sound.click.play(); this.state.sound.click.play();
/**
* TODO Csak az utolsó iterációnál kell usert váltani!! --> 10.)
*/
if (!justOnFirstIteration) {
this.changePlayer(userControl, activePlayer, inactivePlayer);
}
/** set current image in field - WHEN it is a number */ /** set current image in field - WHEN it is a number */
if (!isNaN(currentObject)) { if (!isNaN(currentObject)) {
gridFieldControl.setState({ gridFieldControl.setState({
@@ -301,10 +296,12 @@ class GridControl extends React.Component {
* @param row * @param row
* @param col * @param col
* @param idx * @param idx
* @param max
*/ */
show(row, col, idx = 0) { show(row, col, idx = 0, max = 0) {
this.handleGridField(this.state.grid[row][col], row, col, idx); this.handleGridField(this.state.grid[row][col], row, col, idx);
this.showAppropriateFields(this.refs[this.refString(row, col)], row, col); this.showAppropriateFields(this.refs[this.refString(row, col)], row, col);
this.changePlayer(idx, max, this.state.grid[row][col]);
} }
/** /**
@@ -324,7 +321,7 @@ class GridControl extends React.Component {
var bombRadius = this.getBombRadius(coords[0], coords[1]); var bombRadius = this.getBombRadius(coords[0], coords[1]);
for (var i = 0, j = bombRadius.length; i < j; i++) { for (var i = 0, j = bombRadius.length; i < j; i++) {
this.show(bombRadius[i][0], bombRadius[i][1], i); this.show(bombRadius[i][0], bombRadius[i][1], i, j);
} }
/** remove BOMB from activePlayer */ /** remove BOMB from activePlayer */