コード例 #1
0
  public boolean moveWest(Game game) {

    Player player = game.getPlayer();
    Location currentLocation = player.getLocation();
    Map map = game.getMap();

    if (currentLocation.getCol() == 0) {
      return false;
    }

    player.setLocation(map.getLocation(currentLocation.getRow(), currentLocation.getCol() - 1));

    return true;
  }
コード例 #2
0
  public boolean moveSouth(Game game) {

    Player player = game.getPlayer();
    Location currentLocation = player.getLocation();
    Map map = game.getMap();

    if (currentLocation.getRow() == Map.NUM_ROWS - 1) {
      return false;
    }

    player.setLocation(map.getLocation(currentLocation.getRow() + 1, currentLocation.getCol()));

    return true;
  }
コード例 #3
0
  public boolean moveNorth(Game game) {

    Player player = game.getPlayer();
    Location currentLocation = player.getLocation();
    Map map = game.getMap();

    if (currentLocation.getRow() == 0) {
      return false;
    }

    int currentCol = currentLocation.getCol();
    int currentRow = currentLocation.getRow();
    int newRow = currentRow - 1;

    Location newLocation = map.getLocation(newRow, currentCol);
    player.setLocation(newLocation);

    return true;
  }