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

@@ -101,7 +101,11 @@ class MineseekerTopic implements TopicInterface
$userName = is_string($user) ? $user : $user->getUsername();
/** Save every step by user to db */
$this->saveStepToDb($topic, $event);
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();