Commit 75873824 authored by Peining's avatar Peining
Browse files

Merge branch 'develop' into ihm-main/develop

parents e7f55b4a 4d1f9a13
......@@ -284,7 +284,7 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
@Override
public void leaveGame() {
String role = this.gameMediator.getOwnerStatus();
if (!role.equals("spectator") && this.gameMediator.getCurrentGame()!=null) {
if (!role.equals("spectator") && this.gameMediator.getCurrentGame() != null) {
Logger.getLogger(DataFacade.class.getName()).log(Level.INFO, null, "data | leave game");
this.comfacade.leaveGame(this.gameMediator.getCurrentGame().getRecipients(this.getMyPublicUserProfile().getPlayerName()));
......@@ -308,7 +308,6 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
public void opponentHasLeftGame() {
Logger.getLogger(DataFacade.class.getName()).info("data | opponent has left");
if (!this.gameMediator.isFinishedGame()) {
try {
this.gameMediator.defWin();
......@@ -319,10 +318,9 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
this.ihmTablefacade.opponentHasLeftGame();
}
}
@Override
public void removeGame(String id)
{
public void removeGame(String id) {
this.gameMediator.removeGame(id);
}
......@@ -426,14 +424,16 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
public PublicUser getMyPublicUserProfile() {
PublicUser usr = this.userMediator.getMyPublicUserProfile();
try {
usr.setNumberDefeats(this.getNumberDefeats());
if (usr != null) {
try {
usr.setNumberDefeatsClassic(this.getNumberDefeatsClassic());
usr.setNumberVictories(this.getNumberVictories());
usr.setNumberAbandons(this.getNumberAbandons());
usr.setNumberVictoriesClassic(this.getNumberVictoriesClassic());
usr.setNumberAbandonsClassic(this.getNumberAbandonsClassic());
} catch (DataException ex) {
Logger.getLogger(DataFacade.class.getName()).log(Level.SEVERE, null, ex);
} catch (DataException ex) {
Logger.getLogger(DataFacade.class.getName()).log(Level.SEVERE, null, ex);
}
}
return usr;
......@@ -762,9 +762,12 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
* @return int number of victories
* @throws DataException
*/
@Override
public int getNumberVictories(GameType type) throws DataException {
return this.userMediator.getNumberVictories(type) ;
public int getNumberVictoriesClassic() throws DataException {
return this.userMediator.getNumberVictoriesClassic();
}
public int getNumberVictoriesBelgian() throws DataException {
return this.userMediator.getNumberVictoriesBelgian();
}
/**
......@@ -774,9 +777,12 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
* @return int number of defeats
* @throws DataException
*/
@Override
public int getNumberDefeats(GameType type) throws DataException {
return this.userMediator.getNumberDefeats(type) ;
public int getNumberDefeatsClassic() throws DataException {
return this.userMediator.getNumberDefeatsClassic();
}
public int getNumberDefeatsBelgian() throws DataException {
return this.userMediator.getNumberDefeatsBelgian();
}
/**
......@@ -786,8 +792,11 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
* @return int number of abandons
* @throws DataException
*/
@Override
public int getNumberAbandons(GameType type) throws DataException {
return this.userMediator.getNumberAbandons(type) ;
public int getNumberAbandonsClassic() throws DataException {
return this.userMediator.getNumberAbandonsClassic();
}
public int getNumberAbandonsBelgian() throws DataException {
return this.userMediator.getNumberAbandonsBelgian();
}
}
......@@ -164,8 +164,45 @@ public interface IDataIHMMain {
*/
public void updatePassword(String password) throws DataException;
public int getNumberVictories(GameType type) throws DataException;
public int getNumberDefeats(GameType type) throws DataException;
public int getNumberAbandons(GameType type) throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberVictoriesClassic() throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberDefeatsClassic() throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberAbandonsClassic() throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberVictoriesBelgian() throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberDefeatsBelgian() throws DataException;
/**
*
* @return
* @throws DataException
*/
public int getNumberAbandonsBelgian() throws DataException;
}
......@@ -783,17 +783,31 @@ public class UserMediator {
/**
*
* send number of victories
* send number of victories:mode classical
*
* @return int number of victories
*/
public int getNumberVictories(GameType type) throws DataException {
public int getNumberVictoriesClassic() {
if(this.owner != null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbVictories = 0;
for (StatGame g : games) {
if ((g.getType() == type) && (g.getWinner() == user) && !(g.isGameAbandonned())) {
if ((g.getType() == GameType.CLASSIC) && (g.getWinner() == user) && !(g.isGameAbandonned())) {
nbVictories++ ;
}
}
return nbVictories ;
}
return 0;
}
public int getNumberVictoriesBelgian() {
if(this.owner != null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbVictories = 0;
for (StatGame g : games) {
if ((g.getType() == GameType.BELGIAN) && (g.getWinner() == user) && !(g.isGameAbandonned())) {
nbVictories++ ;
}
}
......@@ -804,17 +818,17 @@ public class UserMediator {
/**
*
* send number of defeats
* send number of defeats:mode classical
*
* @return int number of defeats
*/
public int getNumberDefeats(GameType type) throws DataException {
public int getNumberDefeatsClassic() {
if(this.owner != null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbDefeats = 0;
for (StatGame g : games) {
if ((g.getType() == type) && (g.getWinner() != user) && !(g.isGameAbandonned())) {
if ((g.getType() == GameType.CLASSIC) && (g.getWinner() != user) && !(g.isGameAbandonned())) {
nbDefeats++ ;
}
}
......@@ -823,19 +837,50 @@ public class UserMediator {
return 0;
}
public int getNumberDefeatsBelgian() {
if(this.owner != null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbDefeats = 0;
for (StatGame g : games) {
if ((g.getType() == GameType.BELGIAN) && (g.getWinner() != user) && !(g.isGameAbandonned())) {
nbDefeats++ ;
}
}
return nbDefeats ;
}
return 0;
}
/**
*
* send number of abandons
*
* @return int number of abandons
*/
public int getNumberAbandons(GameType type) throws DataException {
public int getNumberAbandonsClassic() {
if(this.owner!=null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
//LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbAbandons = 0;
for (StatGame g : games) {
if ((g.getType() == GameType.CLASSIC) && (g.getWinner() == null) && (g.isGameAbandonned())) {
nbAbandons++ ;
}
}
return nbAbandons ;
}
return 0;
}
public int getNumberAbandonsBelgian() {
if(this.owner!=null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
//LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbAbandons = 0;
for (StatGame g : games) {
if ((g.getType() == type) && (g.getWinner() == null) && (g.isGameAbandonned())) {
if ((g.getType() == GameType.BELGIAN) && (g.getWinner() == null) && (g.isGameAbandonned())) {
nbAbandons++ ;
}
}
......
......@@ -21,49 +21,81 @@ public class PublicUser extends SerializableEntity {
private byte[] avatar;
@JsonIgnore
private int numberDefeats;
private int numberDefeatsClassic;
@JsonIgnore
private int numberVictories;
private int numberVictoriesClassic;
@JsonIgnore
private int numberAbandons;
private int numberAbandonsClassic;
@JsonIgnore
private int numberDefeatsBelgian;
@JsonIgnore
private int numberVictoriesBelgian;
@JsonIgnore
private int numberAbandonsBelgian;
@JsonIgnore
public int getNumberDefeats() {
return numberDefeats;
public int getNumberDefeatsClassic() {
return numberDefeatsClassic;
}
@JsonIgnore
public void setNumberDefeats(int nbLost) {
this.numberDefeats = nbLost;
public int getNumberDefeatsBelgian() {
return numberDefeatsBelgian;
}
@JsonIgnore
public int getNumberVictories() {
return numberVictories;
public void setNumberDefeatsClassic(int nbLost) {
this.numberDefeatsClassic = nbLost;
}
@JsonIgnore
public void setNumberDefeatsBelgian(int nbLost) {
this.numberDefeatsBelgian = nbLost;
}
@JsonIgnore
public void setNumberVictories(int nbWin) {
this.numberVictories = nbWin;
public int getNumberVictoriesClassic() {
return numberVictoriesClassic;
}
@JsonIgnore
public int getNumberVictoriesBelgian() {
return numberVictoriesBelgian;
}
@JsonIgnore
public int getNumberAbandons() {
return numberAbandons;
public void setNumberVictoriesClassic(int nbWin) {
this.numberVictoriesClassic = nbWin;
}
@JsonIgnore
public void setNumberVictoriesBelgian(int nbWin) {
this.numberVictoriesBelgian = nbWin;
}
@JsonIgnore
public void setNumberAbandons(int nbOther) {
this.numberAbandons = nbOther;
public int getNumberAbandonsClassic() {
return numberAbandonsClassic;
}
@JsonIgnore
public int getNumberAbandonsBelgian() {
return numberAbandonsBelgian;
}
@JsonIgnore
public void setNumberAbandonsClassic(int nbOther) {
this.numberAbandonsClassic = nbOther;
}
@JsonIgnore
public void setNumberAbandonsBelgian(int nbOther) {
this.numberAbandonsBelgian = nbOther;
}
/**
*
*/
public PublicUser() {
this.numberDefeats = 0;
this.numberVictories = 0;
this.numberAbandons = 0;
this.numberDefeatsClassic = 0;
this.numberDefeatsBelgian = 0;
this.numberVictoriesClassic = 0;
this.numberVictoriesBelgian = 0;
this.numberAbandonsClassic = 0;
this.numberAbandonsBelgian = 0;
}
/**
......@@ -79,9 +111,12 @@ public class PublicUser extends SerializableEntity {
this.firstName = firstName;
this.birthDate = birthDate;
this.numberDefeats = 0;
this.numberAbandons = 0;
this.numberVictories = 0;
this.numberDefeatsClassic = 0;
this.numberAbandonsClassic= 0;
this.numberVictoriesClassic = 0;
this.numberDefeatsBelgian = 0;
this.numberAbandonsBelgian= 0;
this.numberVictoriesBelgian = 0;
}
/**
......
......@@ -84,16 +84,15 @@ public class PlayerProfileController extends AbstractController{
private Button Description;
@FXML
private GridPane stat;
private PublicUser me;
private PublicUser other;
private boolean isOther;
private String attribut;
private Image avatarImage;
private SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
private List<Integer> dataClassic;
private List<Integer> dataBelge;
private List<Integer> dataAll;
private List<Integer> dataBelgian;
private List<Integer> dataTotal;
private SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
@FXML
@Override
......@@ -232,49 +231,68 @@ public class PlayerProfileController extends AbstractController{
}
}
public List<Integer> getData(GameType type) throws DataException{
public List<Integer> getData(PublicUser player,GameType type) throws DataException{
List<Integer> data = new ArrayList<>();
data.add(getFacade().iDataIHMMain.getNumberVictories(type));
data.add(getFacade().iDataIHMMain.getNumberDefeats(type));
data.add(getFacade().iDataIHMMain.getNumberAbandons(type));
data.add(data.get(0)+data.get(1)+data.get(2));
if (type == GameType.CLASSIC){
data.add(player.getNumberVictoriesClassic());
data.add(player.getNumberDefeatsClassic());
data.add(player.getNumberAbandonsClassic());
data.add(data.get(0)+data.get(1)+data.get(2));
}else if (type == GameType.BELGIAN){
data.add(player.getNumberVictoriesBelgian());
data.add(player.getNumberDefeatsBelgian());
data.add(player.getNumberAbandonsBelgian());
data.add(data.get(0)+data.get(1)+data.get(2));
}
return data;
}
public List<Integer> getDataAll() throws DataException{
public List<Integer> getTotal( List<Integer> data1, List<Integer> data2){
List<Integer> data = new ArrayList<>();
data.add(dataClassic.get(0)+dataBelge.get(0));
data.add(dataClassic.get(1)+dataBelge.get(1));
data.add(dataClassic.get(2)+dataBelge.get(2));
data.add(dataClassic.get(3)+dataBelge.get(3));
int i = 0;
for (int a : data1){
data.add(data1.get(i)+data2.get(i));
i++;
}
return data;
}
//data1 total data2 classical data3 belge
public void loadStat(List<Integer> data1,List<Integer> data2,List<Integer> data3){
public void drawPieChart(PieChart chart,List<Integer> data) throws DataException{
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
new PieChart.Data("Win", data.get(0)),
new PieChart.Data("Loss", data.get(1)),
new PieChart.Data("Abandonned", data.get(2))
);
chart.setData(pieChartData);
}
public void loadStat(List<Integer> data1, List<Integer> data2,List<Integer> data3){
int i;
int j;
int index = 0;
boolean firstTime = true;
ObservableList<Node> children = stat.getChildren();
data1.addAll(data2);
data1.addAll(data3);//0 1 2 3 4 5 6 7 8
data1.addAll(data3);
if (children.size()>8){
System.out.println("here!!!!!!!!!!!!!");
firstTime = false;
}
for (j=1;j<4;j++){
for (i=1;i<5;i++){
Label value = new Label();
value.setText(data1.get(index).toString());
stat.add(value, i, j);
if (firstTime == true){
Label value = new Label();
value.setText(data1.get(index).toString());
stat.add(value, i, j);
}
else{
for (Node node : children) {
if (GridPane.getColumnIndex(node) == i && GridPane.getRowIndex(node) == j) {
((Label)node).setText(data1.get(index).toString());
}
}
}
index++;
}
}
//test
for (int v:data1){
System.out.println(v);
}
}
public void drawPieChart(PieChart chart, List<Integer> data) throws DataException{
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
new PieChart.Data("Win", data.get(0)),
new PieChart.Data("Loss", data.get(1)),
new PieChart.Data("Abandonned", data.get(2))
);
chart.setData(pieChartData);
}
public void disableButton(){
playerName.setDisable(true);
......@@ -285,7 +303,7 @@ public class PlayerProfileController extends AbstractController{
avatar.setDisable(true);
Description.setDisable(true);
}
/**
* Initializes all the info of profile.
*/
......@@ -301,13 +319,15 @@ public class PlayerProfileController extends AbstractController{
firstNameText.setText(me.getFirstName());
lastNameText.setText(me.getLastName());
birthdayText.setText(formatter.format(me.getBirthDate()));
dataClassic = getData(GameType.CLASSIC);
dataBelge = getData(GameType.BELGIAN);
dataAll = getDataAll();
loadStat(dataAll,dataClassic,dataBelge);
drawPieChart(allMode,dataAll);
//get data
dataClassic = getData(me,GameType.CLASSIC);
dataBelgian = getData(me,GameType.BELGIAN);
dataTotal = getTotal(dataClassic,dataBelgian);
loadStat(dataClassic,dataBelgian,dataTotal);
drawPieChart(allMode,dataTotal);
drawPieChart(classical,dataClassic);
drawPieChart(belge,dataBelge);
drawPieChart(belge,dataBelgian);
}
catch(NullPointerException e){
e.printStackTrace();
......@@ -318,7 +338,7 @@ public class PlayerProfileController extends AbstractController{
);
} catch (DataException ex) {
Logger.getLogger(PlayerProfileController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
else{
try{
......@@ -329,13 +349,22 @@ public class PlayerProfileController extends AbstractController{
firstNameText.setText(other.getFirstName());
lastNameText.setText(other.getLastName());
birthdayText.setText(formatter.format(other.getBirthDate()));
}
catch(NullPointerException e){
//get data
dataClassic = getData(other,GameType.CLASSIC);
dataBelgian = getData(other,GameType.BELGIAN);
dataTotal = getTotal(dataClassic,dataBelgian);
loadStat(dataClassic,dataBelgian,dataTotal);
drawPieChart(allMode,dataTotal);
drawPieChart(classical,dataClassic);
drawPieChart(belge,dataBelgian);
}catch(NullPointerException e){
Logger.getLogger(
PlayerProfileController.class.getName()).log(Level.INFO,
"[PlayerProfile] - error - other profile is null."
);
}
PlayerProfileController.class.getName()).log(Level.INFO,
"[PlayerProfile] - error - other profile is null."
);
} catch (DataException ex) {
Logger.getLogger(PlayerProfileController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
......
......@@ -132,6 +132,7 @@
</Label>
<GridPane fx:id="stat" prefHeight="125.0" prefWidth="368.0" GridPane.halignment="RIGHT" GridPane.rowIndex="1" GridPane.valignment="CENTER">
<children>
<<<<<<< HEAD
<Label text="Total" GridPane.rowIndex="1">
<GridPane.margin>
<Insets left="10.0" />
......@@ -147,17 +148,31 @@
<Insets left="10.0" />
</GridPane.margin>
</Label>
=======
<Label GridPane.columnIndex="1" />
<Label text="Classical" GridPane.rowIndex="1" />
<Label text="Belgian" GridPane.rowIndex="2" />
<Label text="Total" GridPane.rowIndex="3" />
>>>>>>>