mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge branch 'Story62_Reading_Keystrokes' into Story62_Creating_Game_Loop
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
package seng302.controllers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
@@ -11,8 +16,8 @@ import javafx.scene.text.Text;
|
||||
import seng302.gameServer.GameServerThread;
|
||||
import seng302.gameServer.GameStages;
|
||||
import seng302.gameServer.GameState;
|
||||
|
||||
import java.io.IOException;
|
||||
import seng302.gameServerWithThreading.MainServerThread;
|
||||
import seng302.gameServerWithThreading.ServerToClientThread;
|
||||
|
||||
/**
|
||||
* A class describing the actions of the lobby screen
|
||||
@@ -20,12 +25,15 @@ import java.io.IOException;
|
||||
*/
|
||||
public class LobbyController {
|
||||
|
||||
@FXML
|
||||
private ListView competitorsListView;
|
||||
@FXML
|
||||
private GridPane lobbyScreen;
|
||||
@FXML
|
||||
private Text lobbyIpText;
|
||||
|
||||
private GameServerThread gameServerThread;
|
||||
private static ObservableList competitors;
|
||||
|
||||
private void setContentPane(String jfxUrl) {
|
||||
try {
|
||||
@@ -42,6 +50,11 @@ public class LobbyController {
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
competitors = FXCollections.observableArrayList();
|
||||
competitorsListView.setItems(competitors);
|
||||
}
|
||||
|
||||
|
||||
@FXML
|
||||
public void leaveLobbyButtonPressed() {
|
||||
@@ -52,6 +65,11 @@ public class LobbyController {
|
||||
gameServerThread.terminateGame();
|
||||
}
|
||||
|
||||
public static void refreshCompetitors(){
|
||||
Collection<String> competitorsIps = MainServerThread.getServerToClientThreads();
|
||||
competitors.clear();
|
||||
competitors.addAll(competitorsIps);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void readyButtonPressed() {
|
||||
|
||||
@@ -80,10 +80,14 @@ public class StartScreenController {
|
||||
public void connectButtonPressed() {
|
||||
// TODO: 10/07/17 wmu16 - Finish function
|
||||
String ipAddress = ipTextField.getText().trim().toLowerCase();
|
||||
ClientToServerThread clientToServerThread = new ClientToServerThread(ipAddress, 4950);
|
||||
controller.setClientToServerThread(clientToServerThread);
|
||||
clientToServerThread.start();
|
||||
|
||||
try {
|
||||
ClientToServerThread clientToServerThread = new ClientToServerThread(ipAddress, 4950);
|
||||
controller.setClientToServerThread(clientToServerThread);
|
||||
clientToServerThread.start();
|
||||
setContentPane("/views/LobbyView.fxml");
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setController(Controller controller) {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package seng302.gameServerWithThreading;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import javafx.application.Platform;
|
||||
import seng302.controllers.LobbyController;
|
||||
import seng302.gameServer.GameStages;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.models.stream.PacketBufferDelegate;
|
||||
@@ -19,11 +23,11 @@ import java.util.concurrent.PriorityBlockingQueue;
|
||||
public class MainServerThread extends Thread implements PacketBufferDelegate{
|
||||
|
||||
private static final int PORT = 4950;
|
||||
private static final Integer MAX_NUM_PLAYERS = 1;
|
||||
private static final Integer MAX_NUM_PLAYERS = 3;
|
||||
|
||||
private ServerSocket serverSocket = null;
|
||||
private Socket socket;
|
||||
private ArrayList<ServerToClientThread> serverToClientThreads = new ArrayList<>();
|
||||
private static ArrayList<ServerToClientThread> serverToClientThreads = new ArrayList<>();
|
||||
|
||||
private PriorityBlockingQueue<StreamPacket> packetBuffer;
|
||||
|
||||
@@ -47,7 +51,6 @@ public class MainServerThread extends Thread implements PacketBufferDelegate{
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//LOBBYING
|
||||
if (GameState.getCurrentStage() == GameStages.LOBBYING && GameState.getPlayers().size() < MAX_NUM_PLAYERS) {
|
||||
try {
|
||||
@@ -58,6 +61,9 @@ public class MainServerThread extends Thread implements PacketBufferDelegate{
|
||||
}
|
||||
ServerToClientThread thread = new ServerToClientThread(socket, this);
|
||||
serverToClientThreads.add(thread);
|
||||
System.out.println("[SERVER]: Client found");
|
||||
// Platform.runLater() is used to update the UI from within a thread (found on stack overflow)
|
||||
Platform.runLater(LobbyController::refreshCompetitors);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
@@ -72,7 +78,7 @@ public class MainServerThread extends Thread implements PacketBufferDelegate{
|
||||
|
||||
}
|
||||
|
||||
updateClients();
|
||||
// updateClients();
|
||||
|
||||
while (!packetBuffer.isEmpty()){
|
||||
System.out.println("WHATUPPP");
|
||||
@@ -108,4 +114,13 @@ public class MainServerThread extends Thread implements PacketBufferDelegate{
|
||||
System.out.println("HEY HI");
|
||||
return packetBuffer.add(streamPacket);
|
||||
}
|
||||
|
||||
|
||||
public static Collection getServerToClientThreads() {
|
||||
Collection<String> ips = new ArrayList<>();
|
||||
for (ServerToClientThread serverToClientThread: serverToClientThreads){
|
||||
ips.add(serverToClientThread.getName());
|
||||
}
|
||||
return Collections.synchronizedCollection(ips);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<GridPane fx:id="lobbyScreen" nodeOrientation="LEFT_TO_RIGHT" prefHeight="533.0" prefWidth="802.0" style="-fx-background-color: #2C2c36;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.LobbyController">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="171.0" minHeight="0.0" prefHeight="31.0" vgrow="SOMETIMES" />
|
||||
@@ -41,6 +41,27 @@
|
||||
<Button focusTraversable="false" mnemonicParsing="false" onAction="#leaveLobbyButtonPressed" text="Leave Lobby" GridPane.columnIndex="1" GridPane.halignment="CENTER" />
|
||||
</children>
|
||||
</GridPane>
|
||||
<AnchorPane focusTraversable="true" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1" />
|
||||
<AnchorPane focusTraversable="true" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
|
||||
<children>
|
||||
<GridPane layoutX="335.0" layoutY="146.0" prefHeight="399.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="261.0" minWidth="0.0" prefWidth="2.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="-Infinity" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="261.0" minWidth="0.0" prefWidth="2.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="125.0" minHeight="0.0" prefHeight="0.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="266.0" minHeight="10.0" prefHeight="266.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
|
||||
<children>
|
||||
<ListView fx:id="competitorsListView" layoutX="154.0" layoutY="59.0" prefHeight="266.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</children>
|
||||
</GridPane>
|
||||
</children></AnchorPane>
|
||||
</children>
|
||||
</GridPane>
|
||||
|
||||
Reference in New Issue
Block a user