Commit 0006b9e1 authored by Peining's avatar Peining
Browse files

Merge branch 'ihm-main/develop' of https://gitlab.utc.fr/qdruault/lo23-project...

Merge branch 'ihm-main/develop' of https://gitlab.utc.fr/qdruault/lo23-project into ihm-main/develop
parents 197237c8 e7e09ea8
......@@ -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.");
}
......
......@@ -5,6 +5,7 @@
*/
package com.utclo23.ihmmain;
import com.utclo23.data.module.DataException;
import com.utclo23.ihmmain.constants.SceneName;
import com.utclo23.ihmmain.controller.AbstractController;
import com.utclo23.ihmmain.controller.PlayerProfileController;
......@@ -65,11 +66,11 @@ public class IHMMain {
} catch (FileNotFoundException ex) {
Logger.getLogger(PlayerListController.class.getName()).log(Level.SEVERE, null, ex);
}
//add onClose event handler which handle the event when user clicks X
//add onClose event handler which handle the event when user clics X
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent we) {
System.exit(0);
exit();
}
});
}
......@@ -176,4 +177,14 @@ public class IHMMain {
return scene;
}
public void exit(){
try{
facade.iDataIHMMain.signOut();
System.out.println("Logged out");
}catch (Exception e) {
//not displaying anything, the app is closing
}
System.exit(0);
}
}
......@@ -64,7 +64,7 @@ public class LoginController extends AbstractController{
*/
@FXML
private void exitAction(ActionEvent event){
System.exit(0);
getIhmmain().exit();
}
/**
......
......@@ -61,7 +61,7 @@ public class MenuController extends AbstractController{
@FXML
private void exit(ActionEvent event){
System.exit(0);
getIhmmain().exit();
}
@FXML
......
......@@ -35,10 +35,11 @@ import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Pane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
/**
* Object: display all info of player profile.
* Display user's own profile (writable)
* Display others profiles (read-only)
* Displays all info of player profile.
* Displays user's own profile (writable).
* Displays others profiles (read-only).
*
* @author Lipeining
*/
......@@ -75,6 +76,7 @@ public class PlayerProfileController extends AbstractController{
private void back(ActionEvent event) throws IOException{
getIhmmain().toMenu();
}
@FXML
private void toPlayerList(ActionEvent event) throws IOException{
getIhmmain().toPlayerList();
......@@ -87,6 +89,7 @@ public class PlayerProfileController extends AbstractController{
text = description.getText();
description.setText(text);
}
@FXML
private void closeEdit(KeyEvent event) throws IOException{
KeyCode code = event.getCode();
......@@ -94,26 +97,31 @@ public class PlayerProfileController extends AbstractController{
description.setEditable(false);
}
}
@FXML
private void editPlayerName(ActionEvent event) throws IOException{
attribut="PlayerName";
popup(attribut);
}
@FXML
private void editFirstName(ActionEvent event) throws IOException{
attribut="FirstName";
popup(attribut);
}
@FXML
private void editLastName(ActionEvent event) throws IOException{
attribut="LastName";
popup(attribut);
}
@FXML
private void editBirthday(ActionEvent event) throws IOException{
attribut="Birthday";
popup(attribut);
}
@FXML
private void editPassword(ActionEvent event) throws IOException{
attribut="Password";
......@@ -138,7 +146,6 @@ public class PlayerProfileController extends AbstractController{
* The content of pop-up is generated dynamically.
* For updating the birthday, the date picker replace the text field in pop-up.
* @param attribut:name of info that user would like to modify
* @throws IOException
*/
private void popup(String attribut) throws IOException{
final Stage primaryStage = getIhmmain().primaryStage;
......@@ -200,7 +207,7 @@ public class PlayerProfileController extends AbstractController{
popup.show();
}
/**
* This function is for receiving the profile of other player asked by user
* This method is for receiving the profile of other player asked by user.
* @param player: profile sent by Data for us to display
* @throws IOException
*/
......@@ -210,8 +217,9 @@ public class PlayerProfileController extends AbstractController{
other = player;
}
}
/**
* This function is for waiting the profile
* This method is for waiting the profile.
* As soon as receive the profile sent by Data, skip the loading and refresh the page.
* @throws IOException
*/
......@@ -287,7 +295,7 @@ public class PlayerProfileController extends AbstractController{
}
@Override
/**
* Initialize all the info of profile
* Initializes all the info of profile.
*/
public void refresh(){
if (!isOther){
......
......@@ -11,9 +11,9 @@ import javafx.scene.Node;
import javafx.scene.control.TextArea;
/**
* Object: Generate a pop-up to enter and to send new info to update player profile
* According to the label transformed by interface player profile, this controller will call
* the update function corresponding created by Data.
* Generates a pop-up to enter and to send new info to update player profile.
* According to the label transformed by interface player profile,
* this controller will call the update function corresponding created by Data.
*
* @author lipeining
*/
......
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