| 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 | 14 | private function __construct(string $direction) |
|
| 37 | |||
| 38 | 14 | public static function north(): Direction |
|
| 42 | |||
| 43 | 3 | public static function south(): Direction |
|
| 47 | |||
| 48 | 4 | public static function east(): Direction |
|
| 52 | |||
| 53 | 4 | public static function west(): Direction |
|
| 57 | |||
| 58 | 5 | public function turnRight(): Direction |
|
| 62 | |||
| 63 | 5 | public function turnLeft(): Direction |
|
| 67 | |||
| 68 | 1 | public function direction(): string |
|
| 72 | } |
||
| 73 |