1 | <?php |
||
5 | final class Direction |
||
6 | { |
||
7 | public const NORTH = 'n'; |
||
8 | public const SOUTH = 's'; |
||
9 | public const EAST = 'e'; |
||
10 | public const WEST = 'w'; |
||
11 | |||
12 | public const DIRECTIONS = [ |
||
13 | self::NORTH => [ |
||
14 | 'right' => self::EAST, |
||
15 | 'left' => self::WEST |
||
16 | ], |
||
17 | self::EAST => [ |
||
18 | 'right' => self::SOUTH, |
||
19 | 'left' => self::NORTH |
||
20 | ], |
||
21 | self::SOUTH => [ |
||
22 | 'right' => self::WEST, |
||
23 | 'left' => self::EAST |
||
24 | ], |
||
25 | self::WEST => [ |
||
26 | 'right' => self::NORTH, |
||
27 | 'left' => self::SOUTH |
||
28 | ] |
||
29 | ]; |
||
30 | |||
31 | private $direction; |
||
32 | |||
33 | 21 | private function __construct(string $direction) |
|
37 | |||
38 | 21 | public static function north(): Direction |
|
42 | |||
43 | 8 | public static function south(): Direction |
|
47 | |||
48 | 7 | public static function east(): Direction |
|
52 | |||
53 | 6 | public static function west(): Direction |
|
57 | |||
58 | 11 | public function turnRight(): Direction |
|
62 | |||
63 | 7 | public function turnLeft(): Direction |
|
67 | |||
68 | 10 | public function direction(): string |
|
72 | |||
73 | 6 | public function inverseDirection(): Direction |
|
88 | |||
89 | 6 | private function equals(Direction $a_direction): bool |
|
97 | } |
||
98 |