Commit e4bb8c7d authored by Thomas's avatar Thomas
Browse files

Added empty constructors in common datamodel objects, completed chat messages...

Added empty constructors in common datamodel objects, completed chat messages reception, fixed UUID comparison issue in Data module
parent 0c256650
package main.java.client.data;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import javafx.stage.Stage;
import main.java.common.dataModel.*;
import main.java.common.interfaces.client.IMainToData;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
......@@ -17,6 +11,17 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import javafx.stage.Stage;
import main.java.common.dataModel.GameHeavy;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.GameStatus;
import main.java.common.dataModel.UserHeavy;
import main.java.common.dataModel.UserLight;
import main.java.common.interfaces.client.IMainToData;
public class MainToDataImpl implements IMainToData {
DataCoreClient dataCoreClient;
......@@ -71,6 +76,7 @@ public class MainToDataImpl implements IMainToData {
Stage stageFx) {
GameLight gameCreated = new GameLight(UUID.randomUUID(), ul, null, GameStatus.PENDING, spectatorsOk, chatOk,
creatorPlayWhite, limitMove);
dataCoreClient.getDataToCom().addNewGameAvailable(gameCreated);
dataCoreClient.getDataToGame().getGameScreen(gameCreated, stageFx);
return stageFx;
}
......
package main.java.client.game.controller;
import java.text.SimpleDateFormat;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TabPane;
......@@ -9,8 +14,6 @@ import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import main.java.client.game.GameCore;
import main.java.common.dataModel.Message;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* IHM-Game main controller class.
......@@ -96,8 +99,11 @@ public class MainGameController {
*/
public void newMessageToHistory(Message m) {
LOGGER.debug("Message received -> " + m.getMessage());
areaChatHistory.appendText("-------\n");
areaChatHistory.appendText(m.getMessage());
String time = new SimpleDateFormat("HH:mm:ss").format(m.getHourMessage());
areaChatHistory.appendText("---- " + m.getAuthor().getPseudo() + " à " + time + " ----");
areaChatHistory.appendText("\n");
areaChatHistory.appendText("> " + m.getMessage());
areaChatHistory.appendText("\n");
}
/**
......
package main.java.client.game.model;
import java.io.IOException;
import java.util.UUID;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javafx.scene.Scene;
import javafx.stage.Stage;
import main.java.client.game.GameCore;
import main.java.common.dataModel.*;
import main.java.common.dataModel.Board;
import main.java.common.dataModel.GameHeavy;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Message;
import main.java.common.dataModel.UserLight;
import main.java.common.interfaces.client.IDataToGame;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.util.UUID;
public class DataToGameImpl implements IDataToGame {
/**
......
......@@ -7,6 +7,10 @@ public class Board {
private UUID game;
private int[][] state;
public Board() {
}
public Board(UUID game, int[][] state) {
this.game = game;
this.state = state;
......@@ -30,9 +34,6 @@ public class Board {
@Override
public String toString() {
return "Board{" +
"game=" + game +
", state=" + Arrays.toString(state) +
'}';
return "Board{" + "game=" + game + ", state=" + Arrays.toString(state) + '}';
}
}
......@@ -6,6 +6,10 @@ public class Chat {
private List<Message> chat;
private GameMeta game;
public Chat() {
}
public Chat(List<Message> chat, GameMeta game) {
this.chat = chat;
this.game = game;
......@@ -29,9 +33,6 @@ public class Chat {
@Override
public String toString() {
return "Chat{" +
"chat=" + chat +
", game=" + game +
'}';
return "Chat{" + "chat=" + chat + ", game=" + game + '}';
}
}
......@@ -11,7 +11,13 @@ public class GameHeavy extends GameMeta {
private UUID winner;
private List<UserZero> spectators;
public GameHeavy(UUID id, UserLight gameCreator, UserLight player2, GameStatus status, boolean isOkSpectators, boolean isOkChat, boolean isWhiteCreator, int limitMove, List<Move> moveList, Timestamp gameStart, Chat chat, UUID winner, List<UserZero> spectators) {
public GameHeavy() {
}
public GameHeavy(UUID id, UserLight gameCreator, UserLight player2, GameStatus status, boolean isOkSpectators,
boolean isOkChat, boolean isWhiteCreator, int limitMove, List<Move> moveList, Timestamp gameStart,
Chat chat, UUID winner, List<UserZero> spectators) {
super(id, gameCreator, player2, status, isOkSpectators, isOkChat, isWhiteCreator, limitMove);
this.moveList = moveList;
this.gameStart = gameStart;
......@@ -61,18 +67,13 @@ public class GameHeavy extends GameMeta {
}
public GameLight convertToGameLight() {
return new GameLight(this.getId(), this.getGameCreator(), this.getPlayer2(), this.getStatus(),
this.isOkSpectators(), this.isOkChat(), this.isWhiteCreator(), this.getLimitMove());
return new GameLight(getId(), getGameCreator(), getPlayer2(), getStatus(), isOkSpectators(), isOkChat(),
isWhiteCreator(), getLimitMove());
}
@Override
public String toString() {
return "GameHeavy{" +
"moveList=" + moveList +
", gameStart=" + gameStart +
", chat=" + chat +
", winner=" + winner +
", spectators=" + spectators +
'}';
return "GameHeavy{" + "moveList=" + moveList + ", gameStart=" + gameStart + ", chat=" + chat + ", winner="
+ winner + ", spectators=" + spectators + '}';
}
}
......@@ -4,7 +4,12 @@ import java.util.UUID;
public class GameLight extends GameMeta {
public GameLight(UUID id, UserLight gameCreator, UserLight player2, GameStatus status, boolean isOkSpectators, boolean isOkChat, boolean isWhiteCreator, int limitMove) {
public GameLight() {
super();
};
public GameLight(UUID id, UserLight gameCreator, UserLight player2, GameStatus status, boolean isOkSpectators,
boolean isOkChat, boolean isWhiteCreator, int limitMove) {
super(id, gameCreator, player2, status, isOkSpectators, isOkChat, isWhiteCreator, limitMove);
}
......
......@@ -12,7 +12,12 @@ abstract class GameMeta {
private boolean isWhiteCreator;
private int limitMove;
public GameMeta(UUID id, UserLight gameCreator, UserLight player2, GameStatus status, boolean isOkSpectators, boolean isOkChat, boolean isWhiteCreator, int limitMove) {
public GameMeta() {
}
public GameMeta(UUID id, UserLight gameCreator, UserLight player2, GameStatus status, boolean isOkSpectators,
boolean isOkChat, boolean isWhiteCreator, int limitMove) {
this.id = id;
this.gameCreator = gameCreator;
this.player2 = player2;
......@@ -89,15 +94,8 @@ abstract class GameMeta {
@Override
public String toString() {
return "GameMeta{" +
"id=" + id +
", gameCreator=" + gameCreator +
", player2=" + player2 +
", status=" + status +
", isOkSpectators=" + isOkSpectators +
", isOkChat=" + isOkChat +
", isWhiteCreator=" + isWhiteCreator +
", limitMove=" + limitMove +
'}';
return "GameMeta{" + "id=" + id + ", gameCreator=" + gameCreator + ", player2=" + player2 + ", status=" + status
+ ", isOkSpectators=" + isOkSpectators + ", isOkChat=" + isOkChat + ", isWhiteCreator=" + isWhiteCreator
+ ", limitMove=" + limitMove + '}';
}
}
package main.java.common.dataModel;
import java.sql.Timestamp;
public class Message {
......@@ -8,6 +7,10 @@ public class Message {
private String message;
private UserZero author;
public Message() {
}
public Message(Timestamp hourMessage, String message, UserZero author) {
this.hourMessage = hourMessage;
this.message = message;
......
......@@ -8,6 +8,10 @@ public class Move {
private int x;
private int y;
public Move() {
}
public Move(UserZero player, Timestamp hourMove, int x, int y) {
this.player = player;
this.hourMove = hourMove;
......@@ -49,11 +53,6 @@ public class Move {
@Override
public String toString() {
return "Move{" +
"player=" + player +
", hourMove=" + hourMove +
", x=" + x +
", y=" + y +
'}';
return "Move{" + "player=" + player + ", hourMove=" + hourMove + ", x=" + x + ", y=" + y + '}';
}
}
......@@ -9,7 +9,12 @@ public class UserHeavy extends UserMeta {
private String serverPort;
private List<GameHeavy> savedGames;
public UserHeavy(UUID id, String pseudo, String password, String serverAddress, String serverPort, List<GameHeavy> savedGames) {
public UserHeavy() {
super();
}
public UserHeavy(UUID id, String pseudo, String password, String serverAddress, String serverPort,
List<GameHeavy> savedGames) {
super(id, pseudo);
this.password = password;
this.serverAddress = serverAddress;
......@@ -51,11 +56,7 @@ public class UserHeavy extends UserMeta {
@Override
public String toString() {
return "UserHeavy{" +
"password='" + password + '\'' +
", serverAddress='" + serverAddress + '\'' +
", serverPort='" + serverPort + '\'' +
", savedGames=" + savedGames +
'}';
return "UserHeavy{" + "password='" + password + '\'' + ", serverAddress='" + serverAddress + '\''
+ ", serverPort='" + serverPort + '\'' + ", savedGames=" + savedGames + '}';
}
}
......@@ -11,7 +11,8 @@ public class UserLight extends UserMeta {
private int playedGames;
private int wonGames;
public UserLight(UUID id, String pseudo, String lastName, String firstName, Date dateOfBirth, int avatarId, int playedGames, int wonGames) {
public UserLight(UUID id, String pseudo, String lastName, String firstName, Date dateOfBirth, int avatarId,
int playedGames, int wonGames) {
super(id, pseudo);
this.lastName = lastName;
this.firstName = firstName;
......@@ -78,18 +79,13 @@ public class UserLight extends UserMeta {
}
public UserZero convertToUserZero() {
return new UserZero(this.getId(), this.getPseudo());
return new UserZero(getId(), getPseudo());
}
@Override
public String toString() {
return "UserLight{" +
"lastName='" + lastName + '\'' +
", firstName='" + firstName + '\'' +
", dateOfBirth=" + dateOfBirth +
", avatarId=" + avatarId +
", playedGames=" + playedGames +
", wonGames=" + wonGames +
'}';
return "UserLight{" + "lastName='" + lastName + '\'' + ", firstName='" + firstName + '\'' + ", dateOfBirth="
+ dateOfBirth + ", avatarId=" + avatarId + ", playedGames=" + playedGames + ", wonGames=" + wonGames
+ '}';
}
}
......@@ -32,9 +32,6 @@ abstract class UserMeta {
@Override
public String toString() {
return "UserMeta{" +
"id=" + id +
", pseudo='" + pseudo + '\'' +
'}';
return "UserMeta{" + "id=" + id + ", pseudo='" + pseudo + '\'' + '}';
}
}
......@@ -3,6 +3,10 @@ package main.java.common.dataModel;
import java.util.UUID;
public class UserZero extends UserMeta {
public UserZero() {
super();
}
public UserZero(UUID id, String pseudo) {
super(id, pseudo);
}
......
package main.java.server.data;
import main.java.common.dataModel.*;
import main.java.common.interfaces.server.IComToData;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.UUID;
import main.java.common.dataModel.Chat;
import main.java.common.dataModel.GameHeavy;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Message;
import main.java.common.dataModel.Move;
import main.java.common.dataModel.UserLight;
import main.java.common.dataModel.UserZero;
import main.java.common.interfaces.server.IComToData;
public class ComToDataServerImpl implements IComToData {
DataCoreServer dataCoreServer;
......@@ -28,10 +34,11 @@ public class ComToDataServerImpl implements IComToData {
@Override
public void createGame(GameLight gameLight) {
GameHeavy newGame = new GameHeavy(gameLight.getId(), gameLight.getGameCreator(), gameLight.getPlayer2(), gameLight.getStatus(),
gameLight.isOkSpectators(), gameLight.isOkChat(), gameLight.isWhiteCreator(), gameLight.getLimitMove(),
new ArrayList<Move>(), null, gameLight.isOkChat() ? new Chat(new ArrayList<Message>(), gameLight) : null,
null, gameLight.isOkSpectators() ? new ArrayList<UserZero>() : null);
GameHeavy newGame = new GameHeavy(gameLight.getId(), gameLight.getGameCreator(), gameLight.getPlayer2(),
gameLight.getStatus(), gameLight.isOkSpectators(), gameLight.isOkChat(), gameLight.isWhiteCreator(),
gameLight.getLimitMove(), new ArrayList<Move>(), null,
gameLight.isOkChat() ? new Chat(new ArrayList<Message>(), gameLight) : null, null,
gameLight.isOkSpectators() ? new ArrayList<UserZero>() : null);
dataCoreServer.getListGameHeavy().add(newGame);
dataCoreServer.getDataToCom().notifyNewGame(gameLight);
}
......@@ -47,23 +54,24 @@ public class ComToDataServerImpl implements IComToData {
boolean gameFound = false;
while (itGame.hasNext() && !gameFound) {
GameHeavy currentGame = itGame.next();
if (currentGame.getId() == gameID) {
if (currentGame.getId().equals(gameID)) {
gameFound = true;
currentGame.getChat().getChat().add(newMessage);
}
}
if (!gameFound)
if (!gameFound) {
throw new Exception("Game not found");
}
}
@Override
public ArrayList<UUID> getAllGameParticipants(UUID gameID) throws Exception {
ArrayList<UUID> gameParticipants = new ArrayList<UUID>();
ArrayList<UUID> gameParticipants = new ArrayList<>();
ListIterator<GameHeavy> itGame = dataCoreServer.getListGameHeavy().listIterator();
boolean gameFound = false;
while (itGame.hasNext() && !gameFound) {
GameHeavy currentGame = itGame.next();
if (currentGame.getId() == gameID) {
if (currentGame.getId().equals(gameID)) {
gameFound = true;
gameParticipants.add(currentGame.getGameCreator().getId());
gameParticipants.add(currentGame.getPlayer2().getId());
......@@ -72,8 +80,9 @@ public class ComToDataServerImpl implements IComToData {
}
}
}
if (!gameFound)
throw new Exception("Game not found");
if (!gameFound) {
throw new Exception("Game not found 2");
}
return gameParticipants;
}
......@@ -97,8 +106,9 @@ public class ComToDataServerImpl implements IComToData {
return dataCoreServer.getListConnectedUsers();
}
@Override
public List<GameLight> getListGames() {
List<GameLight> listGameLight = new ArrayList<GameLight>();
List<GameLight> listGameLight = new ArrayList<>();
for (GameHeavy gameHeavy : dataCoreServer.getListGameHeavy()) {
listGameLight.add(gameHeavy.convertToGameLight());
}
......@@ -111,12 +121,13 @@ public class ComToDataServerImpl implements IComToData {
boolean found = false;
int index = 0;
while (it.hasNext() && !found) {
if (it.next().getId() == userModified.getId())
if (it.next().getId() == userModified.getId()) {
found = true;
else
} else {
index++;
}
}
dataCoreServer.getListConnectedUsers().set(index, userModified);
//dataCoreServer.getDataToCom().notifyListUserChange(); TO DISCUSS WITH COM
// dataCoreServer.getDataToCom().notifyListUserChange(); TO DISCUSS WITH COM
}
}
Markdown is supported
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