pull/96/head
Gnieark 8 years ago
parent 072eb1e557
commit bc25495ed2

@ -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,

Loading…
Cancel
Save