Commit 330fd18d authored by dkonam's avatar dkonam
Browse files

merge conflict

parents 90268335 9005f2a5
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="Battleship/src/main/resources"/>
<classpathentry kind="src" path="Battleship/src/test/java"/>
<classpathentry kind="src" path="Battleship/src/main/java"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>lo23-project</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
...@@ -61,10 +61,12 @@ public class ComFacade { ...@@ -61,10 +61,12 @@ public class ComFacade {
public void sendShipsToEnnemy(List<Ship> listShips, List<LightPublicUser> recipients) { public void sendShipsToEnnemy(List<Ship> listShips, List<LightPublicUser> recipients) {
M_PlaceShip mPlaceship = new M_PlaceShip(iDataCom.getMyPublicUserProfile(), listShips); M_PlaceShip mPlaceship = new M_PlaceShip(iDataCom.getMyPublicUserProfile(), listShips);
for (LightPublicUser recipient : recipients) { for (LightPublicUser recipient : recipients) {
if (kIpCtrl.getHashMap().get(recipient.getId()) != null){
if (kIpCtrl.getHashMap().get(recipient.getId()) != null) {
Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceship); Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceship);
new Thread(os).start(); new Thread(os).start();
} }
} }
} }
...@@ -112,13 +114,13 @@ public class ComFacade { ...@@ -112,13 +114,13 @@ public class ComFacade {
public void notifyNewCoordinates(Mine mine, List<LightPublicUser> recipients) { public void notifyNewCoordinates(Mine mine, List<LightPublicUser> recipients) {
M_PlaceMine mPlaceMine = new M_PlaceMine(iDataCom.getMyPublicUserProfile(), mine); M_PlaceMine mPlaceMine = new M_PlaceMine(iDataCom.getMyPublicUserProfile(), mine);
for (LightPublicUser recipient : recipients) { for (LightPublicUser recipient : recipients) {
if (kIpCtrl.getHashMap().get(recipient.getId()) != null){
Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceMine); Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceMine);
new Thread(os).start(); new Thread(os).start();
} }
} }
}
/** /**
* Called to notify everybody of the creation of a new game to update all * Called to notify everybody of the creation of a new game to update all
* users Data's module. * users Data's module.
......
...@@ -142,7 +142,7 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -142,7 +142,7 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
*/ */
@Override @Override
public void updatePlayername(String playername) throws DataException { public void updatePlayername(String playername) throws DataException {
this.userMediator.updatePlayername(playername); this.userMediator.updatePlayername(playername);
} }
...@@ -220,13 +220,13 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -220,13 +220,13 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
} }
/** /**
* Add new game <<<<<<< HEAD * Add new game
* *
* @param game ======= * @param game
* @param game the game to add >>>>>>> Data/javadoc
*/ */
@Override @Override
public void addNewGame(StatGame game) { public void addNewGame(StatGame game) {
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Data | new game received");
this.gameMediator.addNewGame(game); this.gameMediator.addNewGame(game);
...@@ -246,7 +246,10 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -246,7 +246,10 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
*/ */
@Override @Override
public void setEnnemyShips(List<Ship> ships) { public void setEnnemyShips(List<Ship> ships) {
//this.gameMediator.setEnnemyShips(ships);
Logger.getLogger(DataFacade.class.getName()).log(Level.INFO, null, "data | set ennemy ships");
this.gameMediator.setEnnemyShips(ships);
} }
/** /**
...@@ -257,6 +260,7 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -257,6 +260,7 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
*/ */
@Override @Override
public void forwardCoordinates(Mine mine) { public void forwardCoordinates(Mine mine) {
Logger.getLogger(DataFacade.class.getName()).log(Level.INFO, null, "data | forward coordinates");
this.gameMediator.forwardCoordinates(mine); this.gameMediator.forwardCoordinates(mine);
} }
...@@ -266,8 +270,11 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -266,8 +270,11 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
*/ */
@Override @Override
public void leaveGame() { public void leaveGame() {
Logger.getLogger(DataFacade.class.getName()).log(Level.INFO, null, "data | leave game");
PublicUser user = this.userMediator.getMyPublicUserProfile(); PublicUser user = this.userMediator.getMyPublicUserProfile();
//LightPublicUser user = this.userMediator.getMyLightPublicUserProfile(); com doit prendre en argument un LightPublicUser
this.comfacade.leaveGame(); this.comfacade.leaveGame();
this.gameMediator.leaveGame(); this.gameMediator.leaveGame();
try { try {
...@@ -282,6 +289,8 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -282,6 +289,8 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
*/ */
@Override @Override
public void opponentHasLeftGame() { public void opponentHasLeftGame() {
Logger.getLogger(DataFacade.class.getName()).log(Level.INFO, null, "data | opponent has left");
if (!this.gameMediator.isFinishedGame()) { if (!this.gameMediator.isFinishedGame()) {
try { try {
this.gameMediator.defWin(); this.gameMediator.defWin();
...@@ -298,7 +307,13 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -298,7 +307,13 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
*/ */
@Override @Override
public void connectionLostWithOpponent() { public void connectionLostWithOpponent() {
Logger.getLogger(DataFacade.class.getName()).log(Level.INFO, null, "data | connection lost");
//stats.
this.gameMediator.setWinner(null); this.gameMediator.setWinner(null);
this.gameMediator.getCurrentGame().getStatGame().setGameAbandonned(true);
this.gameMediator.leaveGame(); this.gameMediator.leaveGame();
this.ihmTablefacade.connectionLostWithOpponent(); this.ihmTablefacade.connectionLostWithOpponent();
} }
...@@ -363,6 +378,8 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -363,6 +378,8 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
*/ */
@Override @Override
public void forwardMessage(Message msg) { public void forwardMessage(Message msg) {
Logger.getLogger(DataFacade.class.getName()).log(Level.INFO, null, "data | forward message");
this.gameMediator.forwardMessage(msg); this.gameMediator.forwardMessage(msg);
} }
...@@ -402,8 +419,8 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -402,8 +419,8 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
*/ */
@Override @Override
public void updateGameList(LightPublicUser user, String id, String role) throws DataException { public void updateGameList(LightPublicUser user, String id, String role) throws DataException {
Logger.getLogger(DataFacade.class.getName()).log(Level.INFO, null, "data | update game list "+user.getPlayerName()+" "+id+" "+role);
this.gameMediator.updateGameList(user, id, role); this.gameMediator.updateGameList(user, id, role);
this.gameMediator.getCurrentGame().addUser(user, role);
} }
/** /**
...@@ -414,6 +431,8 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -414,6 +431,8 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
*/ */
@Override @Override
public List<Ship> getTemplateShips() throws DataException { public List<Ship> getTemplateShips() throws DataException {
Logger.getLogger(DataFacade.class.getName()).log(Level.INFO, null, "data | get template ships");
if (this.gameMediator.getCurrentGame() != null) { if (this.gameMediator.getCurrentGame() != null) {
return this.gameMediator.getCurrentGame().getTemplateShips(); return this.gameMediator.getCurrentGame().getTemplateShips();
} else { } else {
...@@ -428,7 +447,8 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -428,7 +447,8 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
* *
*/ */
public void setShip(Ship ship) throws DataException { public void setShip(Ship ship) throws DataException {
Logger.getLogger(DataFacade.class.getName()).log(Level.INFO, null, "data | set ship");
this.gameMediator.setPlayerShip(ship); this.gameMediator.setPlayerShip(ship);
} }
...@@ -447,11 +467,20 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -447,11 +467,20 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
*/ */
@Override @Override
public Pair<Integer, Ship> attack(Coordinate coords, boolean isAttack) { public Pair<Integer, Ship> attack(Coordinate coords, boolean isAttack) {
if(isAttack)
{
System.out.println("datafacade | attack "+coords.getX()+"-"+coords.getY());
}
try { try {
return this.gameMediator.attack(coords, isAttack); Pair<Integer, Ship> pairReturn = this.gameMediator.attack(coords, isAttack);
if(this.getComfacade() != null){
this.getComfacade().notifyNewCoordinates(this.gameMediator.getCurrentGame().getRecentMine(coords), this.gameMediator.getCurrentGame().getRecipients());
}
return pairReturn;
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
//Logger.getLogger(DataFacade.class.getName()).log(Level.SEVERE, null, ex);
return null; return null;
} }
} }
...@@ -485,6 +514,9 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -485,6 +514,9 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
*/ */
@Override @Override
public void sendMessage(String text) { public void sendMessage(String text) {
Logger.getLogger(DataFacade.class.getName()).log(Level.INFO, null, "data | send message "+text);
this.gameMediator.sendMessage(text); this.gameMediator.sendMessage(text);
} }
...@@ -655,8 +687,10 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -655,8 +687,10 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
@Override @Override
public void receptionGame(Game game) throws DataException { public void receptionGame(Game game) throws DataException {
Logger.getLogger(DataFacade.class.getName()).log(Level.INFO, null, "data | reception game");
if (game != null) { if (game != null) {
Logger.getLogger(DataFacade.class.getName()).log(Level.INFO, null, "data | game not null");
this.gameMediator.receptionGame(game); this.gameMediator.receptionGame(game);
} }
...@@ -676,4 +710,39 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -676,4 +710,39 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
} }
/**
*
* send number of victories
*
* @return int number of victories
* @throws DataException
*/
@Override
public int getNumberVictories() throws DataException {
return this.userMediator.getNumberVictories() ;
}
/**
*
* send number of defeats
*
* @return int number of defeats
* @throws DataException
*/
@Override
public int getNumberDefeats() throws DataException {
return this.userMediator.getNumberDefeats() ;
}
/**
*
* send number of abandons
*
* @return int number of abandons
* @throws DataException
*/
@Override
public int getNumberAbandons() throws DataException {
return this.userMediator.getNumberAbandons() ;
}
} }
...@@ -47,6 +47,8 @@ public interface IDataIHMMain { ...@@ -47,6 +47,8 @@ public interface IDataIHMMain {
public void updateFileImage(String fileImage) throws DataException; public void updateFileImage(String fileImage) throws DataException;
public void updatePassword(String password) throws DataException; public void updatePassword(String password) throws DataException;
public int getNumberVictories() throws DataException;
public int getNumberDefeats() throws DataException;
public int getNumberAbandons() throws DataException;
} }
\ No newline at end of file
...@@ -10,6 +10,7 @@ import java.util.List; ...@@ -10,6 +10,7 @@ import java.util.List;
import com.utclo23.data.structure.BelgianGame; import com.utclo23.data.structure.BelgianGame;
import com.utclo23.data.structure.ClassicGame; import com.utclo23.data.structure.ClassicGame;
import com.utclo23.data.structure.ComputerPlayer;
import com.utclo23.data.structure.Game; import com.utclo23.data.structure.Game;
import com.utclo23.data.structure.GameType; import com.utclo23.data.structure.GameType;
import com.utclo23.data.structure.LightPublicUser; import com.utclo23.data.structure.LightPublicUser;
...@@ -40,13 +41,17 @@ public class GameFactory { ...@@ -40,13 +41,17 @@ public class GameFactory {
if(computerMode) if(computerMode)
{ {
System.out.println("Data | computer mode");
//add second player //add second player
Player j2 = new Player(LightPublicUser.generateComputerProfile()); Player j2 = new ComputerPlayer();
j2.setComputer(true); j2.setComputer(true);
players.add(j2); players.add(j2);
} }
System.out.println("player number : "+players.size());
List<LightPublicUser> spectators = new ArrayList<>(); List<LightPublicUser> spectators = new ArrayList<>();
spectators.add(creator); spectators.add(creator);
......
...@@ -766,5 +766,69 @@ public class UserMediator { ...@@ -766,5 +766,69 @@ public class UserMediator {
} }
/**
*
* send number of victories
*
* @return int number of victories
* @throws DataException
*/
public int getNumberVictories() throws DataException {
if(this.owner != null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbVictories = 0;
for (StatGame g : games) {
if ((g.getWinner() == user) && !(g.isGameAbandonned())) {
nbVictories++ ;
}
}
return nbVictories ;
}
return 0;
}
/**
*
* send number of defeats
*
* @return int number of defeats
* @throws DataException
*/
public int getNumberDefeats() throws DataException {
if(this.owner != null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbDefeats = 0;
for (StatGame g : games) {
if ((g.getWinner() != user) && !(g.isGameAbandonned())) {
nbDefeats++ ;
}
}
return nbDefeats ;
}
return 0;
}
/**
*
* send number of abandons
*
* @return int number of abandons
* @throws DataException
*/
public int getNumberAbandons() throws DataException {
if(this.owner!=null){
List<StatGame> games = this.getMyOwnerProfile().getPlayedGamesList() ;
LightPublicUser user = this.getMyLightPublicUserProfile() ;
int nbAbandons = 0;
for (StatGame g : games) {
if ((g.getWinner() == null) && (g.isGameAbandonned())) {
nbAbandons++ ;
}
}
return nbAbandons ;
}
return 0;
}
} }
...@@ -5,20 +5,34 @@ ...@@ -5,20 +5,34 @@
*/ */
package com.utclo23.data.structure; package com.utclo23.data.structure;
import com.utclo23.data.configuration.Configuration;
import java.rmi.server.UID; import java.rmi.server.UID;
import java.util.List;
import java.util.Random;
import javafx.util.Pair;
/** /**
* *
* @author lucillefargeau * @author lucillefargeau
*/ */
public class ComputerPlayer extends Player{ public class ComputerPlayer extends Player {
private Coordinate focus; private Coordinate focus;
private Coordinate oldFocus;
public void loseFocus()
{
this.oldFocus = null;
this.focus = null;
}
public ComputerPlayer() { public ComputerPlayer() {
super(LightPublicUser.generateComputerProfile()); super(LightPublicUser.generateComputerProfile());
System.out.println("new Com player");
this.focus = null; this.focus = null;
this.oldFocus = null;
this.setComputer(true);
} }
public Coordinate getFocus() { public Coordinate getFocus() {
...@@ -26,14 +40,221 @@ public class ComputerPlayer extends Player{ ...@@ -26,14 +40,221 @@ public class ComputerPlayer extends Player{
} }
public void setFocus(Coordinate focus) { public void setFocus(Coordinate focus) {
this.oldFocus = this.focus;
this.focus = focus; this.focus = focus;
} }
public Coordinate getOldFocus() {
return oldFocus;
}
public void setOldFocus(Coordinate oldFocus) {
this.oldFocus = oldFocus;
}
@Override
public void setShips(List<Ship> ships) {
System.out.println("Data | set ships IA");
int[][] tab = new int[10][10];
for (int i = 0; i < Configuration.WIDTH; ++i) {
for (int j = 0; j < Configuration.WIDTH; ++j) {
tab[i][j] = 0; //empty
}
}
int x, y;
for (Ship ship : ships) {
Random r = new Random();
boolean valid = true;
do {
//choose a new location until empty
x = r.nextInt(Configuration.HEIGHT - 1);
y = r.nextInt(Configuration.WIDTH - 1);
if (tab[x][y] != 0 || (x + ship.getSize() >= Configuration.WIDTH && y + ship.