1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Vehsamrak\Terraformator\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
use Vehsamrak\Terraformator\Entity\Map; |
9
|
|
|
use Vehsamrak\Terraformator\LocationGenerator\LocationGenerator; |
10
|
|
|
use Vehsamrak\Terraformator\Service\MapTransformer; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Vehsamrak |
14
|
|
|
*/ |
15
|
|
|
class TerraformCommand extends Command |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
private const MAP_WIDTH = 60; |
19
|
|
|
private const MAP_HEIGHT = 30; |
20
|
|
|
|
21
|
|
|
/** @var LocationGenerator $locationGenerator */ |
22
|
|
|
private $locationGenerator; |
23
|
|
|
/** @var MapTransformer $mapTransformer */ |
24
|
|
|
private $mapTransformer; |
25
|
|
|
|
26
|
|
|
/** {@inheritDoc} */ |
27
|
2 |
|
public function __construct( |
28
|
|
|
$name = null, |
29
|
|
|
LocationGenerator $locationGenerator = null, |
30
|
|
|
MapTransformer $mapTransformer = null |
31
|
|
|
) { |
32
|
2 |
|
$this->mapTransformer = $mapTransformer ?? new MapTransformer(); |
33
|
2 |
|
$this->locationGenerator = $locationGenerator ?? new LocationGenerator(); |
34
|
2 |
|
parent::__construct($name = null); |
35
|
2 |
|
} |
36
|
|
|
|
37
|
|
|
/** {@inheritDoc} */ |
38
|
2 |
|
protected function configure() |
39
|
|
|
{ |
40
|
2 |
|
$this->setName('create'); |
41
|
2 |
|
$this->setDescription('Create new map'); |
42
|
2 |
|
$this->setHelp('This command allows you to create game map.');; |
43
|
2 |
|
} |
44
|
|
|
|
45
|
|
|
/** {@inheritDoc} */ |
46
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
47
|
|
|
{ |
48
|
2 |
|
$map = new Map(); |
49
|
|
|
|
50
|
2 |
|
for ($y = 1; $y <= self::MAP_HEIGHT; $y++) { |
51
|
2 |
|
for ($x = 1; $x <= self::MAP_WIDTH; $x++) { |
52
|
2 |
|
$location = $this->locationGenerator->generateLocation($map, $x, $y); |
53
|
2 |
|
$map->add($location); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
2 |
|
unset($x, $y); |
58
|
|
|
|
59
|
2 |
|
$stringMap = $this->mapTransformer->convertToString($map, self::MAP_WIDTH); |
60
|
|
|
|
61
|
2 |
|
$output->writeln($stringMap); |
62
|
2 |
|
} |
63
|
|
|
} |
64
|
|
|
|