Commit 916892dc authored by Myriam Begel's avatar Myriam Begel

Death ok for single and multi player - GameOverPanel ok

parent e3e9ed45
......@@ -3,7 +3,9 @@ package core.event;
import core.gamestate.GameContent;
/**
* Event received by Client when an entity die.
* @author Begel Myriam
* Just remove it from the GameState.
*/
public class ToClientDeathEvent implements ClientEvent {
private int entityID;
......@@ -12,6 +14,10 @@ public class ToClientDeathEvent implements ClientEvent {
this.entityID = entityID;
}
public int getEntityID(){
return entityID;
}
private static final long serialVersionUID = 1L;
@Override
public boolean execute(GameContent gameContent) {
......
......@@ -4,9 +4,11 @@ import artificial_intelligence.AIControler;
import core.gamestate.GameContent;
/**
* This event is executed when an entity dies.
* This event is executed by Server when an entity dies.
* @author Begel Myriam
*
* We kill the AI if it is one (if not, the method just do nothing).
* In resolve, we send to the client almost the same Event: AI is not on ClientSide
* so we don't kill AI.
*/
public class ToServerDeathEvent implements ServerEvent {
private int entityID;
......@@ -15,10 +17,6 @@ public class ToServerDeathEvent implements ServerEvent {
this.entityID = entityID;
}
public int getEntityID(){
return entityID;
}
private static final long serialVersionUID = 1L;
@Override
public boolean execute(GameContent gameContent) {
......
......@@ -101,11 +101,14 @@ public class Being extends Entity {
if (HP==0){
Event event = new ToServerDeathEvent(this.getID());
Logger LOGGER = new Logging().getLogger();
LOGGER.info(this.getID()+" is dead");
DummyLocalGameLoop temp1 = DummyLocalGameLoop.getInstance();
NetworkConnection<NetworkObject> temp2 = temp1.getNetworkConnection();
LOGGER.info((temp2==null)+" hope false");
temp2.sendEvent(event);
NetworkConnection<NetworkObject> network = DummyLocalGameLoop.getInstance().getNetworkConnection();
if (network==null){
LOGGER.severe("NetworkConnection null, Being"+this.getID()+" can't die");
} else {
LOGGER.info("Death of "+this.getID()+" is send");
network.sendEvent(event);
}
}
return isDead();
}
......
......@@ -2,9 +2,12 @@ package gameloop;
import core.event.Event;
import core.event.MapInit;
import core.event.ToClientDeathEvent;
import core.event.ToServerDeathEvent;
import core.gamestate.GameContent;
import core.relayer.Relayer;
import core.relayer.Relayers;
import graphics.graphical_abstraction.GraphicsMasterAbstraction;
import network.EndEvent;
import network.NetworkConnection;
import network.NetworkObject;
......@@ -142,6 +145,10 @@ public class DummyLocalGameLoop extends Thread{
setFollowedRelayer(firstEntityRelayer);
relayerSemaphore.release();
}
if (eventToReceive instanceof ToClientDeathEvent && ((ToClientDeathEvent) eventToReceive).getEntityID()==followedRelayer.getCharacter().getID()) {
GraphicsMasterAbstraction.getInstance().changeGUIStateTo(GraphicsMasterAbstraction.GUIStates.GAME_OVER);
}
}
if (eventToReceive instanceof EndEvent)
System.out.println("DummyLocalGameLoop Thread: End Event Received!");
......
......@@ -31,6 +31,16 @@ public class ServerLoop extends Thread {
this.networkConnection=serverConnection;
}
public synchronized NetworkConnection<NetworkObject> getNetworkConnection()
{
return networkConnection;
}
private static ServerLoop ourInstance = new ServerLoop();
public static ServerLoop getInstance() {
return ourInstance;
}
private ServerLoop() {
}
int cframe = 0;
private GameContent load(){
Map newMap= MapGeneration.mapGeneration(15, 20);
......@@ -73,9 +83,6 @@ public class ServerLoop extends Thread {
/*Add all event received to the queue*/
for(Event event=(Event)networkConnection.receiveEvent(false);event!=null;event=(Event)networkConnection.receiveEvent(false)){
queue.addEvent(event, cframe);
if (event instanceof ToServerDeathEvent && ((ToServerDeathEvent) event).getEntityID()==0) {
GraphicsMasterAbstraction.getInstance().changeGUIStateTo(GraphicsMasterAbstraction.GUIStates.GAME_OVER);
}
if (event instanceof EndEvent) {
System.out.println("DummyServerLoop: Just received an EndEvent");
//this is so bad because if this thread sleeps for too long it's a disaster
......
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