.
This commit is contained in:
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…
Reference in New Issue
Block a user