Ejemplo n.º 1
0
    public static Set<TDCoordinate> getEffectedCoordinates() {

      int randomEntry = random.nextInt(30);

      int row = 0;
      int column = 0;

      if (randomEntry < Board.MAX_COLUMNS) {
        column = randomEntry;
      } else {
        column = randomEntry % Board.MAX_COLUMNS;
        row = randomEntry / Board.MAX_COLUMNS;
      }

      TDCoordinate randomCoordinate = TDCoordinate.newInstance(row, column);

      System.out.println(
          "Disaster Coordinate:("
              + randomCoordinate.getRow()
              + ","
              + randomCoordinate.getColumn()
              + ")");

      Set<TDCoordinate> coordinates = Sets.newHashSet();

      int towardsHorizontal = random.nextInt(3);
      int towardsVertical = random.nextInt(3);
      int maxVerticalCoordinates = random.nextInt(4) + 1;

      if (towardsHorizontal == 0) {
        // only left
        fillLeftVerticalThickness(
            row, column, coordinates, towardsVertical, maxVerticalCoordinates);
      }

      if (towardsHorizontal == 1) {

        fillRightVerticalThickness(
            row, column, coordinates, towardsVertical, maxVerticalCoordinates);
      }

      if (towardsHorizontal == 2) {

        fillLeftVerticalThickness(
            row, column, coordinates, towardsVertical, maxVerticalCoordinates / 2);

        fillRightVerticalThickness(
            row,
            column,
            coordinates,
            towardsVertical,
            maxVerticalCoordinates - maxVerticalCoordinates / 2);
      }

      return coordinates;
    }
Ejemplo n.º 2
0
 private static void getBottomCoordinates(
     TDCoordinate coordinate, int maxCoordinates, Set<TDCoordinate> coordinates) {
   int row = coordinate.getRow();
   int column = coordinate.getColumn();
   while (row < Board.MAX_ROWS && maxCoordinates > 0) {
     TDCoordinate c = TDCoordinate.newInstance(row, column);
     coordinates.add(c);
     row++;
     maxCoordinates--;
   }
 }
Ejemplo n.º 3
0
 private static void getTopCoordinates(
     TDCoordinate coordinate, int maxCoordinates, Set<TDCoordinate> coordinates) {
   int row = coordinate.getRow();
   int column = coordinate.getColumn();
   while (row >= 0 && maxCoordinates > 0) {
     TDCoordinate c = TDCoordinate.newInstance(row, column);
     coordinates.add(c);
     row--;
     maxCoordinates--;
   }
 }
Ejemplo n.º 4
0
 private static void fillLeftVerticalThickness(
     int row,
     int column,
     Set<TDCoordinate> coordinates,
     int towardsVertical,
     int maxVerticalCoordinates) {
   int verticalThickness = maxVerticalCoordinates;
   while (verticalThickness > 0 && column >= 0) {
     fillVerticalCoordinates(
         TDCoordinate.newInstance(row, column),
         coordinates,
         random.nextInt(maxVerticalCoordinates) + 1,
         towardsVertical);
     verticalThickness--;
     column--;
   }
 }