diff --git a/src/Mine/SeekerBundle/Entity/Grid.php~ b/src/Mine/SeekerBundle/Entity/Grid.php~ index a47b1a8..f731f53 100644 --- a/src/Mine/SeekerBundle/Entity/Grid.php~ +++ b/src/Mine/SeekerBundle/Entity/Grid.php~ @@ -3,6 +3,7 @@ namespace Mine\SeekerBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** @@ -78,4 +79,38 @@ class Grid { return $this->playedGame; } + + /** + * Add gridRow + * + * @param GridRow $gridRow + * + * @return Grid + */ + public function addGridRow(GridRow $gridRow) + { + $this->gridRow[] = $gridRow; + + return $this; + } + + /** + * Remove gridRow + * + * @param GridRow $gridRow + */ + public function removeGridRow(GridRow $gridRow) + { + $this->gridRow->removeElement($gridRow); + } + + /** + * Get gridRow + * + * @return Collection + */ + public function getGridRow() + { + return $this->gridRow; + } } diff --git a/src/Mine/SeekerBundle/Entity/PlayedGame.php b/src/Mine/SeekerBundle/Entity/PlayedGame.php index 95ad7b0..97193f7 100644 --- a/src/Mine/SeekerBundle/Entity/PlayedGame.php +++ b/src/Mine/SeekerBundle/Entity/PlayedGame.php @@ -87,16 +87,23 @@ class PlayedGame /** * @var boolean * - * @ORM\Column(name="red_has_bomb", nullable=true) + * @ORM\Column(name="red_exploded_bomb", type="boolean", nullable=true) */ - private $redHasBomb; + private $redExplodedBomb; /** * @var boolean * - * @ORM\Column(name="blue_has_bomb", nullable=true) + * @ORM\Column(name="blue_exploded_bomb", type="boolean", nullable=true) */ - private $blueHasBomb; + private $blueExplodedBomb; + + /** + * @var string + * + * @ORM\Column(name="resign", type="string", length=7, nullable=true) + */ + private $resign; /** * @var Step @@ -125,6 +132,30 @@ class PlayedGame return $this->id; } + /** + * Set gameAssoc + * + * @param string $gameAssoc + * + * @return PlayedGame + */ + public function setGameAssoc($gameAssoc) + { + $this->gameAssoc = $gameAssoc; + + return $this; + } + + /** + * Get gameAssoc + * + * @return string + */ + public function getGameAssoc() + { + return $this->gameAssoc; + } + /** * Set redPoints * @@ -174,51 +205,51 @@ class PlayedGame } /** - * Set redHasBomb + * Set redExplodedBomb * - * @param string $redHasBomb + * @param string $redExplodedBomb * * @return PlayedGame */ - public function setRedHasBomb($redHasBomb) + public function setRedExplodedBomb($redExplodedBomb) { - $this->redHasBomb = $redHasBomb; + $this->redExplodedBomb = $redExplodedBomb; return $this; } /** - * Get redHasBomb + * Get redExplodedBomb * * @return string */ - public function getRedHasBomb() + public function getRedExplodedBomb() { - return $this->redHasBomb; + return $this->redExplodedBomb; } /** - * Set blueHasBomb + * Set blueExplodedBomb * - * @param string $blueHasBomb + * @param string $blueExplodedBomb * * @return PlayedGame */ - public function setBlueHasBomb($blueHasBomb) + public function setBlueExplodedBomb($blueExplodedBomb) { - $this->blueHasBomb = $blueHasBomb; + $this->blueExplodedBomb = $blueExplodedBomb; return $this; } /** - * Get blueHasBomb + * Get blueExplodedBomb * * @return string */ - public function getBlueHasBomb() + public function getBlueExplodedBomb() { - return $this->blueHasBomb; + return $this->blueExplodedBomb; } /** @@ -376,26 +407,26 @@ class PlayedGame } /** - * Set gameAssoc + * Set resign * - * @param string $gameAssoc + * @param string $resign * * @return PlayedGame */ - public function setGameAssoc($gameAssoc) + public function setResign($resign) { - $this->gameAssoc = $gameAssoc; + $this->resign = $resign; return $this; } /** - * Get gameAssoc + * Get resign * * @return string */ - public function getGameAssoc() + public function getResign() { - return $this->gameAssoc; + return $this->resign; } } diff --git a/src/Mine/SeekerBundle/Entity/PlayedGame.php~ b/src/Mine/SeekerBundle/Entity/PlayedGame.php~ index 95ad7b0..e987d2f 100644 --- a/src/Mine/SeekerBundle/Entity/PlayedGame.php~ +++ b/src/Mine/SeekerBundle/Entity/PlayedGame.php~ @@ -87,16 +87,23 @@ class PlayedGame /** * @var boolean * - * @ORM\Column(name="red_has_bomb", nullable=true) + * @ORM\Column(name="red_exploded_bomb", type="boolean", nullable=true) */ - private $redHasBomb; + private $redExplodedBomb; /** * @var boolean * - * @ORM\Column(name="blue_has_bomb", nullable=true) + * @ORM\Column(name="blue_exploded_bomb", type="boolean", nullable=true) */ - private $blueHasBomb; + private $blueExplodedBomb; + + /** + * @var string + * + * @ORM\Column(name="resign", type="string", length=7, nullable=true) + */ + private $resign; /** * @var Step @@ -125,6 +132,30 @@ class PlayedGame return $this->id; } + /** + * Set gameAssoc + * + * @param string $gameAssoc + * + * @return PlayedGame + */ + public function setGameAssoc($gameAssoc) + { + $this->gameAssoc = $gameAssoc; + + return $this; + } + + /** + * Get gameAssoc + * + * @return string + */ + public function getGameAssoc() + { + return $this->gameAssoc; + } + /** * Set redPoints * @@ -174,51 +205,51 @@ class PlayedGame } /** - * Set redHasBomb + * Set redExplodedBomb * - * @param string $redHasBomb + * @param string $redExplodedBomb * * @return PlayedGame */ - public function setRedHasBomb($redHasBomb) + public function setRedExplodedBomb($redExplodedBomb) { - $this->redHasBomb = $redHasBomb; + $this->redExplodedBomb = $redExplodedBomb; return $this; } /** - * Get redHasBomb + * Get redExplodedBomb * * @return string */ - public function getRedHasBomb() + public function getRedExplodedBomb() { - return $this->redHasBomb; + return $this->redExplodedBomb; } /** - * Set blueHasBomb + * Set blueExplodedBomb * - * @param string $blueHasBomb + * @param string $blueExplodedBomb * * @return PlayedGame */ - public function setBlueHasBomb($blueHasBomb) + public function setBlueExplodedBomb($blueExplodedBomb) { - $this->blueHasBomb = $blueHasBomb; + $this->blueExplodedBomb = $blueExplodedBomb; return $this; } /** - * Get blueHasBomb + * Get blueExplodedBomb * * @return string */ - public function getBlueHasBomb() + public function getBlueExplodedBomb() { - return $this->blueHasBomb; + return $this->blueExplodedBomb; } /** @@ -374,28 +405,4 @@ class PlayedGame { return $this->step; } - - /** - * Set gameAssoc - * - * @param string $gameAssoc - * - * @return PlayedGame - */ - public function setGameAssoc($gameAssoc) - { - $this->gameAssoc = $gameAssoc; - - return $this; - } - - /** - * Get gameAssoc - * - * @return string - */ - public function getGameAssoc() - { - return $this->gameAssoc; - } } diff --git a/src/Mine/SeekerBundle/Resources/public/css/style.mineseeker.css b/src/Mine/SeekerBundle/Resources/public/css/style.mineseeker.css index 1729519..ae59b1d 100644 --- a/src/Mine/SeekerBundle/Resources/public/css/style.mineseeker.css +++ b/src/Mine/SeekerBundle/Resources/public/css/style.mineseeker.css @@ -143,11 +143,13 @@ main { #mine-wrapper .game-wrapper .game-overlay .game-overlay-window a { background: #d8e3ea; - display: table; + display: inline-table; text-decoration: none; color: #126aa2; padding: 10px 50px; - margin: 0 auto; + margin: 0 2.5px; + + cursor: pointer; -webkit-border-radius: 3px; border-radius: 3px; 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 16cdebc..f201d41 100644 --- a/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/app.js +++ b/src/Mine/SeekerBundle/Resources/public/js/mine-seeker/app.js @@ -46,22 +46,24 @@ class MineSeeker extends React.Component { redPoints += activePlayer === 'red' ? mineCache : 0; bluePoints += activePlayer === 'blue' ? mineCache : 0; - return {red: bluePoints, blue: redPoints}; + return {red: redPoints, blue: bluePoints}; } /** THE END */ - makeGameEndIfItEnds(bluePoints, redPoints) { + makeGameEndIfItEnds(bluePoints, redPoints, resign = false) { var redWins = redPoints > 2, blueWins = bluePoints > 2; - if (redWins || blueWins) { + if (redWins || blueWins || resign) { this.refs.gridControl.state.sound.won.play(); - this.refs.gridControl.setState({ - overlay: true, - overlayTitle: (redWins ? 'Red' : 'Blue') + " wins the game!", - overlaySubTitle: "Play again!" - }); + if (false === resign) { + this.refs.gridControl.setState({ + overlay: true, + overlayTitle: (redWins ? 'Red' : 'Blue') + " wins the game!", + overlaySubTitle: "Play again!" + }); + } this.refs.gridControl.showLeftMines(); @@ -71,6 +73,51 @@ class MineSeeker extends React.Component { } } + resignProcess(color) { + this.refs.gridControl.setState({ + overlay: true, + overlayTitle: color === this.refs.gridControl.state.webPlayer + ? "You have been give up" + : "Your opponent has been resigned", + overlaySubTitle: color === this.refs.gridControl.state.webPlayer + ? "You LOSE!" + : "You WIN!" + }); + + this.makeGameEndIfItEnds(0, 0, true); + } + + clickResign() { + this.state.session + .publish(this.state.channel, { + 'resign': this.refs.gridControl.refs.userControl.state.activePlayer ? 'blue' : 'red' + }); + this.resignProcess(this.refs.gridControl.state.webPlayer); + } + + clickResignCancel() { + this.refs.gridControl.setState({ + overlay: false + }); + } + + /** RESIGN */ + resign() { + let users = this.refs.gridControl.refs.userControl, + activePlayer = users.state.activePlayer ? 'blue' : 'red'; + + if (this.refs.gridControl.state.webPlayer === activePlayer) { + this.refs.gridControl.setState({ + overlay: true, + overlayTitle: "Are u sure u want to resign?!", + overlaySubTitle:
+ }); + } + } + /** after rendering */ componentDidMount() { /** Create Websocket w/ Bahnhof.js */ @@ -143,19 +190,25 @@ class MineSeeker extends React.Component { isNotUnsubscribe = typeof payload.msg === 'undefined'; if (isTopicEvent) { - console.warn(payload.user + " has been stepped to coords: " + payload.data.coords[0] + ', ' + payload.data.coords[1]); /** Auto-Step if this player is not the current user */ if (this.refs.gridControl.state.webPlayer !== payload.data.player) { - console.warn('Opponent stepped: Auto-Step process'); + if (null === payload.data.resign) { + console.warn(payload.user + " has been stepped to coords: " + payload.data.coords[0] + ', ' + payload.data.coords[1]); + console.warn('Opponent stepped: Auto-Step process'); - this.refs.gridControl.refs.userControl.setState({bombSelected: payload.data.bomb}); + this.refs.gridControl.refs.userControl.setState({bombSelected: payload.data.bomb}); - /** STEP */ - let points = this.makePointsCalcAndStep(payload.data.coords); + /** STEP */ + let points = this.makePointsCalcAndStep(payload.data.coords); - /** THE END */ - this.makeGameEndIfItEnds(points.blue, points.red); + /** THE END */ + this.makeGameEndIfItEnds(points.blue, points.red); + } else { + /** RESIGN */ + /** THE END */ + this.resignProcess(payload.data.resign); + } } } else { @@ -235,7 +288,10 @@ class MineSeeker extends React.Component { 'player': activePlayer, 'bomb': this.refs.gridControl.refs.userControl.state.bombSelected, 'redPoints': points.red, - 'bluePoints': points.blue + 'bluePoints': points.blue, + 'resign': null, + 'redExplodedBomb': activePlayer === 'red' && this.refs.gridControl.refs.userControl.state.bombSelected, + 'blueExplodedBomb': activePlayer === 'blue' && this.refs.gridControl.refs.userControl.state.bombSelected }); } } @@ -245,6 +301,7 @@ class MineSeeker extends React.Component { return (