Commit 71477736 authored by Bogdan's avatar Bogdan
Browse files

Lounges almost done - still need to modify ServerLoop + add Please wait panel

parent 8f78310b
......@@ -27,6 +27,7 @@ public class Igniter_Main {
/** Launch the GUI (and thus the game) **/
GraphicsMaster.build();
GraphicsMasterAbstraction gm = GraphicsMasterAbstraction.getInstance();
System.out.println("Starting GUI...");
gm.launchGUI();
}
}
......@@ -33,10 +33,10 @@ public class MultiPlayer_MenuPanel extends MenuPanel {
inputLabel.setForeground(GUIColorsAndFonts.fontColor1);
setTitlePanel("MultiPlayer Thessia");
//addToCentralColumn(ButtonMaker.makeButton("Join Lounge", joinLoungeButton_ActionListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("Refresh Lounges List", refreshGameButton_ActionListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("Create a new game", hostNewGameButton_ActionListener),1,1);
addToCentralColumn(inputLabel,1,1);
addToCentralColumn(new LoungeList_SubPanel(getGraphicsMaster()),1,1);
addToCentralColumn(ButtonMaker.makeButton("Refresh Lounges List", refreshGameButton_ActionListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("Create a new game", hostNewGameButton_ActionListener),1,1);
JButton oldPlayButton = ButtonMaker.makeButton("Old play button", oldPlayButton_ActionListener);
oldPlayButton.setBackground(new Color(174,0,0));
addToCentralColumn(oldPlayButton, 1, 1);
......@@ -49,9 +49,10 @@ public class MultiPlayer_MenuPanel extends MenuPanel {
Lounge lounge=RPCClient.createLounge("test");
if (lounge!=null) {
//there have been no errors in lounge creation
getGraphicsMaster().changeGUIStateTo(GraphicsMasterAbstraction.GUIStates.PLEASE_WAIT);
RPCClient.joinLounge(lounge.getLoungeID());
GameStarter.startGameMultiplayerPlayer(RPCClient.getIp(),lounge.getPort());
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.PLEASE_WAIT);
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.GAME_PANEL);
}
}
};
......@@ -72,6 +73,10 @@ public class MultiPlayer_MenuPanel extends MenuPanel {
scrollPane.getViewport().add(listPanel);
add(scrollPane);
}
LoungeList_SubPanel.getUniqueInstance().removeAll();
LoungeList_SubPanel.getUniqueInstance().add(listPanel);
LoungeList_SubPanel.getUniqueInstance().revalidate();
LoungeList_SubPanel.getUniqueInstance().repaint();
}
};
......
......@@ -47,6 +47,8 @@ public class PickLoungeSubPanelFactory {
graphicsMaster.changeGUIStateTo(GraphicsMasterAbstraction.GUIStates.PLEASE_WAIT);
Logging.getInstance().getLogger().info("PickLoungeSubPanel in the PickLoungeSubPanelFactory: server gives green light. Initiate join...");
GameStarter.startGameMultiplayerPlayer(RPCClient.getIp(),lounge.getPort());
graphicsMaster.changeGUIStateTo(GraphicsMaster.GUIStates.GAME_PANEL);
graphicsMaster.changeGUIStateTo(GraphicsMaster.GUIStates.GAME_PANEL);
}
else{
Logging.getInstance().getLogger().warning("PickLoungeSubPanel in the PickLoungeSubPanelFactory: join failed");
......
......@@ -19,7 +19,7 @@ public class LoungeServer extends Thread {
@Override
public void run()
{
ServerConnection serverConnection=new ServerConnection(lounge.getPort(),lounge.MAX_PLAYERS,0);
ServerConnection serverConnection=new ServerConnection(lounge.getPort(),lounge.MAX_PLAYERS,0,this);
Logging.getInstance().getLogger().info("Server started second phase, initialization done");
ServerLoop dummyServerLoop=new ServerLoop(serverConnection);
......@@ -27,6 +27,15 @@ 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 {
......
......@@ -102,8 +102,9 @@ public class ServerConnection extends NetworkConnection{
* It waits for all clients before to end.
* @param PORT port to communicate for the server
* @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){
public ServerConnection(int PORT, int numberOfClients, int maxNumberOfLateClients, LoungeServer toNotify){
if (numberOfClients>0)
disableLateJoining=false;
this.maxNumberOfLateClients=maxNumberOfLateClients;
......@@ -113,6 +114,8 @@ public class ServerConnection extends NetworkConnection{
int nr=0;
while(nr<numberOfClients)
{
if (toNotify!=null)
toNotify.notifyOnIt();
Socket socket=serverSocket.accept();
ClientInputThread clientInputThread=new ClientInputThread(socket,this,true,incomingEvents.size());
ClientOutputThread clientOutputThread=new ClientOutputThread(socket,this,outputThreads.size());
......@@ -135,8 +138,6 @@ public class ServerConnection extends NetworkConnection{
}
}
/**
* Send an event to all clients.
* In extreme circumstances, if the outgoing queues become so full that they reach MaxINT number of elements,
......
......@@ -37,7 +37,7 @@ public class ServerConnectionTest{
}
public void run(){
server = new ServerConnection(PORT,2,0);
server = new ServerConnection(PORT,2,0,null);
notify();
}
......
......@@ -12,7 +12,7 @@ import network.innershell.ServerConnection;
public class DummyServer {
public static void main(String[] args)
{
ServerConnection serverConnection=new ServerConnection(8888,2,0);
ServerConnection serverConnection=new ServerConnection(8888,2,0,null);
Logging.getInstance().getLogger().info("Server started second phase, initialization done");
ServerLoop dummyServerLoop=new ServerLoop(serverConnection);
......
......@@ -16,7 +16,7 @@ public class SimpleTestServer {
public static void main(String[] args)
{
//For the constructor, 8888 is the port and 2 is the number of expected clients
ServerConnection serverConnection=new ServerConnection(8888,2,0);
ServerConnection serverConnection=new ServerConnection(8888,2,0,null);
Logger LOGGER = Logging.getInstance().getLogger();
while (true)
{
......
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