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
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() {
|
||||||
|
|||||||
@@ -128,7 +128,8 @@ public class RemoteGameSelector {
|
|||||||
localTicTacToe =
|
localTicTacToe =
|
||||||
LocalTicTacToe.createRemote(
|
LocalTicTacToe.createRemote(
|
||||||
ipTextField.getText(), portTextField.getText());
|
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();
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import org.toop.game.tictactoe.GameBase;
|
|||||||
import org.toop.game.tictactoe.TicTacToe;
|
import org.toop.game.tictactoe.TicTacToe;
|
||||||
import org.toop.game.tictactoe.ai.MinMaxTicTacToe;
|
import org.toop.game.tictactoe.ai.MinMaxTicTacToe;
|
||||||
|
|
||||||
|
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.
|
||||||
@@ -71,7 +73,7 @@ public class LocalTicTacToe { // TODO: Implement runnable
|
|||||||
this.connectionId = this.createConnection(ip, port);
|
this.connectionId = this.createConnection(ip, port);
|
||||||
this.createGame(ip, port);
|
this.createGame(ip, port);
|
||||||
this.isLocal = false;
|
this.isLocal = false;
|
||||||
this.executor.submit(this::remoteGameThread);
|
//this.executor.submit(this::remoteGameThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LocalTicTacToe(boolean[] aiFlags) {
|
private LocalTicTacToe(boolean[] aiFlags) {
|
||||||
@@ -86,7 +88,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