This commit is contained in:
@@ -15,6 +15,11 @@ public class Main extends Application {
|
||||
config.setTitle("Let's play sudoku!");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disposeWindow() {
|
||||
stateMachine.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initImGui(Configuration config) {
|
||||
super.initImGui(config);
|
||||
|
||||
@@ -12,6 +12,8 @@ public abstract class BaseView {
|
||||
|
||||
public abstract void render();
|
||||
|
||||
public void onKill() {}
|
||||
|
||||
public void closeMenu() {
|
||||
this.stateMachine.popState();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
58
app/src/main/java/gui/menu/MultiPlayerView.java
Normal file
58
app/src/main/java/gui/menu/MultiPlayerView.java
Normal 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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user