Commit c2163620 authored by Bogdan's avatar Bogdan

Lounges work now + new file organization

parent c85835e1
......@@ -2,7 +2,7 @@ package core.event;
import core.gamestate.GameContent;
import network.innershell.NetworkObject;
import network.helpers.NetworkObject;
/**
* This interface is used to define the message transmitted between the Relayer,
......
......@@ -13,7 +13,7 @@ import gameloop.DummyLocalGameLoop;
import graphics.guiSkeleton.entityDisplayer.EntityDisplayerType;
import logging.Logging;
import map_generation.tiles.TilePropertyVector;
import network.innershell.NetworkConnection;
import network.inner_shell.NetworkConnection;
/**
* This class represents an Entity able to be hit and die.
......
......@@ -18,7 +18,7 @@ import graphics.guiSkeleton.entityDisplayer.EntityDisplayerProvider;
import graphics.guiSkeleton.entityDisplayer.EntityDisplayerType;
import map_generation.map.Map;
import map_generation.tiles.TilePropertyVector;
import network.innershell.NetworkConnection;
import network.inner_shell.NetworkConnection;
/**
* This interface is used to define one object in the GameState.
......
......@@ -3,13 +3,12 @@ package core.gamestate;
import core.zone.Point;
import logging.Logging;
import map_generation.map.Map;
import network.innershell.NetworkConnection;
import network.inner_shell.NetworkConnection;
import core.event.MapChangeEvent;
import core.relayer.*;
import artificial_intelligence.AIControler;
import artificial_intelligence.AIEntities.EnumBehaviourType;
import java.io.InterruptedIOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
......
......@@ -8,8 +8,8 @@ import core.relayer.Relayer;
import core.relayer.Relayers;
import graphics.graphical_abstraction.GraphicsMasterAbstraction;
import logging.Logging;
import network.innershell.EndEvent;
import network.innershell.NetworkConnection;
import network.helpers.EndEvent;
import network.inner_shell.NetworkConnection;
import java.util.concurrent.Semaphore;
......
......@@ -4,10 +4,9 @@ import artificial_intelligence.AIControler;
import core.relayer.Relayer;
import core.relayer.Relayers;
import logging.Logging;
import network.innershell.ClientConnection;
import network.innershell.LocalConnection;
import network.innershell.NetworkConnection;
import network.innershell.NetworkObject;
import network.inner_shell.ClientConnection;
import network.inner_shell.LocalConnection;
import network.inner_shell.NetworkConnection;
/**
* Created by dupriez on 12/11/15.
......
......@@ -9,9 +9,10 @@ import logging.Logging;
import map_generation.map.Map;
import map_generation.map.MapGeneration;
import map_generation.map.MapSize;
import network.innershell.EndEvent;
import network.innershell.NetworkConnection;
import network.innershell.ServerConnection;
import network.helpers.EndEvent;
import network.inner_shell.NetworkConnection;
import network.inner_shell.ServerConnection;
import network.outer_shell.Lounge;
/**
* This might also be a LocalServerLoop, it is just a thread object that cannot and should not be reused
......@@ -47,7 +48,7 @@ public class ServerLoop extends Thread {
nextMap= MapGeneration.mapGeneration(MapSize.SMALL);
int playerNumber;
if (networkConnection instanceof ServerConnection)
playerNumber=2;
playerNumber= Lounge.MAX_PLAYERS;
else
playerNumber=1;
GameContent gameContent=null;
......
package graphics.guiSkeleton.guiPanel.menuPanel;
import gameloop.DummyLocalGameLoop;
import graphics.graphical_abstraction.GraphicsMasterAbstraction;
import graphics.guiSkeleton.GUIColorsAndFonts;
import graphics.guiSkeleton.GraphicsMaster;
import graphics.guiSkeleton.guiPanel.menuPanel.facilities.ButtonMaker;
import graphics.guiSkeleton.guiPanel.menuPanel.facilities.MenuPanel;
import graphics.ingame_input_listener.Input;
import network.outershell.RPCClient;
import network.outershell.server.RPCServer;
import network.outer_shell.RPCClient;
import network.outer_shell.server.RPCServer;
import javax.swing.*;
import java.awt.event.ActionEvent;
......
package graphics.guiSkeleton.guiPanel.menuPanel.multiPlayer_MenuPanel;
import graphics.guiSkeleton.GUIColorsAndFonts;
import graphics.guiSkeleton.GraphicsMaster;
import network.outershell.Lounge;
import network.outershell.RPCClient;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
/**
* Created by dupriez on 07/12/15.
......
......@@ -10,8 +10,8 @@ import graphics.ingame_input_listener.Input;
import javax.swing.*;
import gameloop.GameStarter;
import network.outershell.Lounge;
import network.outershell.RPCClient;
import network.outer_shell.Lounge;
import network.outer_shell.RPCClient;
import java.awt.*;
import java.awt.event.ActionEvent;
......
......@@ -4,10 +4,9 @@ import gameloop.GameStarter;
import graphics.graphical_abstraction.GraphicsMasterAbstraction;
import graphics.guiSkeleton.GUIColorsAndFonts;
import graphics.guiSkeleton.GraphicsMaster;
import graphics.guiSkeleton.guiPanel.menuPanel.facilities.ButtonMaker;
import logging.Logging;
import network.outershell.Lounge;
import network.outershell.RPCClient;
import network.outer_shell.Lounge;
import network.outer_shell.RPCClient;
import javax.swing.*;
import java.awt.*;
......
package network.innershell;
package network.helpers;
import core.event.Event;
import core.gamestate.GameContent;
......
package network.innershell;
package network.helpers;
import gameloop.ServerLoop;
import logging.Logging;
import network.outershell.Lounge;
import network.inner_shell.ServerConnection;
import network.outer_shell.Lounge;
/**
* Created by bogdanbear on 20/11/2015.
*/
public class LoungeServer extends Thread {
public class LoungeServer extends Waitable implements Runnable{
private Lounge lounge;
private int numberOfPlayers;
public LoungeServer(Lounge lounge, int numberOfPlayers)
......@@ -27,21 +28,4 @@ public class LoungeServer extends Thread {
}
/**
* we need this wrapper because notify must be called inside a synchronized method
* to do - implement this and waitOnIt() as an interface.
*/
public synchronized void notifyOnIt()
{
notify();
}
public synchronized void waitOnIt()
{
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
package network.innershell;
package network.helpers;
import logging.Logging;
......
package network.test;
package network.helpers;
import core.event.Event;
import core.gamestate.GameContent;
......@@ -9,10 +9,10 @@ import core.gamestate.GameContent;
*/
public class TestEvent implements Event{
String testMessage;
private String testMessage;
public TestEvent(String string)
{
testMessage=string;
setTestMessage(string);
}
@Override
public boolean execute(GameContent gameContent) {
......@@ -25,4 +25,11 @@ public class TestEvent implements Event{
return this;
}
public String getTestMessage() {
return testMessage;
}
public void setTestMessage(String testMessage) {
this.testMessage = testMessage;
}
}
package network.helpers;
/**
* Created by bogdanbear on 06/01/2016.
* this abstract class is for objects which can be used for thread synchronization using notify and wait
* since these require that the object monitor is acquired, we have to use synchronized methods
*/
public abstract class Waitable {
/**
* we need this wrapper because notify must be called inside a synchronized method
* to do - implement this and waitOnIt() as an interface.
*/
public synchronized void notifyOnIt()
{
notify();
}
/**
* just wait on this object till notified by another thread
*/
public synchronized void waitOnIt()
{
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
package network.innershell;
package network.inner_shell;
import network.helpers.EndEvent;
import network.helpers.NetworkObject;
import java.io.IOException;
import java.io.NotSerializableException;
......
package network.innershell;
package network.inner_shell;
import logging.Logging;
import network.helpers.EndEvent;
import network.helpers.NetworkObject;
import java.io.EOFException;
import java.io.IOException;
......
package network.innershell;
package network.inner_shell;
import logging.Logging;
import network.helpers.NetworkObject;
import java.io.IOException;
import java.io.ObjectOutputStream;
......
package network.innershell;
package network.inner_shell;
import network.helpers.EndEvent;
import network.helpers.NetworkObject;
import java.util.NoSuchElementException;
import java.util.concurrent.BlockingDeque;
......
package network.innershell;
package network.inner_shell;
import logging.Logging;
import network.test.TestEvent;
import network.helpers.NetworkObject;
import network.helpers.TestEvent;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
......
package network.innershell;
package network.inner_shell;
import network.helpers.EndEvent;
import network.helpers.LoungeServer;
import network.helpers.NetworkObject;
import network.helpers.Waitable;
import java.io.IOException;
import java.net.ServerSocket;
......@@ -16,7 +21,7 @@ public class ServerConnection extends NetworkConnection{
/**
* toNotify Object is used to notify a thread that the ServerConnection constructor is ready to accept clients
*/
private Object toNotify;
private Waitable toNotify;
private boolean stillRunning=true;
private boolean disableLateJoining=true;
/**
......@@ -57,7 +62,7 @@ public class ServerConnection extends NetworkConnection{
/**
* @return the object which will be notifed when the serverconnection becomes ready
*/
public Object getToNotify() {
public Waitable getToNotify() {
return toNotify;
}
......@@ -104,7 +109,7 @@ public class ServerConnection extends NetworkConnection{
* @param numberOfClients
* @param toNotify is an object that will be notified when execution is complete, or null
*/
public ServerConnection(int PORT, int numberOfClients, int maxNumberOfLateClients, LoungeServer toNotify){
public ServerConnection(int PORT, int numberOfClients, int maxNumberOfLateClients, Waitable toNotify){
if (numberOfClients>0)
disableLateJoining=false;
this.maxNumberOfLateClients=maxNumberOfLateClients;
......
package network.junit_tests;
import network.innershell.ClientConnection;
import network.inner_shell.ClientConnection;
import org.junit.*;
import org.junit.runners.MethodSorters;
import java.io.IOException;
......
package network.junit_tests;
import network.innershell.LocalConnection;
import network.innershell.NetworkConnection;
import network.innershell.NetworkObject;
import network.inner_shell.LocalConnection;
import network.inner_shell.NetworkConnection;
import network.helpers.NetworkObject;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
......
package network.junit_tests;
import network.innershell.NetworkObject;
import network.helpers.NetworkObject;
/**
* Fake NetworkObject which do nothing.
......
package network.junit_tests;
import network.innershell.ServerConnection;
import network.inner_shell.ServerConnection;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
......@@ -14,8 +14,6 @@ import java.net.Socket;
import static org.junit.Assert.assertEquals;
import org.junit.runners.model.TestTimedOutException;
/**
* Class for JUnits test for the class ServerConnection.
* Created by mymi on 20/12/15.
......
package network.test;
package network.legacy_tests;
import network.innershell.ClientConnection;
import network.helpers.TestEvent;
import network.inner_shell.ClientConnection;
import java.io.*;
/**
......@@ -32,7 +33,7 @@ public class ConnectionEndTestClient {
TestEvent event = null;
while ((event = (TestEvent) clientConnection.receiveEvent(false)) != null) {
System.out.println(event.testMessage);
System.out.println(event.getTestMessage());
}
......
package network.test;
package network.legacy_tests;
import core.event.Event;
import logging.Logging;
import network.helpers.TestEvent;
import java.io.IOException;
import java.io.ObjectInputStream;
......@@ -32,7 +33,7 @@ public class DumbClient {
Event tester2=(Event)inputStream.readObject();
TestEvent tester3=(TestEvent)tester2;
System.out.println(tester3.testMessage);
System.out.println(tester3.getTestMessage());
}
catch (UnknownHostException e) {
......
package network.test;
package network.legacy_tests;
import core.event.Event;
import logging.Logging;
......
package network.test;
package network.legacy_tests;
import gameloop.ServerLoop;
import logging.Logging;
import network.innershell.NetworkObject;
import network.innershell.ServerConnection;
import network.inner_shell.ServerConnection;
/**
......
package network.test;
package network.legacy_tests;
import network.innershell.ClientConnection;
import network.helpers.TestEvent;
import network.inner_shell.ClientConnection;
import java.io.*;
......@@ -34,7 +35,7 @@ public class SimpleTestClient {
TestEvent event=null;
while ((event=(TestEvent)clientConnection.receiveEvent(false))!=null)
{
System.out.println(event.testMessage);
System.out.println(event.getTestMessage());
}
}
......
package network.test;
package network.legacy_tests;
import logging.Logging;
import network.innershell.NetworkObject;
import network.innershell.ServerConnection;
import network.helpers.NetworkObject;
import network.inner_shell.ServerConnection;
import java.util.logging.Logger;
......
package network.outershell;
package network.outer_shell;
import java.io.Serializable;
import java.util.ArrayList;
/**
* Created by bogdanbear on 03/01/2016.
......
package network.outershell;
package network.outer_shell;
import logging.Logging;
......
package network.outershell;
package network.outer_shell;
import network.outershell.Lounge;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.ArrayList;
......
package network.outershell.server;
package network.outer_shell.server;
import logging.Logging;
......
package network.outershell.server;
package network.outer_shell.server;
import logging.Logging;
import network.innershell.LoungeServer;
import network.outershell.Lounge;
import network.outershell.RegisterInterface;
import network.helpers.LoungeServer;
import network.outer_shell.Lounge;
import network.outer_shell.RegisterInterface;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
......@@ -14,6 +14,8 @@ import java.util.logging.Logger;
/**
* Created by bogdanbear on 02/01/2016.
* note on sunchronized methods - does not prevent simultaneous remote calls for two JVM (two clients)
but it works for one. (the pair client-server)
*/
......@@ -67,7 +69,7 @@ public class Registrar extends UnicastRemoteObject implements RegisterInterface
waiting.put(genID, lounge);
//instantiate a loungeServer on the serverside and then put it into motion
LoungeServer loungeServer=new LoungeServer(lounge,lounge.MAX_PLAYERS);
loungeServer.start();
(new Thread(loungeServer)).start();
loungeServer.waitOnIt();
......
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