This commit is contained in:
Gnieark 2016-07-11 21:16:26 +02:00
parent 072eb1e557
commit bc25495ed2

View File

@ -1,4 +1,7 @@
<?php
class InvalidDirectionException extends UnexpectedValueException{
}
class Direction
{
private static $top = 0;
@ -27,6 +30,28 @@ class Direction
break;
}
}
public static function make($str){
$dir = new Direction();
switch((string)$str){
case "x+":
$dir->value = Direction::$right;
break;
case "x-":
$dir->value = Direction::$left;
break;
case "y+":
$dir->value = Direction::$top;
break;
case "y-":
$dir->value = Direction::$bottom;
break;
default:
throw new InvalidDirectionException("expected 'x+', 'x-', 'y+' or 'y-'". (string)$str."received.");
break;
}
return $dir;
}
public function opposite(){
$opposites = array(
Direction::$top => Direction::$bottom,