예제 #1
0
  @Test
  public void testKing() {
    Board b = new Board(true);
    Piece water = new Piece(false, b, 2, 2, "bomb");
    Piece fire = new Piece(true, b, 1, 1, "pawn");
    Piece fire2 = new Piece(true, b, 2, 6, "shield");
    b.place(water, 2, 2);
    b.place(fire, 1, 1);
    b.place(fire2, 2, 6);

    assertEquals(false, water.isKing());
    assertEquals(false, fire2.isKing());
    assertEquals(fire, b.pieceAt(1, 1));

    fire2.move(3, 7);
    assertEquals(true, fire2.isKing());
    assertEquals(true, fire2.isFire());
    assertEquals(fire2, b.pieceAt(3, 7));

    water.move(0, 0);
    assertEquals(true, water.isKing());
    assertEquals(true, fire2.isKing());
    assertEquals(null, b.pieceAt(1, 1));
    assertEquals(null, b.pieceAt(0, 0));

    b.select(3, 7);
    assertEquals(true, b.canSelect(4, 6)); // fire can now move down
    assertEquals(false, b.canSelect(4, 8)); // out of bounds
  }
예제 #2
0
  @Test
  public void testWinner() {
    Board b = new Board(true);
    Piece water = new Piece(false, b, 2, 2, "bomb");
    Piece fire = new Piece(true, b, 1, 1, "pawn");
    Piece water2 = new Piece(false, b, 2, 2, "shield");

    b.place(water, 2, 2);
    b.place(fire, 1, 1);
    assertEquals(null, b.winner());

    water.move(0, 0);
    assertEquals("No one", b.winner());

    b.place(fire, 1, 1);
    b.place(water2, 2, 2);
    assertEquals(null, b.winner());
    fire.move(3, 3);
    assertEquals("fire", b.winner());

    Piece water3 = new Piece(false, b, 4, 4, "pawn");
    b.place(water3, 4, 4);
    assertEquals(null, b.winner());
    water3.move(2, 2);
    assertEquals("water", b.winner());
  }
예제 #3
0
  @Test
  public void testBombandShield() {
    Board b = new Board(true);
    Piece fire = new Piece(true, b, 5, 5, "bomb");
    Piece water = new Piece(false, b, 4, 6, "shield");
    Piece water2 = new Piece(false, b, 2, 6, "pawn");
    b.place(fire, 5, 5);
    b.place(water, 4, 6);
    b.place(water2, 2, 6);

    fire.move(3, 7);
    assertEquals(null, b.pieceAt(4, 7));
    assertEquals(null, b.pieceAt(3, 6));
    assertEquals(null, b.pieceAt(5, 6));

    fire = new Piece(true, b, 4, 4, "bomb");
    water = new Piece(false, b, 3, 5, "shield");
    water2 = new Piece(false, b, 3, 7, "pawn");
    Piece water3 = new Piece(false, b, 1, 7, "pawn");
    Piece water4 = new Piece(false, b, 1, 5, "bomb");

    b.place(fire, 4, 4);
    b.place(water, 3, 5);
    b.place(water2, 3, 7);
    b.place(water3, 1, 7);
    b.place(water4, 1, 5);
    fire.move(2, 6);

    assertEquals(null, b.pieceAt(3, 5));
    assertEquals(null, b.pieceAt(3, 7));
    assertEquals(null, b.pieceAt(1, 7));
    assertEquals(null, b.pieceAt(1, 5));
  }
예제 #4
0
  @Test
  public void testMoveandCapture() {
    Board b = new Board(true);
    Piece fire = new Piece(true, b, 0, 0, "pawn");
    Piece water = new Piece(false, b, 1, 1, "pawn");
    Piece water2 = new Piece(false, b, 3, 3, "pawn");

    b.place(fire, 0, 0);
    b.place(water, 1, 1);
    b.place(water2, 3, 3);

    fire.move(2, 2);
    assertEquals(true, fire.hasCaptured());
    assertEquals(fire, b.pieceAt(2, 2));
    assertEquals(null, b.pieceAt(1, 1));

    fire.move(4, 4);
    assertEquals(true, fire.hasCaptured());
    assertEquals(fire, b.pieceAt(4, 4));
    assertEquals(null, b.pieceAt(3, 3));
  }
예제 #5
0
  @Test
  public void testPieces() {
    Board b = new Board(true);
    Piece fire = new Piece(true, b, 0, 0, "pawn");
    Piece water = new Piece(false, b, 1, 1, "shield");
    assertEquals(true, fire.isFire());
    assertEquals(false, water.isFire());

    assertEquals(false, fire.isShield());
    assertEquals(true, water.isShield());
    assertEquals(false, fire.isBomb());
    assertEquals(false, water.isBomb());

    assertEquals(0, fire.side());
    assertEquals(1, water.side());

    Piece fire2 = new Piece(true, b, 6, 6, "bomb"); // move makes it a king, not place
    b.place(fire2, 6, 6);
    fire2.move(7, 7);
    assertEquals(true, fire2.isKing());
    assertEquals(false, water.isKing());
  }