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 {
*/
@Override
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;
import com.utclo23.data.facade.DataFacade;
import com.utclo23.data.structure.ComputerPlayer;
import com.utclo23.data.structure.Coordinate;
import com.utclo23.data.structure.Event;
import com.utclo23.data.structure.Game;
import com.utclo23.data.structure.GameType;
import com.utclo23.data.structure.LightPublicUser;
......@@ -298,37 +299,36 @@ public class GameMediator {
dataFacade.getComfacade().notifyNewCoordinates(new Mine(player, coordinate), currentGame.getRecipients());
//save with caretaker
this.currentGame.getCaretaker().add(this.currentGame.saveStateToMemento());
if (!this.currentGame.isSave()) {
this.currentGame.getCaretaker().add(this.currentGame.saveStateToMemento());
}
//if creator of the game
if (this.currentGame.getStatGame().getCreator().getId().equals(this.dataFacade.getUserMediator().getMyPublicUserProfile().getId())) {
//if computer mode ?
if (this.currentGame.isComputerGame()) {
//attack
// this.currentGame.nextTurn();
Mine m = this.currentGame.getComputerPlayer().randomMine();
this.forwardCoordinates(m);
System.out.println("verification ia bateaux de ... " + this.currentGame.ennemyOf(this.currentGame.getComputerPlayer()).getLightPublicUser().getPlayerName());
boolean check = false;
for (Ship ship : this.currentGame.ennemyOf(this.currentGame.getComputerPlayer()).getShips()) {
if (this.currentGame.isShipTouched(ship, m)) {
System.out.println("IA focus on location");
this.currentGame.getComputerPlayer().setFocus(m.getCoord());
check = true;
if (this.currentGame.isShipDestroyed(ship, this.currentGame.getComputerPlayer().getMines())) {
this.currentGame.getComputerPlayer().loseFocus();
System.out.println("IA loses total focus");
}
}
}
if (!check) {
System.out.println("IA loses focus");
this.currentGame.getComputerPlayer().setFocus(null);
}
......@@ -502,7 +502,7 @@ public class GameMediator {
* @param mine the mine placed
*/
public void forwardCoordinates(Mine mine) {
System.out.println("forward coordinate..");
List<Ship> ships = this.currentGame.getCurrentPlayer().getShips();
Ship shipDestroyed = null;
boolean touched = false;
......@@ -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) {
this.dataFacade.getIhmTablefacade().feedBack(mine.getCoord(), touched, shipDestroyed);
......@@ -664,5 +674,32 @@ 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{
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 @@
*/
package com.utclo23.data.structure;
import java.util.Comparator;
import java.util.Date;
/**
......@@ -12,6 +13,7 @@ import java.util.Date;
* @author Davy
*/
public abstract class Event extends SerializableEntity{
private Date timestamp;
public Event() {
......
......@@ -14,6 +14,8 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javafx.util.Pair;
......@@ -30,6 +32,7 @@ public abstract class Game extends SerializableEntity {
private List<Player> players;
private List<LightPublicUser> spectators;
private List<Message> messages;
private boolean save;
private Caretaker caretaker;
private Player currentPlayer;
......@@ -38,6 +41,8 @@ public abstract class Game extends SerializableEntity {
this.statGame = statGame;
this.statGame.setRealGame(this);
this.save = false;
this.players = players;
this.spectators = spectators;
......@@ -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.
*
......@@ -272,11 +285,15 @@ public abstract class Game extends SerializableEntity {
public Memento saveStateToMemento() {
//notify caretaker
List<Event> events = new ArrayList<>();
//Add msgs
events.addAll(this.messages);
for (Player p : players) {
events.addAll(p.getMines());
}
//creation of memento
Memento memento = new Memento(events);
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