mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Terminated the game server socket when click exit lobby button
- the whole server thread should be terminated instead. To be fixed in the future. #story[1047] #issue[28]
This commit is contained in:
@@ -8,6 +8,7 @@ import javafx.scene.layout.AnchorPane;
|
|||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
|
import seng302.gameServer.GameServerThread;
|
||||||
import seng302.gameServer.GameStages;
|
import seng302.gameServer.GameStages;
|
||||||
import seng302.gameServer.GameState;
|
import seng302.gameServer.GameState;
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ public class LobbyController {
|
|||||||
@FXML
|
@FXML
|
||||||
private TableColumn readyTableColumn;
|
private TableColumn readyTableColumn;
|
||||||
|
|
||||||
|
private GameServerThread gameServerThread;
|
||||||
|
|
||||||
private void setContentPane(String jfxUrl) {
|
private void setContentPane(String jfxUrl) {
|
||||||
try {
|
try {
|
||||||
@@ -54,7 +56,8 @@ public class LobbyController {
|
|||||||
// TODO: 10/07/17 wmu16 - Finish function!
|
// TODO: 10/07/17 wmu16 - Finish function!
|
||||||
setContentPane("/views/StartScreenView.fxml");
|
setContentPane("/views/StartScreenView.fxml");
|
||||||
System.out.println("Leaving lobby!");
|
System.out.println("Leaving lobby!");
|
||||||
|
GameState.setCurrentStage(GameStages.CANCELLED);
|
||||||
|
gameServerThread.terminateGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -62,4 +65,8 @@ public class LobbyController {
|
|||||||
public void readyButtonPressed() {
|
public void readyButtonPressed() {
|
||||||
GameState.setCurrentStage(GameStages.RACING);
|
GameState.setCurrentStage(GameStages.RACING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setGameServerThread(GameServerThread gameServerThread) {
|
||||||
|
this.gameServerThread = gameServerThread;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package seng302.controllers;
|
|||||||
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
@@ -25,20 +26,27 @@ public class StartScreenController {
|
|||||||
@FXML
|
@FXML
|
||||||
private GridPane startScreen2;
|
private GridPane startScreen2;
|
||||||
|
|
||||||
|
/**
|
||||||
private void setContentPane(String jfxUrl) {
|
* Loads the fxml content into the parent pane
|
||||||
|
* @param jfxUrl
|
||||||
|
* @return the controller of the fxml
|
||||||
|
*/
|
||||||
|
private Object setContentPane(String jfxUrl) {
|
||||||
try {
|
try {
|
||||||
AnchorPane contentPane = (AnchorPane) startScreen2.getParent();
|
AnchorPane contentPane = (AnchorPane) startScreen2.getParent();
|
||||||
contentPane.getChildren().removeAll();
|
contentPane.getChildren().removeAll();
|
||||||
contentPane.getChildren().clear();
|
contentPane.getChildren().clear();
|
||||||
contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
|
contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
|
||||||
contentPane.getChildren()
|
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(jfxUrl));
|
||||||
.addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
|
contentPane.getChildren().addAll((Pane) fxmlLoader.load());
|
||||||
|
|
||||||
|
return fxmlLoader.getController();
|
||||||
} catch (javafx.fxml.LoadException e) {
|
} catch (javafx.fxml.LoadException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -53,9 +61,13 @@ public class StartScreenController {
|
|||||||
try {
|
try {
|
||||||
String ipAddress = InetAddress.getLocalHost().getHostAddress();
|
String ipAddress = InetAddress.getLocalHost().getHostAddress();
|
||||||
new GameState(ipAddress);
|
new GameState(ipAddress);
|
||||||
new GameServerThread("Game Server");
|
GameServerThread gameServerThread = new GameServerThread("Game Server");
|
||||||
System.out.println("Server thread started");
|
System.out.println("Server thread started");
|
||||||
setContentPane("/views/LobbyView.fxml");
|
|
||||||
|
// get the lobby controller so that we can pass the game server thread to it
|
||||||
|
LobbyController lobbyController = (LobbyController) setContentPane("/views/LobbyView.fxml");
|
||||||
|
lobbyController.setGameServerThread(gameServerThread);
|
||||||
|
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
System.err.println("COULD NOT FIND YOUR IP ADDRESS!");
|
System.err.println("COULD NOT FIND YOUR IP ADDRESS!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -256,8 +256,9 @@ public class GameServerThread implements Runnable, Observer, ClientConnectionDel
|
|||||||
}
|
}
|
||||||
|
|
||||||
acceptConnection();
|
acceptConnection();
|
||||||
acceptConnection();
|
|
||||||
// acceptConnection();
|
// acceptConnection();
|
||||||
|
// acceptConnection();
|
||||||
|
System.out.println("well, hit here now");
|
||||||
|
|
||||||
for (Player player : GameState.getPlayers()) {
|
for (Player player : GameState.getPlayers()) {
|
||||||
System.out.println(player);
|
System.out.println(player);
|
||||||
@@ -399,4 +400,13 @@ public class GameServerThread implements Runnable, Observer, ClientConnectionDel
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
public void terminateGame() {
|
||||||
|
try {
|
||||||
|
//TODO: for now, I just close the socket, but i think we should terminate the whole thread instead. -hyi25 13 July
|
||||||
|
server.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ public enum GameStages {
|
|||||||
LOBBYING(0),
|
LOBBYING(0),
|
||||||
PRE_RACE(1),
|
PRE_RACE(1),
|
||||||
RACING(2),
|
RACING(2),
|
||||||
FINISHED(3);
|
FINISHED(3),
|
||||||
|
CANCELLED(4);
|
||||||
|
|
||||||
private long code;
|
private long code;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user