示例#1
0
文件: Rover.php 项目: gryzz/catawiki
 /**
  * Executes instructions.
  *
  * @throws ImpossibleMoveException
  * @throws UnknownInstructionException
  */
 public function executeInstructions()
 {
     foreach ($this->instructions as $instruction) {
         if (in_array($instruction, $this->allowedActions)) {
             if (!$this->plateau->isMovePossible($this->xPosition, $this->yPosition, $this->orientation)) {
                 throw new ImpossibleMoveException('Move is not possible - new position is out of the grid.');
             }
             list($newXCoordinate, $newYCoordinate) = $this->plateau->move($this->xPosition, $this->yPosition, $this->orientation);
             $this->xPosition = $newXCoordinate;
             $this->yPosition = $newYCoordinate;
         } elseif (in_array($instruction, $this->allowedTurnDirections)) {
             $this->orientation = $this->plateau->turn($this->orientation, $instruction);
         } else {
             throw new UnknownInstructionException('Unknown instruction.');
         }
     }
 }
示例#2
0
 /**
  * @expectedException CoordinatesOutOfGridException
  */
 public function testMoveException()
 {
     $plateau = new Plateau(5, 5);
     $plateau->move(10, 10, Plateau::NORTH);
 }