private function parseOptions(array &$data)
 {
     $viewData = array();
     foreach ($this->possibleStartRegions as $id_option_type => $option_types) {
         $optionType = ModelOptionType::getOptionType($id_option_type);
         foreach ($option_types as $option_number => $options) {
             $optionViewData = array();
             $optionViewData['number'] = $option_number;
             $optionViewData['countrySelectUnitCount'] = $optionType->getUnits();
             $optionViewData['countrySelectCount'] = $optionType->getCountries();
             $optionViewData['areas'] = array();
             foreach ($options as $id_area => $startRegion) {
                 // get area infos
                 $areaModel = ModelArea::getArea($id_area);
                 $area = array();
                 $area['id_area'] = $id_area;
                 $area['number'] = $areaModel->getNumber();
                 $area['name'] = $areaModel->getName();
                 // check if country already selected
                 $gameArea = ModelGameArea::getGameAreaForArea(ModelGame::getCurrentGame()->getId(), $id_area);
                 $id_zarea = $gameArea->getId();
                 $modelMove = ModelSelectStartMove::getSelectStartMoveForUser(ModelUser::getCurrentUser()->getId(), ModelGame::getCurrentGame()->getId());
                 if ($modelMove->checkIfAreaIsSelected($option_number, $id_zarea)) {
                     $area['checked'] = true;
                 }
                 $optionViewData['areas'][] = $area;
             }
             $viewData[] = $optionViewData;
         }
     }
     $data['options'] = $viewData;
 }
Пример #2
0
 public function run(array &$data)
 {
     $data['template'] = $this->getTemplate();
     $this->addCurrentGameInfo($data);
     $this->moveController = new SetShipsController(ModelUser::getCurrentUser()->getId(), ModelGame::getCurrentGame()->getId());
     // update moves
     if (isset($_POST['setship'])) {
         $this->setShip($data);
     }
     if (isset($_POST['fixate_start'])) {
         $this->fixateMove($data);
     }
     if (isset($_POST['delete'])) {
         $this->deleteMove($data);
     }
     // show already set ships
     $data['currentShips'] = array();
     $iterator = ModelSetShipsMove::getSetShipMovesForUser(ModelUser::getCurrentUser()->getId(), ModelGame::getCurrentGame()->getId());
     while ($iterator->hasNext()) {
         /** @var ModelSetShipsMove $move */
         $move = $iterator->next();
         $zShip = ModelInGameShip::getShipById(ModelGame::getCurrentGame()->getId(), $move->getIdZunit());
         $id_ship = $zShip->getIdUnit();
         $ship = ModelShip::getModelById($id_ship);
         $zAreaInPort = ModelGameArea::getGameArea(ModelGame::getCurrentGame()->getId(), $move->getIdZareaInPort());
         $zAreaAtSea = ModelGameArea::getGameArea(ModelGame::getCurrentGame()->getId(), $move->getIdZarea());
         $data['currentShips'][] = array('id' => $move->getId(), 'ship_type' => $ship->getName(), 'ship_name' => $zShip->getName(), 'zarea_in_port' => $zAreaInPort->getName() . ' ' . $zAreaInPort->getNumber(), 'zarea_at_sea' => $zAreaAtSea->getName() . ' ' . $zAreaAtSea->getNumber());
     }
     // show still available ships
     $data['availableShips'] = array();
     $stillAvailableShips = $this->moveController->getStillAvailableShips();
     foreach ($stillAvailableShips as $id_unit => $count) {
         if ($count <= 0) {
             continue;
         }
         $data['availableShips'][] = array('id' => $id_unit, 'count' => $count, 'name' => ModelShip::getModelById($id_unit)->getName());
     }
     // show available countries
     $data['availableZAreasInPort'] = array();
     $data['availableZAreasAtSea'] = array();
     $iterator = ModelGameArea::iterator(ModelUser::getCurrentUser()->getId(), ModelGame::getCurrentGame()->getId());
     while ($iterator->hasNext()) {
         /** @var ModelGameArea $zArea */
         $zArea = $iterator->next();
         $data['availableZAreasInPort'][] = array('id_zarea_in_port' => $zArea->getId(), 'name' => $zArea->getName(), 'number' => $zArea->getNumber());
     }
     $iterator = ModelArea::iterator(TYPE_SEA);
     while ($iterator->hasNext()) {
         /** @var ModelArea $area */
         $area = $iterator->next();
         $data['availableZAreasAtSea'][] = array('id_zarea_at_sea' => ModelGameArea::getGameAreaForArea(ModelGame::getCurrentGame()->getId(), $area->getId())->getId(), 'name' => $area->getName(), 'number' => $area->getNumber());
     }
     $this->checkFixate($data, PHASE_SETSHIPS);
     $this->checkCurrentPhase($data, PHASE_SETSHIPS);
 }
Пример #3
0
 private function showNewMove(array &$data)
 {
     $startAreas = array();
     $destinationAreas = array();
     $areas = ModelArea::iterator(TYPE_LAND);
     while ($areas->hasNext()) {
         /* @var $area ModelArea */
         $area = $areas->next();
         $zArea = ModelGameArea::getGameAreaForArea(ModelGame::getCurrentGame()->getId(), $area->getId());
         $areaViewData = array();
         $areaViewData['id_zarea'] = $zArea->getId();
         $areaViewData['number'] = $area->getNumber();
         $areaViewData['name'] = $area->getName();
         if ($zArea->getIdUser() === ModelUser::getCurrentUser()->getId()) {
             $startAreas[] = $areaViewData;
         }
         $destinationAreas[] = $areaViewData;
     }
     $data['startAreas'] = $startAreas;
     $data['destinationAreas'] = $destinationAreas;
 }
Пример #4
0
 /**
  * @return array(int $id_adjacent_area)
  */
 public function getAdjecents()
 {
     $area = ModelArea::getArea($this->id_area);
     return $area->getAdjecents();
 }
 private function showNewMove(array &$data)
 {
     $areasViewData = array();
     $areas = ModelArea::iterator(TYPE_LAND);
     while ($areas->hasNext()) {
         /* @var $area ModelArea */
         $area = $areas->next();
         $zArea = ModelGameArea::getGameAreaForArea(ModelGame::getCurrentGame()->getId(), $area->getId());
         $areaViewData = array();
         $areaViewData['id_zarea'] = $zArea->getId();
         $areaViewData['number'] = $area->getNumber();
         $areaViewData['name'] = $area->getName();
         if ($zArea->getIdUser() === ModelUser::getCurrentUser()->getId()) {
             $areasViewData[] = $areaViewData;
         }
     }
     $data['areas'] = $areasViewData;
     $unitsViewData = array();
     $unit_iter = ModelLandUnit::iterator();
     while ($unit_iter->hasNext()) {
         /* @var $unit ModelLandUnit */
         $unit = $unit_iter->next();
         $unitsViewData[] = array('id' => $unit->getId(), 'name' => $unit->getName());
     }
     $data['units'] = $unitsViewData;
 }
Пример #6
0
 /**
  * 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;
 }