Commit 3279dff7 authored by JING LI's avatar JING LI
Browse files

Merge branch 'Data/develop' of https://gitlab.utc.fr/qdruault/lo23-project into data/javadoc

parents d1b43e89 61f4216b
......@@ -22,7 +22,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Set;
/**
* Facade for the communication module
*
......@@ -40,7 +39,7 @@ public class ComFacade {
public ComFacade(IDataCom iDataCom) {
this.iDataCom = iDataCom;
kIpCtrl = KnownIPController.getInstance();
kIpCtrl = KnownIPController.getInstance();
receiver = new Receiver(25000, iDataCom);
new Thread(receiver).start();
Logger.getLogger(ComFacade.class.getName()).log(Level.INFO, null, "Facade created");
......@@ -65,7 +64,7 @@ public class ComFacade {
if (kIpCtrl.getHashMap().get(recipient.getId()) != null) {
Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceship);
new Thread(os).start();
}
}
}
}
......@@ -83,7 +82,7 @@ public class ComFacade {
public void notifyUserSignedOut() {
M_Deconnection mDeconnection = new M_Deconnection(iDataCom.getMyPublicUserProfile());
for (Inet4Address ip : kIpCtrl.getHashMap().values()) {
if (ip != null){
if (ip != null) {
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), mDeconnection);
new Thread(os).start();
}
......@@ -98,7 +97,7 @@ public class ComFacade {
public void notifyNewMessage(com.utclo23.data.structure.Message message) {
M_Chat mChat = new M_Chat(iDataCom.getMyPublicUserProfile(), message);
for (LightPublicUser recipient : message.getRecipients()) {
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(), mChat);
new Thread(os).start();
}
......@@ -112,28 +111,31 @@ public class ComFacade {
* @param recipients are the recipients of the new mine
*/
public void notifyNewCoordinates(Mine mine, List<LightPublicUser> recipients) {
M_PlaceMine mPlaceMine = new M_PlaceMine(iDataCom.getMyPublicUserProfile(), mine);
for (LightPublicUser recipient : recipients) {
if (kIpCtrl.getHashMap().get(recipient.getId()) != null) {
Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceMine);
new Thread(os).start();
}
}
/**
* Called to notify everybody of the creation of a new game to update all
* users Data's module.
*
* @param game is the new created game
*/
public void notifyNewGame(StatGame game) {
}
/**
* Called to notify everybody of the creation of a new game to update
* all users Data's module.
*
* @param game is the new created game
*/
public void notifyNewGame(StatGame game) {
M_CreationGame mCreationGame = new M_CreationGame(iDataCom.getMyPublicUserProfile(), game);
for (Inet4Address ip : kIpCtrl.getHashMap().values()) {
if(ip != null){
if (ip != null) {
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), mCreationGame);
Thread thread = new Thread(os);
thread.start();
thread.start();
}
}
}
......@@ -158,7 +160,7 @@ public class ComFacade {
public void leaveGame() {
M_LeaveGame mLeaveGame = new M_LeaveGame(iDataCom.getMyPublicUserProfile());
for (Inet4Address ip : kIpCtrl.getHashMap().values()) {
if(ip != null){
if (ip != null) {
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), mLeaveGame);
new Thread(os).start();
}
......@@ -176,22 +178,23 @@ public class ComFacade {
List<LightPublicUser> tmp = new ArrayList(iDataCom.getConnectedUsers());
tmp.add(iDataCom.getMyPublicUserProfile().getLightPublicUser());
// Suppression des doublons et de nous même au cas où
// dans listIpTarget
Set set = new HashSet();
set.addAll(listIpTarget);
if(set.contains(kIpCtrl.getMyInetAddress()))
if (set.contains(kIpCtrl.getMyInetAddress())) {
set.remove(kIpCtrl.getMyInetAddress());
}
List<Inet4Address> newIpTarget = new ArrayList(set);
for (Inet4Address ipDest : newIpTarget) {
for (Inet4Address ipDest : newIpTarget) {
// On vérie si l'ip n'est pas déjà dans le hashMap
if(!kIpCtrl.getHashMap().containsValue(ipDest)){
if (!kIpCtrl.getHashMap().containsValue(ipDest)) {
List otherTargets = new ArrayList(newIpTarget);
otherTargets.remove(ipDest);
M_Bleu mBleu = new M_Bleu(iDataCom.getMyPublicUserProfile(),
M_Bleu mBleu = new M_Bleu(iDataCom.getMyPublicUserProfile(),
tmpHash, tmp, iDataCom.getGameList(), otherTargets);
Sender os = new Sender(ipDest.getHostAddress(), kIpCtrl.getPort(), mBleu);
new Thread(os).start();
......@@ -224,7 +227,7 @@ public class ComFacade {
if (success) {
for (Inet4Address ip : kIpCtrl.getHashMap().values()) {
if(ip != null) {
if (ip != null) {
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), mJoinGameResponse);
new Thread(os).start();
Logger.getLogger(ComFacade.class.getName()).log(Level.INFO, null, "Send success joinGame");
......
......@@ -282,6 +282,8 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
} catch (IOException ex) {
ex.printStackTrace();
}
this.opponentHasLeftGame();
}
/**
......
......@@ -321,6 +321,7 @@ public class GameMediator {
if (this.currentGame.isShipDestroyed(ship, this.currentGame.getComputerPlayer().getMines())) {
this.currentGame.getComputerPlayer().loseFocus();
System.out.println("");
}
}
......@@ -666,7 +667,6 @@ public class GameMediator {
if (ready) //notify IA to place ships
{
System.out.println("Data | IA turn set ships");
this.currentGame.getComputerPlayer().setShips(this.currentGame.getTemplateShips());
this.dataFacade.getIhmTablefacade().notifyGameReady();
......
......@@ -40,8 +40,14 @@ public class ComputerPlayer extends Player {
}
public void setFocus(Coordinate focus) {
if(focus!=null){
this.oldFocus = this.focus;
this.focus = focus;
}
else
{
this.focus = this.oldFocus;
}
}
......@@ -73,8 +79,8 @@ public class ComputerPlayer extends Player {
do {
//choose a new location until empty
x = r.nextInt(Configuration.HEIGHT - 1);
y = r.nextInt(Configuration.WIDTH - 1);
x = r.nextInt(Configuration.HEIGHT );
y = r.nextInt(Configuration.WIDTH);
if (tab[x][y] != 0 || (x + ship.getSize() >= Configuration.WIDTH && y + ship.getSize() >= Configuration.WIDTH)) {
// System.out.println("("+x+","+y+") NON VALIDE");
......@@ -191,8 +197,8 @@ public class ComputerPlayer extends Player {
do {
valid = true;
//choose a new location until empty
x = r.nextInt(Configuration.WIDTH - 1);
y = r.nextInt(Configuration.WIDTH - 1);
x = r.nextInt(Configuration.WIDTH );
y = r.nextInt(Configuration.WIDTH);
if (tab[x][y] != 0 || (x >= Configuration.WIDTH || y >= Configuration.WIDTH)) {
valid = false;
......@@ -205,9 +211,13 @@ public class ComputerPlayer extends Player {
//System.out.println("focus method");
if ((focus.getX() + 1 >= Configuration.WIDTH || focus.getY() >= Configuration.WIDTH) || tab[focus.getX() + 1][focus.getY()] != 0 ) {
System.out.println("no x + 1");
if ((focus.getX() - 1 < 0 || focus.getY() >= Configuration.WIDTH) || tab[focus.getX() - 1][focus.getY()] != 0) {
System.out.println("no x-1");
if ((focus.getX() >= Configuration.WIDTH || focus.getY() + 1 >= Configuration.WIDTH)|| tab[focus.getX()][focus.getY() + 1] != 0) {
System.out.println("no y+1");
if ( (focus.getX() >= Configuration.WIDTH || focus.getY() - 1 < 0) || tab[focus.getX()][focus.getY() - 1] != 0) {
System.out.println("no y-1");
this.focus = null;
this.oldFocus = null;
......@@ -217,8 +227,8 @@ public class ComputerPlayer extends Player {
valid = true;
//choose a new location until empty
x = r.nextInt(Configuration.HEIGHT - 1);
y = r.nextInt(Configuration.WIDTH - 1);
x = r.nextInt(Configuration.HEIGHT );
y = r.nextInt(Configuration.WIDTH);
if (tab[x][y] != 0 || (x >= Configuration.WIDTH || y >= Configuration.WIDTH)) {
......@@ -230,19 +240,24 @@ public class ComputerPlayer extends Player {
} while (!valid);
} else {
System.out.println("y-1");
x = focus.getX();
y = focus.getY() - 1;
}
} else {
System.out.println("y+1");
x = focus.getX();
y = focus.getY() + 1;
}
} else {
System.out.println("x-1");
x = focus.getX() - 1;
y = focus.getY();
}
} else {
System.out.println("x+1");
x = focus.getX() + 1;
y = focus.getY();
}
......
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