mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
Merge remote-tracking branch 'origin/UI' into UI
This commit is contained in:
@@ -75,9 +75,8 @@ public final class MultiplayerLayer extends Layer {
|
||||
});
|
||||
} else {
|
||||
player1Container.addText(AppContext.getString("computerDifficulty"), true);
|
||||
player1Container.addSlider(5, computer1Difficulty, (difficulty) -> {
|
||||
computer1Difficulty = difficulty;
|
||||
});
|
||||
player1Container.addSlider(10, computer1Difficulty, (difficulty) ->
|
||||
computer1Difficulty = difficulty);
|
||||
}
|
||||
|
||||
if (isConnectionLocal) {
|
||||
@@ -93,9 +92,8 @@ public final class MultiplayerLayer extends Layer {
|
||||
});
|
||||
} else {
|
||||
player2Container.addText(AppContext.getString("computerDifficulty"), true);
|
||||
player2Container.addSlider(5, computer2Difficulty, (difficulty) -> {
|
||||
computer2Difficulty = difficulty;
|
||||
});
|
||||
player2Container.addSlider(10, computer2Difficulty, (difficulty) ->
|
||||
computer2Difficulty = difficulty);
|
||||
}
|
||||
} else {
|
||||
player2Container.addText(AppContext.getString("serverIP"), true);
|
||||
|
||||
@@ -7,6 +7,8 @@ import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.app.layer.layers.MainLayer;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.networking.events.NetworkEvents;
|
||||
import org.toop.game.Game;
|
||||
import org.toop.game.tictactoe.TicTacToe;
|
||||
import org.toop.game.tictactoe.TicTacToeAI;
|
||||
@@ -63,7 +65,13 @@ public final class TicTacToeLayer extends Layer {
|
||||
if (information.isConnectionLocal()) {
|
||||
new Thread(this::localGameThread).start();
|
||||
} else {
|
||||
new Thread(this::serverGameThread).start();
|
||||
new EventFlow()
|
||||
.addPostEvent(NetworkEvents.StartClient.class,
|
||||
information.serverIP(),
|
||||
Integer.parseInt(information.serverPort()))
|
||||
.onResponse(NetworkEvents.StartClientResponse.class, event ->
|
||||
new Thread(() -> serverGameThread(event)).start())
|
||||
.postEvent();
|
||||
}
|
||||
|
||||
reload();
|
||||
@@ -126,7 +134,8 @@ public final class TicTacToeLayer extends Layer {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
move = ticTacToeAI.findBestMove(ticTacToe, compurterDifficultyToDepth(5, information.computerDifficulty()[currentPlayer]));
|
||||
move = ticTacToeAI.findBestMove(ticTacToe, compurterDifficultyToDepth(10,
|
||||
information.computerDifficulty()[currentPlayer]));
|
||||
}
|
||||
|
||||
if (move == null) {
|
||||
@@ -153,11 +162,37 @@ public final class TicTacToeLayer extends Layer {
|
||||
}
|
||||
}
|
||||
|
||||
private void serverGameThread() {
|
||||
class OnlineGameState {
|
||||
public long clientId = -1;
|
||||
public long receivedMove = -1;
|
||||
}
|
||||
|
||||
private void serverGameThread(NetworkEvents.StartClientResponse event) {
|
||||
boolean running = true;
|
||||
final long clientId = event.clientId();
|
||||
final OnlineGameState onlineGameState = new OnlineGameState();
|
||||
onlineGameState.clientId = clientId;
|
||||
|
||||
new EventFlow()
|
||||
.listen(NetworkEvents.GameMoveResponse.class,respEvent -> onMoveResponse(onlineGameState, respEvent));
|
||||
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendLogin(clientId, information.playerName()[0]))
|
||||
.postEvent();
|
||||
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendSubscribe(clientId, "tic-tac-toe"))
|
||||
.postEvent();
|
||||
|
||||
while (running) {
|
||||
final int currentPlayer = ticTacToe.getCurrentTurn();
|
||||
}
|
||||
}
|
||||
|
||||
private void onMoveResponse(OnlineGameState ogs, NetworkEvents.GameMoveResponse resp) {
|
||||
}
|
||||
|
||||
private void serverGameThreadResponseHandler(OnlineGameState ogs, NetworkEvents.ChallengeResponse msg) {
|
||||
if (msg.clientId() != ogs.clientId) return;
|
||||
IO.println("Client ID: " + ogs.clientId + " Received Message: " + msg);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user