コード例 #1
0
 public function toJson()
 {
     $response = [];
     if ($this->hasWinner()) {
         $response = ['success' => true, 'contestant' => $this->contestant->getName(), 'time' => $this->getTime()];
     } else {
         $response = ['success' => false];
     }
     return json_encode($response);
 }
コード例 #2
0
ファイル: WampConnector.php プロジェクト: sky7sea/Jeopardy
 public function onContestantScoreUpdate(Contestant $contestant)
 {
     if (!array_key_exists(self::CONTESTANT_SCORE, $this->subscribedTopics)) {
         return;
     }
     $response = $contestant->toJson();
     $this->subscribedTopics[self::CONTESTANT_SCORE]->broadcast($response, [], []);
 }
コード例 #3
0
ファイル: Board.php プロジェクト: sky7sea/Jeopardy
 /**
  * @param Contestant $contestant
  * @param $value
  * @return Contestant
  */
 public function addScore(Contestant $contestant, $value)
 {
     /** @var Contestant $c */
     $c = $this->getContestants()->first(function ($key, Contestant $c) use($contestant) {
         return $c->getName() == $contestant->getName();
     });
     if ($c == null) {
         //TODO logging.
         echo "Unable to find contestant with name {$contestant->getName()}";
     }
     $c->addScore($value);
     return $contestant;
 }
コード例 #4
0
ファイル: Board.php プロジェクト: mattsches/Jeopardy
 /**
  * @param Contestant $contestant
  * @param            $value
  *
  * @return Contestant
  * @throws \Depotwarehouse\Jeopardy\Board\ContestantNotFoundException
  */
 public function addScore(Contestant $contestant, $value) : Contestant
 {
     /** @var Contestant $c */
     $c = $this->getContestants()->first(function (Contestant $c) use($contestant) {
         return $c->getName() === $contestant->getName();
     });
     if ($c === null) {
         //TODO logging.
         throw new ContestantNotFoundException("Unable to find contestant with name {$contestant->getName()}", 0, null, $this->getContestants());
     }
     $c->addScore($value);
     return $contestant;
 }