mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Fixed race condition on startup of AI vs Player game
# Conflicts: # src/main/java/org/toop/frontend/UI/RemoteGameSelector.java
This commit is contained in:
@@ -92,6 +92,7 @@ public class LocalGameSelector extends JFrame {
|
||||
}
|
||||
cardLayout.show(cards, "TicTacToe");
|
||||
}
|
||||
lttt.startThreads();
|
||||
}
|
||||
|
||||
public void showMainMenu() {
|
||||
|
||||
@@ -104,7 +104,7 @@ public class RemoteGameSelector {
|
||||
// });
|
||||
|
||||
GlobalEventBus.post(
|
||||
new NetworkEvents.SendCommand(
|
||||
new Events.ServerEvents.SendCommand(
|
||||
connectionId,
|
||||
"create_game",
|
||||
nameTextField.getText(),
|
||||
@@ -130,8 +130,9 @@ public class RemoteGameSelector {
|
||||
frame.remove(mainMenu);
|
||||
localTicTacToe =
|
||||
LocalTicTacToe.createRemote(
|
||||
ipTextField.getText(), Integer.parseInt(portTextField.getText())); // TODO: Unsafe parse
|
||||
UIGameBoard ttt = new UIGameBoard(localTicTacToe, this); // TODO: Fix later
|
||||
ipTextField.getText(), portTextField.getText());
|
||||
UIGameBoard ttt = new UIGameBoard(localTicTacToe, this);
|
||||
localTicTacToe.startThreads();
|
||||
frame.add(ttt.getTTTPanel()); // TODO: Fix later
|
||||
frame.revalidate();
|
||||
frame.repaint();
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.toop.game.tictactoe.TicTacToe;
|
||||
import org.toop.game.tictactoe.ai.MinMaxTicTacToe;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
/**
|
||||
* A representation of a local tic-tac-toe game. Calls are made to a server for information about
|
||||
* current game state. MOST OF THIS CODE IS TRASH, THROW IT OUT OF THE WINDOW AFTER DEMO.
|
||||
@@ -76,7 +78,7 @@ public class LocalTicTacToe { // TODO: Implement runnable
|
||||
this.connectionId = this.createConnection(ip, port);
|
||||
this.createGame("X", "O");
|
||||
this.isLocal = false;
|
||||
this.executor.submit(this::remoteGameThread);
|
||||
//this.executor.submit(this::remoteGameThread);
|
||||
}
|
||||
|
||||
private LocalTicTacToe(boolean[] aiFlags) {
|
||||
@@ -91,7 +93,14 @@ public class LocalTicTacToe { // TODO: Implement runnable
|
||||
}
|
||||
|
||||
this.isLocal = true;
|
||||
this.executor.submit(this::localGameThread);
|
||||
//this.executor.submit(this::localGameThread);
|
||||
}
|
||||
public void startThreads(){
|
||||
if (isLocal) {
|
||||
this.executor.submit(this::localGameThread);
|
||||
}else {
|
||||
this.executor.submit(this::remoteGameThread);
|
||||
}
|
||||
}
|
||||
|
||||
public static LocalTicTacToe createLocal(boolean[] aiPlayers) {
|
||||
|
||||
Reference in New Issue
Block a user