-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovementOption.php
55 lines (45 loc) · 2.29 KB
/
MovementOption.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
class MovementOption
{
private string $direction;
private TileInterface $tile;
private string $currentDirection;
public function __construct(string $currentDirection, string $direction, TileInterface $tile) {
$this->direction = $direction;
$this->tile = $tile;
$this->currentDirection = $currentDirection;
}
public function getTile(): TileInterface
{
return $this->tile;
}
public function getDirection(): string
{
return $this->direction;
}
public function convertToInstruction(): string
{
if ($this->direction === $this->currentDirection) {
return 'V';
}
switch (true) {
case $this->direction === DirectionOfTravel::WEST && $this->currentDirection === DirectionOfTravel::NORTH:
case $this->direction === DirectionOfTravel::NORTH && $this->currentDirection === DirectionOfTravel::EAST:
case $this->direction === DirectionOfTravel::EAST && $this->currentDirection === DirectionOfTravel::SOUTH:
case $this->direction === DirectionOfTravel::SOUTH && $this->currentDirection === DirectionOfTravel::WEST:
return 'LV';
case $this->direction === DirectionOfTravel::EAST && $this->currentDirection === DirectionOfTravel::NORTH:
case $this->direction === DirectionOfTravel::SOUTH && $this->currentDirection === DirectionOfTravel::EAST:
case $this->direction === DirectionOfTravel::WEST && $this->currentDirection === DirectionOfTravel::SOUTH:
case $this->direction === DirectionOfTravel::NORTH && $this->currentDirection === DirectionOfTravel::WEST:
return 'RV';
case $this->direction === DirectionOfTravel::SOUTH && $this->currentDirection === DirectionOfTravel::NORTH:
case $this->direction === DirectionOfTravel::WEST && $this->currentDirection === DirectionOfTravel::EAST:
case $this->direction === DirectionOfTravel::NORTH && $this->currentDirection === DirectionOfTravel::SOUTH:
case $this->direction === DirectionOfTravel::EAST && $this->currentDirection === DirectionOfTravel::WEST:
return 'BV';
}
throw new RuntimeException('Cannot convert direction??');
}
}