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

@@ -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,8 +122,17 @@ 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});
/** 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'
});
/** 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({
@@ -138,6 +142,9 @@ class MineSeeker extends React.Component {
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);

View File

@@ -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

View File

@@ -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);