Commit bc526707 authored by Quentin DRUAULT-AUBIN's avatar Quentin DRUAULT-AUBIN Committed by Paul Jeannot
Browse files

[Data][Com] Set ennemy ships

parent 1797cac1
......@@ -61,8 +61,10 @@ public class ComFacade {
public void sendShipsToEnnemy(List<Ship> listShips, List<LightPublicUser> recipients) {
M_PlaceShip mPlaceship = new M_PlaceShip(iDataCom.getMyPublicUserProfile(), listShips);
for (LightPublicUser recipient : recipients) {
Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceship);
new Thread(os).start();
if (kIpCtrl.getHashMap().get(recipient.getId()) != null) {
Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceship);
new Thread(os).start();
}
}
}
......
......@@ -246,7 +246,7 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
*/
@Override
public void setEnnemyShips(List<Ship> ships) {
//this.gameMediator.setEnnemyShips(ships);
this.gameMediator.setEnnemyShips(ships);
}
/**
......
......@@ -531,4 +531,35 @@ public class GameMediator {
return status;
}
public void setEnnemyShips(List<Ship> ships) {
// Check game is instanciated
if (this.currentGame != null){
if(!ships.isEmpty()){
// retrieve the id of the player that put the ships
String player_id = ships.get(0).getOwner().getLightPublicUser().getId();
// Retrieve the player that put the ships
Player p = this.currentGame.getPlayer(player_id);
// Set the ships
p.setShips(ships);
// If the 2 players are ready, notify IHM Table.
boolean ready = true;
for (Player player : currentGame.getPlayers()) {
// If their ships are placed.
if (this.currentGame.getTemplateShips().size() != player.getShips().size()) {
ready = false;
break;
}
}
if(ready) {
this.dataFacade.getIhmTablefacade().notifyGameReady();
}
}
}
}
}
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