Commit 0b80e052 authored by dkonam's avatar dkonam
Browse files

Merge branch 'Data/develop' into develop

parents 330fd18d 1271aa47
...@@ -504,7 +504,9 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain { ...@@ -504,7 +504,9 @@ public class DataFacade implements IDataCom, IDataIHMTable, IDataIHMMain {
*/ */
@Override @Override
public List<Event> getNextBoard() { public List<Event> getNextBoard() {
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.
return null;
} }
/** /**
......
...@@ -5,6 +5,7 @@ import com.utclo23.data.configuration.Configuration; ...@@ -5,6 +5,7 @@ import com.utclo23.data.configuration.Configuration;
import com.utclo23.data.facade.DataFacade; import com.utclo23.data.facade.DataFacade;
import com.utclo23.data.structure.ComputerPlayer; import com.utclo23.data.structure.ComputerPlayer;
import com.utclo23.data.structure.Coordinate; import com.utclo23.data.structure.Coordinate;
import com.utclo23.data.structure.Event;
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;
...@@ -298,29 +299,28 @@ public class GameMediator { ...@@ -298,29 +299,28 @@ public class GameMediator {
dataFacade.getComfacade().notifyNewCoordinates(new Mine(player, coordinate), currentGame.getRecipients()); dataFacade.getComfacade().notifyNewCoordinates(new Mine(player, coordinate), currentGame.getRecipients());
//save with caretaker //save with caretaker
if (!this.currentGame.isSave()) {
this.currentGame.getCaretaker().add(this.currentGame.saveStateToMemento()); this.currentGame.getCaretaker().add(this.currentGame.saveStateToMemento());
}
//if creator of the game //if creator of the game
if (this.currentGame.getStatGame().getCreator().getId().equals(this.dataFacade.getUserMediator().getMyPublicUserProfile().getId())) { if (this.currentGame.getStatGame().getCreator().getId().equals(this.dataFacade.getUserMediator().getMyPublicUserProfile().getId())) {
//if computer mode ? //if computer mode ?
if (this.currentGame.isComputerGame()) { if (this.currentGame.isComputerGame()) {
//attack //attack
// this.currentGame.nextTurn();
Mine m = this.currentGame.getComputerPlayer().randomMine(); Mine m = this.currentGame.getComputerPlayer().randomMine();
this.forwardCoordinates(m); this.forwardCoordinates(m);
System.out.println("verification ia bateaux de ... " + this.currentGame.ennemyOf(this.currentGame.getComputerPlayer()).getLightPublicUser().getPlayerName());
boolean check = false; boolean check = false;
for (Ship ship : this.currentGame.ennemyOf(this.currentGame.getComputerPlayer()).getShips()) { for (Ship ship : this.currentGame.ennemyOf(this.currentGame.getComputerPlayer()).getShips()) {
if (this.currentGame.isShipTouched(ship, m)) { if (this.currentGame.isShipTouched(ship, m)) {
System.out.println("IA focus on location");
this.currentGame.getComputerPlayer().setFocus(m.getCoord()); this.currentGame.getComputerPlayer().setFocus(m.getCoord());
check = true; check = true;
if (this.currentGame.isShipDestroyed(ship, this.currentGame.getComputerPlayer().getMines())) { if (this.currentGame.isShipDestroyed(ship, this.currentGame.getComputerPlayer().getMines())) {
this.currentGame.getComputerPlayer().loseFocus(); this.currentGame.getComputerPlayer().loseFocus();
System.out.println("IA loses total focus");
} }
} }
...@@ -328,7 +328,7 @@ public class GameMediator { ...@@ -328,7 +328,7 @@ public class GameMediator {
} }
if (!check) { if (!check) {
System.out.println("IA loses focus");
this.currentGame.getComputerPlayer().setFocus(null); this.currentGame.getComputerPlayer().setFocus(null);
} }
...@@ -502,7 +502,7 @@ public class GameMediator { ...@@ -502,7 +502,7 @@ public class GameMediator {
* @param mine the mine placed * @param mine the mine placed
*/ */
public void forwardCoordinates(Mine mine) { public void forwardCoordinates(Mine mine) {
System.out.println("forward coordinate..");
List<Ship> ships = this.currentGame.getCurrentPlayer().getShips(); List<Ship> ships = this.currentGame.getCurrentPlayer().getShips();
Ship shipDestroyed = null; Ship shipDestroyed = null;
boolean touched = false; boolean touched = false;
...@@ -515,6 +515,16 @@ public class GameMediator { ...@@ -515,6 +515,16 @@ public class GameMediator {
} }
} }
//Add mine to local game
if (!this.currentGame.isComputerGame()) {
this.currentGame.ennemyOf(this.currentGame.getCurrentPlayer()).getMines().add(mine);
}
//save
if (!this.currentGame.isSave()) {
this.currentGame.getCaretaker().add(this.currentGame.saveStateToMemento());
}
if (this.dataFacade.getIhmTablefacade() != null) { if (this.dataFacade.getIhmTablefacade() != null) {
this.dataFacade.getIhmTablefacade().feedBack(mine.getCoord(), touched, shipDestroyed); this.dataFacade.getIhmTablefacade().feedBack(mine.getCoord(), touched, shipDestroyed);
...@@ -665,4 +675,31 @@ public class GameMediator { ...@@ -665,4 +675,31 @@ public class GameMediator {
} }
} }
public void next()
{
if(this.currentGame!= null)
{
if(this.currentGame.isSave())
{
Event event = this.currentGame.getCaretaker().getMemento().getLastEvent();
if(event instanceof Mine)
{
Mine mine = (Mine) event;
if(this.dataFacade.getMyPublicUserProfile().getId().equals(mine.getOwner().getLightPublicUser().getId()))
{
//equivalent of attack
}
else
{
//equivalent of forward
}
}
this.currentGame.getCaretaker().next();
}
}
}
} }
...@@ -44,4 +44,18 @@ public class Memento extends SerializableEntity{ ...@@ -44,4 +44,18 @@ public class Memento extends SerializableEntity{
this.state = state; this.state = state;
} }
public Event getLastEvent()
{
Event max = this.state.get(0);
for(int i = 1; i< state.size(); ++i)
{
if(max!=null && max.getTimestamp().compareTo(state.get(i).getTimestamp()) < 0)
{
max = state.get(i);
}
}
return max;
}
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
*/ */
package com.utclo23.data.structure; package com.utclo23.data.structure;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
/** /**
...@@ -12,6 +13,7 @@ import java.util.Date; ...@@ -12,6 +13,7 @@ import java.util.Date;
* @author Davy * @author Davy
*/ */
public abstract class Event extends SerializableEntity{ public abstract class Event extends SerializableEntity{
private Date timestamp; private Date timestamp;
public Event() { public Event() {
......
...@@ -14,6 +14,8 @@ import java.io.IOException; ...@@ -14,6 +14,8 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import javafx.util.Pair; import javafx.util.Pair;
...@@ -30,6 +32,7 @@ public abstract class Game extends SerializableEntity { ...@@ -30,6 +32,7 @@ public abstract class Game extends SerializableEntity {
private List<Player> players; private List<Player> players;
private List<LightPublicUser> spectators; private List<LightPublicUser> spectators;
private List<Message> messages; private List<Message> messages;
private boolean save;
private Caretaker caretaker; private Caretaker caretaker;
private Player currentPlayer; private Player currentPlayer;
...@@ -38,6 +41,8 @@ public abstract class Game extends SerializableEntity { ...@@ -38,6 +41,8 @@ public abstract class Game extends SerializableEntity {
this.statGame = statGame; this.statGame = statGame;
this.statGame.setRealGame(this); this.statGame.setRealGame(this);
this.save = false;
this.players = players; this.players = players;
this.spectators = spectators; this.spectators = spectators;
...@@ -48,6 +53,14 @@ public abstract class Game extends SerializableEntity { ...@@ -48,6 +53,14 @@ public abstract class Game extends SerializableEntity {
} }
public boolean isSave() {
return save;
}
public void setSave(boolean save) {
this.save = save;
}
/** /**
* Adding a user to the game, as spectator or player. * Adding a user to the game, as spectator or player.
* *
...@@ -272,11 +285,15 @@ public abstract class Game extends SerializableEntity { ...@@ -272,11 +285,15 @@ public abstract class Game extends SerializableEntity {
public Memento saveStateToMemento() { public Memento saveStateToMemento() {
//notify caretaker //notify caretaker
List<Event> events = new ArrayList<>(); List<Event> events = new ArrayList<>();
//Add msgs //Add msgs
events.addAll(this.messages); events.addAll(this.messages);
for (Player p : players) { for (Player p : players) {
events.addAll(p.getMines()); events.addAll(p.getMines());
} }
//creation of memento //creation of memento
Memento memento = new Memento(events); Memento memento = new Memento(events);
return memento; return memento;
......
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