diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 217766f..db2f4ca 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -11,9 +11,10 @@
-
-
+
+
+
@@ -133,7 +134,7 @@
-
+
diff --git a/src/cs3500/threetrios/ThreeTrios.java b/src/cs3500/threetrios/ThreeTrios.java
index 8add9d0..ddc5dfd 100644
--- a/src/cs3500/threetrios/ThreeTrios.java
+++ b/src/cs3500/threetrios/ThreeTrios.java
@@ -86,6 +86,12 @@ public static void main(String[] args) {
redPlayerType,
redStrategyType
);
+ Player bluePlayer = choosePlayer(
+ model,
+ ThreeTriosPlayer.BLUE,
+ bluePlayerType,
+ blueStrategyType
+ );
// -- Creating views, which display information
// (and potentially handel inputs for human players)--
@@ -104,7 +110,7 @@ public static void main(String[] args) {
PlayerController redController = new PlayerControllerImpl(model,
redView, redPlayer, ThreeTriosPlayer.RED);
ProviderController blueController = new ProviderController(adaptedModel,
- ThreeTriosPlayer.BLUE, blueView);
+ blueView, bluePlayer, ThreeTriosPlayer.BLUE);
// -- Starting the game. --
model.startGame();
diff --git a/src/cs3500/threetrios/controller/ProviderController.java b/src/cs3500/threetrios/controller/ProviderController.java
index a918a9d..ab4a066 100644
--- a/src/cs3500/threetrios/controller/ProviderController.java
+++ b/src/cs3500/threetrios/controller/ProviderController.java
@@ -1,5 +1,7 @@
package cs3500.threetrios.controller;
+import java.util.Objects;
+
import cs3500.threetrios.model.ThreeTriosPlayer;
import cs3500.threetrios.provider.controller.Features;
import cs3500.threetrios.provider.model.IThreeTriosModel;
@@ -12,8 +14,9 @@
*/
public class ProviderController implements Features, PlayerController {
private final IThreeTriosModel model;
- private final ThreeTriosPlayer player;
private final IPlayerView view;
+ private final Player player;
+ private final ThreeTriosPlayer playerColor;
private Integer selectedCardIdx;
private boolean isMyTurn;
@@ -21,17 +24,29 @@ public class ProviderController implements Features, PlayerController {
/**
* Creates a new ProviderController that controls a view and model for a specific player.
* @param model The model to use.
- * @param player The player to control for.
+ * @param playerColor The player to control for.
* @param view The view to use.
*/
- public ProviderController(IThreeTriosModel model, ThreeTriosPlayer player, IPlayerView view) {
- this.model = model;
+ public ProviderController(
+ IThreeTriosModel model,
+ IPlayerView view,
+ Player player,
+ ThreeTriosPlayer playerColor
+ ) {
+ this.model = Objects.requireNonNull(model);
+ this.model.addFeaturesListener(this);
+
+ this.playerColor = Objects.requireNonNull(playerColor);
+
+ this.view = Objects.requireNonNull(view);
this.player = player;
- this.view = view;
- isMyTurn = false;
+ if (this.player != null) {
+ this.player.addControllerListener(this);
+ } else {
+ view.addFeaturesListener(this);
+ }
- this.view.addFeaturesListener(this);
- this.model.addFeaturesListener(this);
+ isMyTurn = false;
}
// Methods from Features //
@@ -99,6 +114,10 @@ public void setTurn(boolean turn) {
isMyTurn = turn;
view.blurScreen(!turn);
view.refresh();
+
+ if (isMyTurn && player!=null) {
+ player.itsYourTurn();
+ }
}
/**
@@ -119,7 +138,7 @@ public void gameOver() {
*/
@Override
public void handleCardSelection(Integer index, ThreeTriosPlayer player) {
- if (player == this.player) {
+ if (player == this.playerColor) {
this.selectCard(index);
}
}
@@ -142,8 +161,8 @@ public void handleGridCellSelection(int row, int col) {
@Override
public void update() {
System.out.println("Provider updated with turn = " + model.getTurn());
- System.out.println("Provider is " + player.getName());
- this.setTurn(model.getTurn().equals(player.getName()));
+ System.out.println("Provider is " + playerColor.getName());
+ this.setTurn(model.getTurn().equals(playerColor.getName()));
if (model.isGameOver()) {
gameOver();
}
@@ -165,6 +184,6 @@ public void isYourTurn() {
*/
@Override
public ThreeTriosPlayer getPlayer() {
- return player;
+ return playerColor;
}
}
diff --git a/src/cs3500/threetrios/controller/UpperLeftmostStrategy.java b/src/cs3500/threetrios/controller/UpperLeftmostStrategy.java
index 428a509..dd814f2 100644
--- a/src/cs3500/threetrios/controller/UpperLeftmostStrategy.java
+++ b/src/cs3500/threetrios/controller/UpperLeftmostStrategy.java
@@ -32,7 +32,7 @@ public ThreeTriosMove findBestMove(
throws IllegalStateException {
if (tiedMoves == null || tiedMoves.isEmpty()) {
throw new IllegalStateException(
- "The provided list of moved is empty! No move could be found!"
+ "The provided list of moves is empty! No move could be found!"
);
}
diff --git a/src/cs3500/threetrios/model/ThreeTriosGameModel.java b/src/cs3500/threetrios/model/ThreeTriosGameModel.java
index f5c8819..c4f2af3 100644
--- a/src/cs3500/threetrios/model/ThreeTriosGameModel.java
+++ b/src/cs3500/threetrios/model/ThreeTriosGameModel.java
@@ -187,6 +187,7 @@ private void update() {
}
if (!isGameOver() && !playerControllers.isEmpty()) {
+ System.out.println(playerControllers.get(currentPlayer) == null);
playerControllers.get(currentPlayer).isYourTurn();
}
}