This commit is contained in:
@@ -14,12 +14,12 @@ public class ConnexionStatusView extends BaseView {
|
|||||||
|
|
||||||
private String displayText = "Connecting ...";
|
private String displayText = "Connecting ...";
|
||||||
|
|
||||||
public ConnexionStatusView(StateMachine stateMachine, String address, short port)
|
public ConnexionStatusView(StateMachine stateMachine, String pseudo, String address, short port)
|
||||||
throws UnknownHostException, IOException {
|
throws UnknownHostException, IOException {
|
||||||
super(stateMachine);
|
super(stateMachine);
|
||||||
Thread t = new Thread(() -> {
|
Thread t = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
this.client = new Client(address, port);
|
this.client = new Client(pseudo, address, port);
|
||||||
bindListeners();
|
bindListeners();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -29,12 +29,13 @@ public class ConnexionStatusView extends BaseView {
|
|||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnexionStatusView(StateMachine stateMachine, short port) throws UnknownHostException, IOException {
|
public ConnexionStatusView(StateMachine stateMachine, String pseudo, short port)
|
||||||
|
throws UnknownHostException, IOException {
|
||||||
super(stateMachine);
|
super(stateMachine);
|
||||||
Thread t = new Thread(() -> {
|
Thread t = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
this.server = new Server(port);
|
this.server = new Server(port);
|
||||||
this.client = new Client("localhost", port);
|
this.client = new Client(pseudo, "localhost", port);
|
||||||
bindListeners();
|
bindListeners();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package gui.menu;
|
package gui.menu;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.ImVec2;
|
import imgui.ImVec2;
|
||||||
@@ -11,6 +12,7 @@ public class MultiMenu extends BaseView {
|
|||||||
|
|
||||||
private final ImInt port = new ImInt(25565);
|
private final ImInt port = new ImInt(25565);
|
||||||
private final ImString address = new ImString("localhost");
|
private final ImString address = new ImString("localhost");
|
||||||
|
private final ImString pseudo = new ImString("Joueur" + new Random().nextInt());
|
||||||
|
|
||||||
public MultiMenu(StateMachine stateMachine) {
|
public MultiMenu(StateMachine stateMachine) {
|
||||||
super(stateMachine);
|
super(stateMachine);
|
||||||
@@ -22,9 +24,10 @@ public class MultiMenu extends BaseView {
|
|||||||
ImGui.beginChild("##CreateGame", new ImVec2(displaySize.x / 2.0f, displaySize.y * 8.0f / 9.0f));
|
ImGui.beginChild("##CreateGame", new ImVec2(displaySize.x / 2.0f, displaySize.y * 8.0f / 9.0f));
|
||||||
if (ImGui.inputInt("Port", port))
|
if (ImGui.inputInt("Port", port))
|
||||||
port.set(Math.clamp(port.get(), 1, 65535));
|
port.set(Math.clamp(port.get(), 1, 65535));
|
||||||
|
ImGui.inputText("Pseudo", pseudo);
|
||||||
if (ImGui.button("Créer")) {
|
if (ImGui.button("Créer")) {
|
||||||
try {
|
try {
|
||||||
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, (short) port.get()));
|
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, pseudo.get(), (short) port.get()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -38,6 +41,7 @@ public class MultiMenu extends BaseView {
|
|||||||
ImGui.inputText("Adresse", address);
|
ImGui.inputText("Adresse", address);
|
||||||
if (ImGui.inputInt("Port", port))
|
if (ImGui.inputInt("Port", port))
|
||||||
port.set(Math.clamp(port.get(), 1, 65535));
|
port.set(Math.clamp(port.get(), 1, 65535));
|
||||||
|
ImGui.inputText("Pseudo", pseudo);
|
||||||
if (ImGui.button("Rejoindre")) {
|
if (ImGui.button("Rejoindre")) {
|
||||||
try {
|
try {
|
||||||
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, address.get(), (short) port.get()));
|
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, address.get(), (short) port.get()));
|
||||||
|
|||||||
@@ -28,12 +28,10 @@ public class Client {
|
|||||||
|
|
||||||
String disconnectReason = null;
|
String disconnectReason = null;
|
||||||
|
|
||||||
public Client(String address, short port) throws UnknownHostException, IOException {
|
public Client(String pseudo, String address, short port) throws UnknownHostException, IOException {
|
||||||
this.clientConnection = new ClientConnexion(address, port, this);
|
this.clientConnection = new ClientConnexion(address, port, this);
|
||||||
this.game = new Game();
|
this.game = new Game();
|
||||||
// temp
|
login(pseudo);
|
||||||
Random r = new Random();
|
|
||||||
login("Player" + r.nextInt());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void login(String pseudo) {
|
public void login(String pseudo) {
|
||||||
|
|||||||
Reference in New Issue
Block a user