Exemplo n.º 1
0
 private void walk(DecoratedRobot dr)
 {
     Point currentPosition = getRobotBoardCoordinates(dr);
     Point destinationPosition = getRelativeCoordinate(currentPosition, dr.getHeading());
     if (!isPointOnBoard(destinationPosition)) {
         board[currentPosition.X, currentPosition.Y] = null;
         robotIndex.Remove(dr);
         simulatorWindow.log(dr.getName() + " fell off the board!");
     } else if (isPositionEmpty(destinationPosition)) {
         board[currentPosition.X, currentPosition.Y] = null;
         board[destinationPosition.X, destinationPosition.Y] = dr;
     }
 }
Exemplo n.º 2
0
 private RobotLookEvent look(DecoratedRobot dr)
 {
     Point p = getRelativeCoordinate(getRobotBoardCoordinates(dr),dr.getHeading());
     int distance = 1;
     while (isPointOnBoard(p)) {
         SimulationActor sa = board[p.X, p.Y];
         if (sa == null) {
             p = getRelativeCoordinate(p, dr.getHeading());
             distance++;
             continue;
         }
         switch (sa.getType()) {
             case SimulationActor.Type.ROBOT:
                 return new RobotLookEvent(RobotLookEvent.ContactType.ROBOT, distance);
             default:
                 return new RobotLookEvent(RobotLookEvent.ContactType.SOMETHING, distance);
         }
     }
     return new RobotLookEvent(RobotLookEvent.ContactType.EDGE, distance);
 }
Exemplo n.º 3
0
 private void turn(DecoratedRobot dr, RobotAction ra)
 {
     RobotTurnAction rta = (RobotTurnAction)ra;
     dr.setHeading(getNewHeading(dr.getHeading(),rta.getDirection()));
 }
Exemplo n.º 4
0
 private RobotKillEvent kill(DecoratedRobot dr)
 {
     Point p = getRelativeCoordinate(getRobotBoardCoordinates(dr), dr.getHeading());
     SimulationActor target = board[p.X, p.Y];
     if (target != null && (target.getType() == SimulationActor.Type.ROBOT)) {
         DecoratedRobot victim = (DecoratedRobot)target;
         removeRobotFromSimulation(victim);
         simulatorWindow.log(dr.getName() + " killed " + victim.getName());
         return new RobotKillEvent();
     }
     return null;
 }