mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +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");
|
cardLayout.show(cards, "TicTacToe");
|
||||||
}
|
}
|
||||||
|
lttt.startThreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showMainMenu() {
|
public void showMainMenu() {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public class RemoteGameSelector {
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
GlobalEventBus.post(
|
GlobalEventBus.post(
|
||||||
new NetworkEvents.SendCommand(
|
new Events.ServerEvents.SendCommand(
|
||||||
connectionId,
|
connectionId,
|
||||||
"create_game",
|
"create_game",
|
||||||
nameTextField.getText(),
|
nameTextField.getText(),
|
||||||
@@ -130,8 +130,9 @@ public class RemoteGameSelector {
|
|||||||
frame.remove(mainMenu);
|
frame.remove(mainMenu);
|
||||||
localTicTacToe =
|
localTicTacToe =
|
||||||
LocalTicTacToe.createRemote(
|
LocalTicTacToe.createRemote(
|
||||||
ipTextField.getText(), Integer.parseInt(portTextField.getText())); // TODO: Unsafe parse
|
ipTextField.getText(), portTextField.getText());
|
||||||
UIGameBoard ttt = new UIGameBoard(localTicTacToe, this); // TODO: Fix later
|
UIGameBoard ttt = new UIGameBoard(localTicTacToe, this);
|
||||||
|
localTicTacToe.startThreads();
|
||||||
frame.add(ttt.getTTTPanel()); // TODO: Fix later
|
frame.add(ttt.getTTTPanel()); // TODO: Fix later
|
||||||
frame.revalidate();
|
frame.revalidate();
|
||||||
frame.repaint();
|
frame.repaint();
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import org.toop.game.tictactoe.TicTacToe;
|
|||||||
import org.toop.game.tictactoe.ai.MinMaxTicTacToe;
|
import org.toop.game.tictactoe.ai.MinMaxTicTacToe;
|
||||||
import java.util.function.Supplier;
|
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
|
* 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.
|
* 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.connectionId = this.createConnection(ip, port);
|
||||||
this.createGame("X", "O");
|
this.createGame("X", "O");
|
||||||
this.isLocal = false;
|
this.isLocal = false;
|
||||||
this.executor.submit(this::remoteGameThread);
|
//this.executor.submit(this::remoteGameThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LocalTicTacToe(boolean[] aiFlags) {
|
private LocalTicTacToe(boolean[] aiFlags) {
|
||||||
@@ -91,7 +93,14 @@ public class LocalTicTacToe { // TODO: Implement runnable
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.isLocal = true;
|
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) {
|
public static LocalTicTacToe createLocal(boolean[] aiPlayers) {
|
||||||
|
|||||||
Reference in New Issue
Block a user