['status' => 1], 'm' => ['status' => 1, 'message' => 'Тут может быть ваша реклама!'], ]; public function __construct(MapData $mapData, $force = null) { $this->map = $mapData->getMap(); Player::start([$mapData->getStartx(), $mapData->getStarty()], $force); } private function canMoveTo($x, $y): bool { return $x >= 0 && $y >= 0 && !empty($this->map[$y][$x]) && !empty(self::ALLOWED_PATH_MARKS[$this->map[$y][$x]]) && self::ALLOWED_PATH_MARKS[$this->map[$y][$x]]['status'] === 1; } private function mapImage(int $x, int $y): string { if ($x < 0 || $y < 0 || empty($this->map[$y][$x])) { return '../resources/img/end.png'; } return '../resources/img/' . $this->map[$y][$x] . '.png'; } public function goUp() { if ($this->canMoveTo(Player::getPos()[0], Player::getPos()[1] - 1)) { Player::modYPos(-1); } } public function goDown() { if ($this->canMoveTo(Player::getPos()[0], Player::getPos()[1] + 1)) { Player::modYPos(+1); } } public function goLeft() { if ($this->canMoveTo(Player::getPos()[0] - 1, Player::getPos()[1])) { Player::modXPos(-1); } } public function goRight() { if ($this->canMoveTo(Player::getPos()[0] + 1, Player::getPos()[1])) { Player::modXPos(+1); } } public function drawVisible(int $radius = 2): string { $x_last = Player::getPos()[0] + $radius; $y = Player::getPos()[1] - $radius; $y_last = Player::getPos()[1] + $radius; $message = !empty(self::ALLOWED_PATH_MARKS[$this->map[Player::getPos()[1]][Player::getPos()[0]]]['message']) ? self::ALLOWED_PATH_MARKS[$this->map[Player::getPos()[1]][Player::getPos()[0]]]['message'] : ''; $str = ''; $str .= ''; $str .= ""; while ($y <= $y_last) { $str .= ''; $x = Player::getPos()[0] - $radius; while ($x <= $x_last) { $mapImage = $this->mapImage($x, $y); if ($x === Player::getPos()[0] && $y === Player::getPos()[1]) { $str .= "'; $x++; } $str .= ''; $y++; } $str .= '
Некий остров
$message
"; $str .= 'player'; } else { $str .= ''; $str .= "mapsqare"; } $str .= '
'; return $str; } }