/** * sets game status of a new game to GAME_STATUS_STARTED * * @return bool * @throws GameAdministrationException * @throws ModelException */ public function startGame() { if ($this->status !== GAME_STATUS_NEW) { throw new GameAdministrationException('Only new games can be started.'); } // allocate starting sets to users $iter_player = ModelIsInGameInfo::iterator(null, $this->id); $players = $iter_player->size(); $iter_sets = ModelStartingSet::iterator($players, true); while ($iter_player->hasNext()) { if (!$iter_sets->hasNext()) { throw new GameAdministrationException('Not enough starting sets found!'); } $iter_player->next()->setStartingSet($iter_sets->next()->getId()); } // allocate resources $iter_poor = ModelEconomy::iterator(ECONOMY_POOR); $iter_weak = ModelEconomy::iterator(ECONOMY_WEAK); $iter_normal = ModelEconomy::iterator(ECONOMY_NORMAL); $iter_strong = ModelEconomy::iterator(ECONOMY_STRONG); $iter_areas = ModelArea::iterator(TYPE_LAND); while ($iter_areas->hasNext()) { $_Area = $iter_areas->next(); switch ($_Area->getEconomy()) { case ECONOMY_POOR: $_Eco = $iter_poor->next(); break; case ECONOMY_WEAK: $_Eco = $iter_weak->next(); break; case ECONOMY_NORMAL: $_Eco = $iter_normal->next(); break; case ECONOMY_STRONG: $_Eco = $iter_strong->next(); break; default: throw new ModelException('Area with invalid eco type found: ' . $_Area->getId()); break; } ModelGameArea::setGameArea($this->id, 0, NEUTRAL_COUNTRY, $_Area->getId(), $_Eco->getIdResource(), $_Eco->getResPower()); } // create sea areas $iter_sea = ModelArea::iterator(TYPE_SEA); while ($iter_sea->hasNext()) { $_Area = $iter_sea->next(); ModelGameArea::setGameArea($this->id, 0, NEUTRAL_COUNTRY, $_Area->getId(), RESOURCE_NONE, 0); } // set game to started $this->setStatus(GAME_STATUS_STARTED); return true; }
/** * sets the starting set for the user * * @param $id_set int * @throws NullPointerException * @return void */ public function setStartingSet($id_set) { $id_set = intval($id_set); ModelStartingSet::getSet($id_set); $this->id_set = $id_set; DataSource::Singleton()->epp('set_starting_set_for_user', array(':id_user' => $this->id_user, ':id_game' => $this->id_game, ':id_set' => $this->id_set)); }