A multiplayer card game where players place cards on a grid and battle for control.
If the cell state of a grid cell is Block, it cannot be modified at any point in the code.
The ThreeTrios game is a multiplayer card game where players place cards on a grid.
The objective is to control the most cards of your PlayerColor on the board by the end of the game.
-
Grid & cells:
Each position on the grid is represented by aGridCellsobject, which has:- a cell state (
Filled,Unfilled, orBlock) - a card value, which is initially
null
Based on a grid cell’s state, a player may or may not be allowed to place a card on that cell.
- a cell state (
-
Configuration-driven setup:
The game is loaded from configuration files:- a grid configuration (board layout)
- a deck configuration (cards and their values)
Below is a minimal example of how to construct and run a game using the model and view:
import cs3500.threetrios.model.SoloTTGModel;
import cs3500.threetrios.model.SimpleCard;
import cs3500.threetrios.model.TTGModel;
import cs3500.threetrios.view.SoloTTGView;
import cs3500.threetrios.view.TTGView;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
TTGModel<SimpleCard> ttgModel =
new SoloTTGModel("src/hardboard.config", "src/largeCardBase.config");
TTGView ttgView = new SoloTTGView(ttgModel);
ttgModel.startGame();
ttgModel.placeCard(0, 0, 0);
ttgModel.battle();
ttgModel.placeCard(0, 1, 1);
ttgModel.battle();
System.out.println(ttgView.toString());
}
}-
Grid & cells (
GridCells):
The grid is a 2D array ofGridCells.
Each cell:- has a state:
Filled,Unfilled, orBlock - holds an optional card (initially
null)
- has a state:
-
Deck & grid creation (
DeckCreator,GridCreator):
These classes read and parse the configuration files to construct:- the starting deck
- the initial grid layout
-
GameState:
Tracks the current phase of the game, such as:StartPlaceBattleEnd
-
Pair:
Stores a row/column pair used for tracking the coordinates of cards that are flipped during the battle phase. This supports combo battles by remembering which cells were affected.
-
Configuration files:
Located undersrc/(for example,hardboard.config,largeCardBase.config). -
Model (
cs3500.threetrios.model):
Contains all core interfaces and classes for the game logic, including:- grid and cells
- cards and decks
- game state and strategies
-
View (
cs3500.threetrios.view):
Contains classes and interfaces to render the game and interact with the user.
-
GridPanel- A
JPanelsubclass representing the grid. - Uses the actual model grid to display:
- holes
- filled cells
- unfilled cells
- A
-
HandPanel- Represents both players’ hands.
- Shows the current cards available to each player.
-
ThreeTriosGUI- A
JFramesubclass that represents the window of the game. - Hosts panels and connects them to the controller.
- A
-
Features interface
- Defines the actions that can be triggered from the view (e.g., button clicks in the hand and grid).
- Implemented by the controller and used by both
HandPanelandGridPanelto notify the model of user interactions.
-
ModelFeatures interface
- Defines methods in the model that interact with both the controller and the view.
- Includes methods such as:
addListeners(...)to subscribe the controller as a listenerdisplayTurn()to announce whose turn it is
-
Playerinterface- Implemented by:
HumanPlayerMachinePlayer
- Allows the controller to distinguish between human and machine players and request moves or coordinates accordingly.
- Implemented by:
-
Controller logic
- The controller supports:
- human vs. human
- human vs. machine
- machine vs. machine
- The
machinePlay()method interacts with the model and applies the appropriate strategy based on thePlayertype, choosing the coordinates to pass intoplaceCard(...).
- The controller supports:
-
Player types & strategies
- In your configuration, specify:
humanto initialize a human playerstrategy1orstrategy2(or other supported names) to initialize a machine player
If no command-line arguments are provided, the game defaults to a human vs. human game.
- In your configuration, specify:
-
Entry point (
ThreeTriosclass)- Reads the command-line arguments.
- Creates the appropriate player types (human or machine) and the strategies associated with them.
- Initializes the model, view, and controller.
-
View–Features pattern
- The view’s frame and its panels are separated into distinct classes.
- Each feature (panel, button group, etc.) is responsible only for UI concerns and delegates
logic to the controller via the
Featuresinterface.
-
Observer pattern
- The model uses
ModelFeaturesto notify subscribed listeners (e.g., the controller) of changes. - This yields strong decoupling between model, view, and controller.
- The model uses
-
Future improvements
- Move further away from concrete classes when possible and increase the use of interfaces and abstractions.
- Continue refining the MVC design to keep responsibilities well separated and testable.