Private
Public Access
1
0

bugfix points saving and exploded bombs to db && you can resign #6

This commit is contained in:
2016-11-20 17:44:29 +01:00
parent 180c827380
commit 5a3ce73e40
8 changed files with 242 additions and 87 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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();
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: <div className="resign">
<a onClick={this.clickResign.bind(this)}>Yes</a>
<a onClick={this.clickResignCancel.bind(this)}>No!</a>
</div>
});
}
}
/** after rendering */
componentDidMount() {
/** Create Websocket w/ Bahnhof.js */
@@ -143,10 +190,11 @@ 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) {
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});
@@ -156,6 +204,11 @@ class MineSeeker extends React.Component {
/** 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 (
<GridControl ref="gridControl"
env={this.props.env === 'dev'}
resign={this.resign.bind(this)}
onClick={this.onClick.bind(this)}/>
);
}

View File

@@ -429,6 +429,7 @@ class GridControl extends React.Component {
</div>
</div>
<UserControl ref="userControl"
resign={this.props.resign}
webPlayer={this.state.webPlayer}
bombClear={this.bombClear.bind(this)}/>
<div className="grid-container">

View File

@@ -66,7 +66,7 @@ class UserControl extends React.Component {
webPlayer={this.props.webPlayer}
active={this.state.activePlayer === 0}
onClickBombSelector={this.onClickBombSelector.bind(this, 0)}/>
<button className={this.getResignClass(this.props.webPlayer)}>
<button className={this.getResignClass(this.props.webPlayer)} onClick={this.props.resign}>
<div className="resign-shine"></div>
Resign
</button>

View File

@@ -101,7 +101,11 @@ class MineseekerTopic implements TopicInterface
$userName = is_string($user) ? $user : $user->getUsername();
/** Save every step by user to db */
if (null === $event['resign']) {
$this->saveStepToDb($topic, $event);
} else {
$this->saveResignToDb($topic, $event['resign']);
}
$topic->broadcast([
'userTopicId' => $connection->resourceId,
@@ -122,6 +126,22 @@ class MineseekerTopic implements TopicInterface
return 'mineseeker.topic';
}
/**
* Save Resign event to database
*/
private function saveResignToDb($topic, $color)
{
$gameAssoc = explode('/', $topic->getId())[2];
$playedGame = $this->em
->getRepository('MineSeekerBundle:PlayedGame')
->findOneByGameAssoc($gameAssoc);
$playedGame->setResign($color);
$this->em->persist($playedGame);
$this->em->flush();
}
/**
* Save steps and point information to database
*
@@ -146,6 +166,8 @@ class MineseekerTopic implements TopicInterface
$playedGame->setBluePoints($event['bluePoints']);
$playedGame->setRedPoints($event['redPoints']);
$playedGame->setBlueExplodedBomb($event['blueExplodedBomb'] ? true : null);
$playedGame->setRedExplodedBomb($event['redExplodedBomb'] ? true : null);
$this->em->persist($playedGame);
$this->em->flush();