diff --git a/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/app.js b/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/app.js index 66261ca..590f42d 100644 --- a/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/app.js +++ b/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/app.js @@ -44,9 +44,7 @@ class MineSeeker extends React.Component { 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 }); + this.refs.gridControl.refs.userControl.setState({activePlayer: false}); } } @@ -92,9 +90,6 @@ class MineSeeker extends React.Component { renderGridFields: this.state.gameAssoc }); - /** setup the web player */ - this.refs.gridControl.state.webPlayer === null && this.refs.gridControl.setState({webPlayer: this.state.gameInherited ? 'blue' : 'red'}); - /** Connect - Subscribe */ this.state.session.subscribe( this.state.channel, @@ -127,17 +122,29 @@ class MineSeeker extends React.Component { (typeof payload.user !== 'undefined' ? payload.user : 'user') + " has been subscribed to the channel!" ); - /** remove overlay when every user has been came */ - this.refs.gridControl.setState({overlay: payload.userCnt < 2}); - - /** Set up player names w/ server data */ - this.refs.gridControl.refs.userControl.refs.red.setState({ - name: payload.users.red !== '' ? payload.users.red : payload.users.redAnon + /** setup the web player */ + null === this.refs.gridControl.state.webPlayer && this.refs.gridControl.setState({ + webPlayer: payload.user === payload.users.blue || payload.user === payload.users.blueAnon + ? 'blue' + : 'red' }); - this.refs.gridControl.refs.userControl.refs.blue.setState({ - name: payload.users.blue !== '' ? payload.users.blue : payload.users.blueAnon - }); + /** every user has been came */ + if (payload.userCnt === 2) { + /** every time the blue starts */ + this.refs.gridControl.refs.userControl.setState({activePlayer: 1}); + + /** Set up player names w/ server data */ + this.refs.gridControl.refs.userControl.refs.red.setState({ + name: payload.users.red !== '' ? payload.users.red : payload.users.redAnon + }); + + this.refs.gridControl.refs.userControl.refs.blue.setState({ + name: payload.users.blue !== '' ? payload.users.blue : payload.users.blueAnon + }); + + this.refs.gridControl.setState({overlay: false}); + } } else { console.info(payload.msg); diff --git a/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/user/user-control.js b/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/user/user-control.js index 75c1e27..a95e137 100644 --- a/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/user/user-control.js +++ b/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/user/user-control.js @@ -5,8 +5,12 @@ class UserControl extends React.Component { constructor() { super(); + /** + * activePlayer - red: 0, blue: 1 + * @type {{activePlayer: boolean, mines: number, bombSelected: boolean, foundMines: boolean}} + */ this.state = { - activePlayer: 0, // activePlayer - red: 0, blue: 1 + activePlayer: false, mines: 51, bombSelected: false, foundMines: false diff --git a/src/Mine/SeekerBundle/Topic/MineseekerTopic.php b/src/Mine/SeekerBundle/Topic/MineseekerTopic.php index 68a3e96..2d91662 100644 --- a/src/Mine/SeekerBundle/Topic/MineseekerTopic.php +++ b/src/Mine/SeekerBundle/Topic/MineseekerTopic.php @@ -173,7 +173,16 @@ class MineseekerTopic implements TopicInterface ->getRepository('JotunheimrUserBundle:User') ->findOneByUsername($userName); - $count == 1 ? $playedGame->setRed($FOSUser) : $playedGame->setBlue($FOSUser); + if ($count == 1) { + /** @var $random {integer} Active player: red: 0, blue: 1 */ + $random = rand(0, 1); + + !$random ? $playedGame->setRed($FOSUser) : $playedGame->setBlue($FOSUser); + } else { + null === $playedGame->getRed() && null === $playedGame->getRedAnon() + ? $playedGame->setRed($FOSUser) + : $playedGame->setBlue($FOSUser); + } } else { // $request = $this->requestStack->getCurrentRequest(); // TODO nem megy... @@ -181,7 +190,16 @@ class MineseekerTopic implements TopicInterface $anon->setUserName($userName); $this->em->persist($anon); - $count == 1 ? $playedGame->setRedAnon($anon) : $playedGame->setBlueAnon($anon); + if ($count == 1) { + /** @var $random {integer} Active player: red: 0, blue: 1 */ + $random = rand(0, 1); + + !$random ? $playedGame->setRedAnon($anon) : $playedGame->setBlueAnon($anon); + } else { + null === $playedGame->getRed() && null === $playedGame->getRedAnon() + ? $playedGame->setRedAnon($anon) + : $playedGame->setBlueAnon($anon); + } } $this->em->persist($playedGame);