Commit f1ca34be authored by Gabrielle Spielmann's avatar Gabrielle Spielmann
Browse files

'test_for_endGame'

parent 8d259ca9
......@@ -165,4 +165,85 @@ public class AttackTest {
}
@org.junit.Test
public void testEndGame() throws DataException {
DataFacade df = new DataFacade();
df.setTestMode(true);
try {
df.createUser("Xiaodan", "123", "", "", new Date(), "");
} catch (Exception e) {
e.printStackTrace();
df.signin("Xiaodan", "123");
}
df.createGame("TestAttack", false, true, true, GameType.CLASSIC);
//Add another player
LightPublicUser lightPublicUserB = new LightPublicUser("456", "Toto");
df.getGameMediator().getCurrentGame().addUser(lightPublicUserB, "player");
//Coordinate of A's ship
Coordinate coorShipA11 = new Coordinate(1,1);
Coordinate coorShipA12 = new Coordinate(2,1);
Coordinate coorShipA13 = new Coordinate(3,1);
List<Coordinate> coordShipA1 = new ArrayList<>();
coordShipA1.add(coorShipA11);
coordShipA1.add(coorShipA12);
coordShipA1.add(coorShipA13);
//set A's ship
Player playerA = df.getGameMediator().getCurrentGame().getPlayer(df.getUserMediator().getMyPublicUserProfile().getId());
Player playerB = df.getGameMediator().getCurrentGame().ennemyOf(playerA);
Ship shipA1 = new Ship(ShipType.SUBMARINE, playerA, coordShipA1, 3);
List<Ship> shipsA = new ArrayList<>();
shipsA.add(shipA1);
playerA.setShips(shipsA);
//Coordinate of B's ship
Coordinate coorShipB11 = new Coordinate(11,2);
Coordinate coorShipB12 = new Coordinate(12,2);
Coordinate coorShipB13 = new Coordinate(13,2);
List<Coordinate> coordShipB1 = new ArrayList<>();
coordShipB1.add(coorShipB11);
coordShipB1.add(coorShipB12);
coordShipB1.add(coorShipB13);
//set B's ship
Ship shipB1 = new Ship(ShipType.SUBMARINE, playerB, coordShipB1, 3);
List<Ship> shipsB = new ArrayList<>();
shipsB.add(shipB1);
playerB.setShips(shipsB);
//Coordinate of A's mines
Coordinate coorMineA1 = new Coordinate(11,2);
Mine mineA1 = new Mine(playerA, coorMineA1);
Coordinate coorMineA2 = new Coordinate(12,2);
Mine mineA2 = new Mine(playerA, coorMineA2);
Coordinate coorMineA3 = new Coordinate(13,2);
Mine mineA3 = new Mine(playerA, coorMineA3);
//Coordinate of B's mines
Coordinate coorMineB1 = new Coordinate(1,1);
Mine mineB1 = new Mine(playerB, coorMineB1);
Coordinate coorMineB2 = new Coordinate(2,1);
Mine mineB2 = new Mine(playerB, coorMineB2);
Coordinate coorMineB3 = new Coordinate(3,1);
Mine mineB3 = new Mine(playerB, coorMineB3);
df.attack(coorMineA1, true);
df.forwardCoordinates(mineA1);
df.attack(coorMineB1, true);
df.forwardCoordinates(mineB1);
df.attack(coorMineA2, true);
df.forwardCoordinates(mineA2);
df.attack(coorMineB2, true);
df.forwardCoordinates(mineB2);
df.attack(coorMineA3, true);
boolean b = df.getGameMediator().getCurrentGame().isGameFinishedByEnnemy() ;
df.forwardCoordinates(mineA3);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment