network structure
Some checks failed
Linux arm64 / Build (push) Failing after 5m1s

This commit is contained in:
2025-01-23 18:59:11 +01:00
parent b05351bc20
commit 5e99cd92df
21 changed files with 429 additions and 36 deletions

View File

@@ -12,6 +12,8 @@ public abstract class BaseView {
public abstract void render();
public void onKill() {}
public void closeMenu() {
this.stateMachine.popState();
}

View File

@@ -1,17 +0,0 @@
package gui.menu;
import imgui.ImGui;
public class CreateGameMenu extends BaseView {
public CreateGameMenu(StateMachine stateMachine) {
super(stateMachine);
}
@Override
public void render() {
ImGui.text("Créer");
renderReturnButton();
}
}

View File

@@ -1,17 +0,0 @@
package gui.menu;
import imgui.ImGui;
public class JoinGameMenu extends BaseView {
public JoinGameMenu(StateMachine stateMachine) {
super(stateMachine);
}
@Override
public void render() {
ImGui.text("Rejoindre");
renderReturnButton();
}
}

View File

@@ -1,15 +1,22 @@
package gui.menu;
import java.io.IOException;
import imgui.ImGui;
import imgui.ImVec2;
import imgui.type.ImInt;
import imgui.type.ImString;
import network.client.Client;
import network.server.Server;
public class MultiMenu extends BaseView {
private final ImInt port = new ImInt(25565);
private final ImString address = new ImString("localhost");
private Server server;
private Client client;
public MultiMenu(StateMachine stateMachine) {
super(stateMachine);
}
@@ -19,7 +26,11 @@ public class MultiMenu extends BaseView {
ImGui.beginChild("##CreateGame", new ImVec2(displaySize.x / 2.0f, displaySize.y * 8.0f / 9.0f));
ImGui.inputInt("Port", port);
if (ImGui.button("Créer")) {
// TODO: create game
try {
this.stateMachine.pushState(new MultiPlayerView(stateMachine, (short) port.get()));
} catch (IOException e) {
e.printStackTrace();
}
}
ImGui.endChild();
}
@@ -30,7 +41,12 @@ public class MultiMenu extends BaseView {
ImGui.inputText("Adresse", address);
ImGui.inputInt("Port", port);
if (ImGui.button("Rejoindre")) {
// TODO: join game
try {
this.stateMachine.pushState(new MultiPlayerView(stateMachine, address.get(), (short) port.get()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
ImGui.endChild();
}

View File

@@ -0,0 +1,58 @@
package gui.menu;
import java.io.IOException;
import java.net.UnknownHostException;
import imgui.ImGui;
import network.client.Client;
import network.server.Server;
public class MultiPlayerView extends BaseView {
private Client client;
private Server server;
/**
* Client
*
* @param stateMachine
* @param address
* @param port
* @throws IOException
* @throws UnknownHostException
*/
public MultiPlayerView(StateMachine stateMachine, String address, short port)
throws UnknownHostException, IOException {
super(stateMachine);
this.client = new Client(address, port);
}
/**
* Server
*
* @param stateMachine
* @param port
* @throws IOException
*/
public MultiPlayerView(StateMachine stateMachine, short port) throws IOException {
super(stateMachine);
this.server = new Server(port);
this.client = new Client("localhost", port);
}
@Override
public void onKill() {
if (this.server != null) {
this.server.stop();
}
if (this.client != null) {
this.client.stop();
}
}
@Override
public void render() {
ImGui.text("Tema le gameplay");
}
}

View File

@@ -15,11 +15,19 @@ public class StateMachine {
this.menus = new Stack<>();
}
public void clear() {
for (BaseView view : menus) {
view.onKill();
}
menus.clear();
}
public void pushState(BaseView menu) {
menus.add(menu);
}
public void popState() {
menus.getLast().onKill();
menus.pop();
}