コード例 #1
0
  /** Create a table containing a half-full and completely full cell. */
  @Test
  public void Water_table_can_contain_standing_water() {
    List<Block> blocks = Collections.emptyList();
    LookupTable2D<Block> blockTable = new LookupTable2D<>(blocks, new Dimension(2, 2));

    HashMap<Position, Integer> waterAmounts = new HashMap<Position, Integer>();
    waterAmounts.put(new Position(0, 0), WaterUtil.HALF_CAPACITY);
    waterAmounts.put(new Position(1, 1), WaterUtil.MAX_CAPACITY);

    LookupTable2D<WaterRegion> waterTable =
        WaterRegionFactory.generateWaterTable(blockTable, waterAmounts);

    assertThat(waterTable.size, equalTo(blockTable.size));
    Set<CellularDirection> allDirs = Util.newSet(UP, LEFT, RIGHT, DOWN);
    // The cell at 0,0 should be half-full.
    assertThat(
        waterTable.getItemAt(0, 0),
        equalTo(new WaterRegion(0, 0, allDirs, MAX_CAPACITY, HALF_CAPACITY, false)));
    // These two cells should be empty.
    assertThat(waterTable.getItemAt(0, 1), equalTo(new WaterRegion(0, 1, allDirs, MAX_CAPACITY)));
    assertThat(waterTable.getItemAt(1, 0), equalTo(new WaterRegion(1, 0, allDirs, MAX_CAPACITY)));
    // The cell at 1,1 should be full.
    assertThat(
        waterTable.getItemAt(1, 1),
        equalTo(new WaterRegion(1, 1, allDirs, MAX_CAPACITY, MAX_CAPACITY, false)));
  }
コード例 #2
0
  /** Create a table containing a block and two ramps. Check the generated water table. */
  @Test
  public void Generate_water_table() {
    Block block = new Block(0, 0, Material.EARTH, Shape.FLAT, 0);
    Block leftRamp = new Block(0, 1, Material.EARTH, Shape.UP_LEFT, 0);
    Block rightRamp = new Block(1, 0, Material.EARTH, Shape.UP_RIGHT, 0);
    List<Block> blocks = Arrays.asList(block, leftRamp, rightRamp);
    LookupTable2D<Block> blockTable = new LookupTable2D<>(blocks, new Dimension(2, 2));

    LookupTable2D<WaterRegion> waterTable =
        WaterRegionFactory.generateWaterTable(blockTable, new HashMap<Position, Integer>());

    assertThat(waterTable.size, equalTo(blockTable.size));
    assertNull(waterTable.getItemAt(0, 0));
    assertThat(
        waterTable.getItemAt(0, 1),
        equalTo(new WaterRegion(0, 1, Util.newSet(UP, RIGHT), HALF_CAPACITY)));
    assertThat(
        waterTable.getItemAt(1, 0),
        equalTo(new WaterRegion(1, 0, Util.newSet(UP, LEFT), HALF_CAPACITY)));
    assertThat(
        waterTable.getItemAt(1, 1),
        equalTo(new WaterRegion(1, 1, Util.newSet(UP, LEFT, RIGHT, DOWN), MAX_CAPACITY)));

    // Also check the perimeter.
    for (int i = -1; i <= 2; i++) {
      assertThat(
          waterTable.getItemAt(-1, i),
          equalTo(new WaterRegion(-1, i, Util.newSet(UP, LEFT, RIGHT, DOWN), MAX_CAPACITY)));
      assertThat(
          waterTable.getItemAt(i, -1),
          equalTo(new WaterRegion(i, -1, Util.newSet(UP, LEFT, RIGHT, DOWN), MAX_CAPACITY)));
      assertThat(
          waterTable.getItemAt(i, 2),
          equalTo(new WaterRegion(i, 2, Util.newSet(UP, LEFT, RIGHT, DOWN), MAX_CAPACITY)));
      assertThat(
          waterTable.getItemAt(2, i),
          equalTo(new WaterRegion(2, i, Util.newSet(UP, LEFT, RIGHT, DOWN), MAX_CAPACITY)));
    }
  }