Private
Public Access
1
0

random player on start #5

This commit is contained in:
2016-11-19 15:45:52 +01:00
parent 2cb38f2681
commit 47627edca8
3 changed files with 47 additions and 18 deletions

View File

@@ -45,8 +45,6 @@ class MineSeeker extends React.Component {
this.refs.gridControl.showLeftMines(); this.refs.gridControl.showLeftMines();
this.refs.gridControl.refs.userControl.setState({activePlayer: false}); 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 });
} }
} }
@@ -92,9 +90,6 @@ class MineSeeker extends React.Component {
renderGridFields: this.state.gameAssoc 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 */ /** Connect - Subscribe */
this.state.session.subscribe( this.state.session.subscribe(
this.state.channel, this.state.channel,
@@ -127,8 +122,17 @@ class MineSeeker extends React.Component {
(typeof payload.user !== 'undefined' ? payload.user : 'user') + " has been subscribed to the channel!" (typeof payload.user !== 'undefined' ? payload.user : 'user') + " has been subscribed to the channel!"
); );
/** remove overlay when every user has been came */ /** setup the web player */
this.refs.gridControl.setState({overlay: payload.userCnt < 2}); null === this.refs.gridControl.state.webPlayer && this.refs.gridControl.setState({
webPlayer: payload.user === payload.users.blue || payload.user === payload.users.blueAnon
? 'blue'
: 'red'
});
/** 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 */ /** Set up player names w/ server data */
this.refs.gridControl.refs.userControl.refs.red.setState({ this.refs.gridControl.refs.userControl.refs.red.setState({
@@ -138,6 +142,9 @@ class MineSeeker extends React.Component {
this.refs.gridControl.refs.userControl.refs.blue.setState({ this.refs.gridControl.refs.userControl.refs.blue.setState({
name: payload.users.blue !== '' ? payload.users.blue : payload.users.blueAnon name: payload.users.blue !== '' ? payload.users.blue : payload.users.blueAnon
}); });
this.refs.gridControl.setState({overlay: false});
}
} else { } else {
console.info(payload.msg); console.info(payload.msg);

View File

@@ -5,8 +5,12 @@ class UserControl extends React.Component {
constructor() { constructor() {
super(); super();
/**
* activePlayer - red: 0, blue: 1
* @type {{activePlayer: boolean, mines: number, bombSelected: boolean, foundMines: boolean}}
*/
this.state = { this.state = {
activePlayer: 0, // activePlayer - red: 0, blue: 1 activePlayer: false,
mines: 51, mines: 51,
bombSelected: false, bombSelected: false,
foundMines: false foundMines: false

View File

@@ -173,7 +173,16 @@ class MineseekerTopic implements TopicInterface
->getRepository('JotunheimrUserBundle:User') ->getRepository('JotunheimrUserBundle:User')
->findOneByUsername($userName); ->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 { } else {
// $request = $this->requestStack->getCurrentRequest(); // TODO nem megy... // $request = $this->requestStack->getCurrentRequest(); // TODO nem megy...
@@ -181,7 +190,16 @@ class MineseekerTopic implements TopicInterface
$anon->setUserName($userName); $anon->setUserName($userName);
$this->em->persist($anon); $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); $this->em->persist($playedGame);