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; } }
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); }
private void turn(DecoratedRobot dr, RobotAction ra) { RobotTurnAction rta = (RobotTurnAction)ra; dr.setHeading(getNewHeading(dr.getHeading(),rta.getDirection())); }
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; }