Added second player to initial form

This commit is contained in:
lieght
2025-09-17 20:31:50 +02:00
parent 032d388f4f
commit 5eb6e8ea37
4 changed files with 77 additions and 60 deletions

2
.idea/workspace.xml generated
View File

@@ -6,9 +6,9 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="997b32da-b4d4-48ac-ab51-52d65f364f81" name="Changes" comment=""> <list default="true" id="997b32da-b4d4-48ac-ab51-52d65f364f81" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/toop/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/toop/UI/GameSelectorWindow.form" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/UI/GameSelectorWindow.form" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/org/toop/UI/GameSelectorWindow.form" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/UI/GameSelectorWindow.form" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/toop/UI/GameSelectorWindow.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/UI/GameSelectorWindow.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/org/toop/UI/GameSelectorWindow.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/UI/GameSelectorWindow.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/toop/server/backend/TcpServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/server/backend/TcpServer.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.toop.UI.GameSelectorWindow"> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.toop.UI.GameSelectorWindow">
<grid id="27dc6" binding="mainMenu" layout-manager="GridLayoutManager" row-count="8" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="27dc6" binding="mainMenu" layout-manager="GridLayoutManager" row-count="9" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/> <margin top="10" left="10" bottom="10" right="10"/>
<constraints> <constraints>
<xy x="20" y="20" width="500" height="400"/> <xy x="20" y="20" width="500" height="400"/>
@@ -23,7 +23,7 @@
</component> </component>
<vspacer id="4e05c"> <vspacer id="4e05c">
<constraints> <constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> <grid row="8" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
</vspacer> </vspacer>
<component id="1d2f1" class="javax.swing.JLabel"> <component id="1d2f1" class="javax.swing.JLabel">
@@ -42,7 +42,7 @@
<text value="Welcome to ISY games selector!"/> <text value="Welcome to ISY games selector!"/>
</properties> </properties>
</component> </component>
<component id="5cc82" class="javax.swing.JTextField" binding="ipTextField"> <component id="5cc82" class="javax.swing.JTextField" binding="name2TextField">
<constraints> <constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"> <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/> <preferred-size width="150" height="-1"/>
@@ -52,62 +52,14 @@
<text value=""/> <text value=""/>
</properties> </properties>
</component> </component>
<component id="26a0" class="javax.swing.JTextField" binding="portTextField">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="3abc3" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Port:"/>
</properties>
</component>
<component id="514db" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="IP:"/>
</properties>
</component>
<hspacer id="27f2a"> <hspacer id="27f2a">
<constraints> <constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
</hspacer> </hspacer>
<component id="a2f0" class="javax.swing.JButton" binding="connectButton" default-binding="true">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Connect"/>
</properties>
</component>
<component id="4214e" class="javax.swing.JComboBox" binding="gameSelectorBox">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model/>
</properties>
</component>
<component id="43a89" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Select game:"/>
</properties>
</component>
<component id="3874e" class="javax.swing.JLabel" binding="fillAllFields"> <component id="3874e" class="javax.swing.JLabel" binding="fillAllFields">
<constraints> <constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<enabled value="true"/> <enabled value="true"/>
@@ -116,6 +68,70 @@
<visible value="false"/> <visible value="false"/>
</properties> </properties>
</component> </component>
<component id="a2f0" class="javax.swing.JButton" binding="connectButton" default-binding="true">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Connect"/>
</properties>
</component>
<component id="6a4c6" class="javax.swing.JTextField" binding="ipTextField">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="4214e" class="javax.swing.JComboBox" binding="gameSelectorBox">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model/>
</properties>
</component>
<component id="4225c" class="javax.swing.JTextField" binding="portTextField">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="43a89" class="javax.swing.JLabel">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Select game:"/>
</properties>
</component>
<component id="3abc3" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Port:"/>
</properties>
</component>
<component id="514db" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="IP:"/>
</properties>
</component>
<component id="5723c" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Name 2:"/>
</properties>
</component>
</children> </children>
</grid> </grid>
</form> </form>

View File

@@ -4,7 +4,6 @@ import org.toop.eventbus.GlobalEventBus;
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.*;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@@ -13,6 +12,7 @@ import java.util.concurrent.ExecutionException;
public class GameSelectorWindow extends JFrame { public class GameSelectorWindow extends JFrame {
private JPanel mainMenu; private JPanel mainMenu;
private JTextField nameTextField; private JTextField nameTextField;
private JTextField name2TextField;
private JTextField ipTextField; private JTextField ipTextField;
private JTextField portTextField; private JTextField portTextField;
private JButton connectButton; private JButton connectButton;
@@ -40,6 +40,7 @@ public class GameSelectorWindow extends JFrame {
private void init() { private void init() {
connectButton.addActionListener((ActionEvent e) -> { connectButton.addActionListener((ActionEvent e) -> {
if( !nameTextField.getText().isEmpty() && if( !nameTextField.getText().isEmpty() &&
!name2TextField.getText().isEmpty() &&
!ipTextField.getText().isEmpty() && !ipTextField.getText().isEmpty() &&
!portTextField.getText().isEmpty()) { !portTextField.getText().isEmpty()) {
@@ -73,7 +74,7 @@ public class GameSelectorWindow extends JFrame {
GlobalEventBus.post(new Events.ServerEvents.CreateTicTacToeGameRequest( // TODO: Make this happen through commands send through the connection, instead of an event. GlobalEventBus.post(new Events.ServerEvents.CreateTicTacToeGameRequest( // TODO: Make this happen through commands send through the connection, instead of an event.
serverId, serverId,
nameTextField.getText(), nameTextField.getText(),
"P", name2TextField.getText(),
ticTacToeGame ticTacToeGame
)); ));
String ticTacToeGameId; String ticTacToeGameId;

View File

@@ -34,10 +34,10 @@ public class TcpServer implements Runnable {
protected final ExecutorService connectionExecutor = Executors.newCachedThreadPool(); protected final ExecutorService connectionExecutor = Executors.newCachedThreadPool();
// Shared queues for subclasses / consumers // Shared queues for subclasses / consumers
public final BlockingQueue<String> receivedQueue = new LinkedBlockingQueue<>(); // unbounded; you may choose bounded public final BlockingQueue<String> receivedQueue = new LinkedBlockingQueue<>();
public final BlockingQueue<String> sendQueue = new LinkedBlockingQueue<>(); public final BlockingQueue<String> sendQueue = new LinkedBlockingQueue<>();
// (Optional) if you want to associate sockets -> player ids // Association for sockets -> player ids
public final Map<Socket, String> knownPlayers = new ConcurrentHashMap<>(); public final Map<Socket, String> knownPlayers = new ConcurrentHashMap<>();
public final Map<String, String> playersGames = new ConcurrentHashMap<>(); public final Map<String, String> playersGames = new ConcurrentHashMap<>();
@@ -157,7 +157,7 @@ public class TcpServer implements Runnable {
} }
}; };
// Submit tasks - they will run on the shared connectionExecutor // Input and Output mappings
connectionExecutor.submit(inputTask); connectionExecutor.submit(inputTask);
connectionExecutor.submit(outputTask); connectionExecutor.submit(outputTask);