diff --git a/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/grid/grid-control.js b/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/grid/grid-control.js index 39c7ca7..29733dc 100644 --- a/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/grid/grid-control.js +++ b/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/grid/grid-control.js @@ -156,18 +156,27 @@ class GridControl extends React.Component { } /** set __ACTIVE__ player in the UserControl !!!! */ - changePlayer(userControl, activePlayer, inactivePlayer) { - userControl.setState({ - activePlayer: userControl.state.activePlayer ? 0 : 1 - }); + changePlayer(idx, max, currentObject) { + var userControl = this.refs.userControl, + activePlayer = userControl.state.activePlayer ? 'blue' : 'red', + inactivePlayer = userControl.state.activePlayer ? 'red' : 'blue'; - userControl.refs[activePlayer].setState({ - active: false - }); + if ( + userControl.state.bombSelected && idx === (max - 1) || + !idx && !userControl.state.bombSelected && currentObject !== 'm' + ) { + userControl.setState({ + activePlayer: userControl.state.activePlayer ? 0 : 1 + }); - userControl.refs[inactivePlayer].setState({ - active: true - }); + userControl.refs[activePlayer].setState({ + active: false + }); + + userControl.refs[inactivePlayer].setState({ + active: true + }); + } } /** @@ -242,13 +251,6 @@ class GridControl extends React.Component { ? 'warning' : 'mine' ].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 */ @@ -258,13 +260,6 @@ class GridControl extends React.Component { } else { 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 */ if (!isNaN(currentObject)) { gridFieldControl.setState({ @@ -301,10 +296,12 @@ class GridControl extends React.Component { * @param row * @param col * @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.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]); 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 */