/** * @inheritDoc */ public function parse($line) { // seperate components $line = trim($line); $components = explode(' ', $line); // designator switch ($components[0]) { case 'settings': return \Mastercoding\Conquest\Command\SettingParser::parse($line); case 'setup_map': return \Mastercoding\Conquest\Command\SetupMapParser::parse($line); case 'go': return \Mastercoding\Conquest\Command\GoParser::parse($line); case 'info': return \Mastercoding\Conquest\Command\InfoParser::parse($line); case 'pick_starting_regions': return \Mastercoding\Conquest\Command\StartingRegions\Pick::create($components); case 'update_map': return \Mastercoding\Conquest\Command\UpdateMap\Update::create($components); case 'opponent_moves': return \Mastercoding\Conquest\Command\OpponentMoves\Moves::create($components); } return null; }
/** * Updates the map $map by processing the update map command * * @param \Mastercoding\Conquest\Object\Map $map * @param \Mastercoding\Conquest\Command\UpdateMap\Update $updateCommand */ public function updateMap(\Mastercoding\Conquest\Object\Map $map, \Mastercoding\Conquest\Command\UpdateMap\Update $updateCommand) { // loop updates foreach ($updateCommand->getUpdates() as $update) { // get region by id $region = $map->getRegionById($update['regionId']); $region->setArmies($update['armies']); // owner if ($update['owner'] == 'neutral') { $region->setOwner(new \Mastercoding\Conquest\Object\Owner\Neutral()); } else { foreach ($map->getPlayers() as $player) { if ($player->getName() == $update['owner']) { $region->setOwner($player); } } } } }