mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +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 {
|
} else {
|
||||||
player1Container.addText(AppContext.getString("computerDifficulty"), true);
|
player1Container.addText(AppContext.getString("computerDifficulty"), true);
|
||||||
player1Container.addSlider(5, computer1Difficulty, (difficulty) -> {
|
player1Container.addSlider(10, computer1Difficulty, (difficulty) ->
|
||||||
computer1Difficulty = difficulty;
|
computer1Difficulty = difficulty);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isConnectionLocal) {
|
if (isConnectionLocal) {
|
||||||
@@ -93,9 +92,8 @@ public final class MultiplayerLayer extends Layer {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
player2Container.addText(AppContext.getString("computerDifficulty"), true);
|
player2Container.addText(AppContext.getString("computerDifficulty"), true);
|
||||||
player2Container.addSlider(5, computer2Difficulty, (difficulty) -> {
|
player2Container.addSlider(10, computer2Difficulty, (difficulty) ->
|
||||||
computer2Difficulty = difficulty;
|
computer2Difficulty = difficulty);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
player2Container.addText(AppContext.getString("serverIP"), true);
|
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.Layer;
|
||||||
import org.toop.app.layer.containers.VerticalContainer;
|
import org.toop.app.layer.containers.VerticalContainer;
|
||||||
import org.toop.app.layer.layers.MainLayer;
|
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.Game;
|
||||||
import org.toop.game.tictactoe.TicTacToe;
|
import org.toop.game.tictactoe.TicTacToe;
|
||||||
import org.toop.game.tictactoe.TicTacToeAI;
|
import org.toop.game.tictactoe.TicTacToeAI;
|
||||||
@@ -63,7 +65,13 @@ public final class TicTacToeLayer extends Layer {
|
|||||||
if (information.isConnectionLocal()) {
|
if (information.isConnectionLocal()) {
|
||||||
new Thread(this::localGameThread).start();
|
new Thread(this::localGameThread).start();
|
||||||
} else {
|
} 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();
|
reload();
|
||||||
@@ -126,7 +134,8 @@ public final class TicTacToeLayer extends Layer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
move = ticTacToeAI.findBestMove(ticTacToe, compurterDifficultyToDepth(5, information.computerDifficulty()[currentPlayer]));
|
move = ticTacToeAI.findBestMove(ticTacToe, compurterDifficultyToDepth(10,
|
||||||
|
information.computerDifficulty()[currentPlayer]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (move == null) {
|
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;
|
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) {
|
while (running) {
|
||||||
final int currentPlayer = ticTacToe.getCurrentTurn();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -90,6 +90,11 @@ public class ResourceManager {
|
|||||||
return asset.getResource();
|
return asset.getResource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @SuppressWarnings("unchecked")
|
||||||
|
// public static <T extends BaseResource> ArrayList<ResourceMeta<T>> getAllOfType() {
|
||||||
|
// return (ArrayList<ResourceMeta<T>>) (ArrayList<?>) new ArrayList<>(assets.values());
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all assets of a specific resource type.
|
* Retrieve all assets of a specific resource type.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user