Commit 96d83998 authored by Xuhao Lin's avatar Xuhao Lin
Browse files

Merge branch 'develop' of https://gitlab.utc.fr/qdruault/lo23-project into IHM-Main/secondinteg

parents d5ec1683 820ea067
......@@ -10,6 +10,7 @@ import com.utclo23.data.structure.Mine;
import com.utclo23.data.structure.StatGame;
import com.utclo23.com.messages.*;
import com.utclo23.data.facade.IDataCom;
import com.utclo23.data.structure.Game;
import com.utclo23.data.structure.LightPublicUser;
import java.net.Inet4Address;
import java.net.InterfaceAddress;
......@@ -122,11 +123,12 @@ public class ComFacade {
*
* @param game is the new created game
*/
public void notifyNewGame(StatGame game) {
public void notifyNewGame(StatGame game) {
M_CreationGame m_creationgame = new M_CreationGame(iDataCom.getMyPublicUserProfile(), game);
for (Inet4Address ip : kIpCtrl.getHashMap().values()) {
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), m_creationgame);
new Thread(os).start();
Thread thread = new Thread(os);
thread.start();
}
}
......@@ -214,16 +216,18 @@ public class ComFacade {
* @param id is the UID of the player demanding to join the game
* @param game is the game in question
*/
public void joinGameResponse(boolean success, String id, StatGame game) {
public void joinGameResponse(boolean success, String id, Game game) {
M_JoinGameResponse m_joingameresponse = new M_JoinGameResponse(iDataCom.getMyPublicUserProfile(), success, game);
if (success) {
for (Inet4Address ip : kIpCtrl.getHashMap().values()) {
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), m_joingameresponse);
new Thread(os).start();
System.out.println("send success joinGame");
}
} else {
Sender os = new Sender(kIpCtrl.getHashMap().get(id).getHostAddress(), kIpCtrl.getPort(), m_joingameresponse);
new Thread(os).start();
System.out.println("fail joinGame");
}
}
}
......@@ -57,7 +57,7 @@ public class Receiver implements Runnable {
request.callback(iDataCom);
break;
}*/
System.out.println("message received" + request.getClass().toString());
client.close();
in.close();
......
......@@ -50,7 +50,7 @@ public class Sender implements Runnable {
out = new ObjectOutputStream(socket.getOutputStream());
request.setIpSender(kIpCtrl.getMyInetAddress());
out.writeObject(request);
System.out.println("message sent" + request.getClass().toString());
System.out.println("message sent" + request.getClass().toString());
out.close();
socket.close();
} catch (UnknownHostException e) {}
......
......@@ -7,6 +7,7 @@ package com.utclo23.com.messages;
import com.utclo23.data.facade.IDataCom;
import com.utclo23.data.module.DataException;
import com.utclo23.data.structure.Game;
import com.utclo23.data.structure.PublicUser;
import com.utclo23.data.structure.StatGame;
import java.util.logging.Level;
......@@ -22,7 +23,7 @@ import java.util.logging.Logger;
public class M_JoinGameResponse extends Message {
private final boolean success;
private final StatGame game;
private final Game game;
/**
* Constructor.
......@@ -30,7 +31,7 @@ public class M_JoinGameResponse extends Message {
* @param user is the message's sender
* @param success is the response
*/
public M_JoinGameResponse(PublicUser user, boolean success, StatGame game) {
public M_JoinGameResponse(PublicUser user, boolean success, Game game) {
super(user);
this.success = success;
this.game = game;
......@@ -40,7 +41,7 @@ public class M_JoinGameResponse extends Message {
public void callback(IDataCom iDataCom) {
if (success) {
try {
iDataCom.receptionGame(game.getRealGame());
iDataCom.receptionGame(game);
} catch (DataException ex) {
Logger.getLogger(M_JoinGameResponse.class.getName()).log(Level.SEVERE, null, ex);
}
......
......@@ -93,8 +93,11 @@ public class GameMediator {
//to Com : notify a new game
ComFacade comFacade = this.dataFacade.getComfacade();
if (comFacade != null && game != null) {
System.out.println("notify");
comFacade.notifyNewGame(game.getStatGame());
}
else System.out.println("no notify");
//set current game
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Création d'un Game");
......@@ -306,11 +309,11 @@ public class GameMediator {
System.out.println("add role "+role);
System.out.println("add Urole "+role);
this.getCurrentGame().addUser(user, role);
if (this.dataFacade.getComfacade() != null) {
this.dataFacade.getComfacade().joinGameResponse(true, id, this.currentGame.getStatGame());
this.dataFacade.getComfacade().joinGameResponse(true, user.getId(), this.currentGame);
}
} else {
......
......@@ -17,6 +17,10 @@ public class BelgianGame extends Game {
public BelgianGame(StatGame statGame, List<Player> players, List<LightPublicUser> spectators, List<Message> messages) {
super(statGame, players, spectators, messages);
}
/**
......
......@@ -19,6 +19,7 @@ public class ClassicGame extends Game{
public ClassicGame(StatGame statGame, List<Player> players, List<LightPublicUser> spectators, List<Message> messages) {
super(statGame, players, spectators, messages);
}
......
......@@ -35,10 +35,9 @@ public abstract class Game extends SerializableEntity {
private Player currentPlayer;
public Game(StatGame statGame, List<Player> players, List<LightPublicUser> spectators, List<Message> messages) {
public Game(StatGame statGame, List<Player> players, List<LightPublicUser> spectators, List<Message> messages) {
this.statGame = statGame;
statGame.setRealGame(this);
this.players = players;
this.spectators = spectators;
......@@ -48,6 +47,8 @@ public abstract class Game extends SerializableEntity {
this.currentPlayer = players.get(0);
/* creation of caretaker */
this.caretaker = new Caretaker();
}
/**
......@@ -69,24 +70,24 @@ public abstract class Game extends SerializableEntity {
System.out.println("players == null");
}
if(this.players.size() == 1) {
if(this.players.size() <= 1) {
Player player = new Player(user);
this.players.add(player);
System.out.println("player "+player.getLightPublicUser().getId());
} else
} /*else
{
throw new DataException("Data : already two players in this "
+ "game, you can not add another one.");
}
}*/
} else if(role.equals("spectator")) {
this.spectators.add(user);
System.out.println("spectator "+user.getId());
} else {
throw new DataException("Data : given role is not known.");
}
......
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