CSC 207 mvc模型

University of Toronto
CSC 207, Fall 2021
Assignment 2: Three Musketeers GUI
Due on November 12th, 2021, 11:59PM EST
Description
This assignment’s major learning goal is inversion of control and to create a GUI version of Assignment 1’s
Three Musketeers game. In this assignment, you must be:
• Ensuring classes are small and do one thing (Single Responsibility Principle)
• Implementing a MVC pattern in the design
• Using inheritance, composition, and polymorphism
• Creating a GUI for the game using JavaFX
Just like the previous assignment, we will be implementing the Three Musketeers Board game. Feel free to
play against an AI to gain some intuition about this game.
THE GAME
This game is played on a 5x5 square board with this starting position:
• Starting Position:
| A B C D E
−−+−−−−−−−−−−
1 | O O O O X
2 | O O O O O
3 | O O X O O
4 | O O O O O
5 | X O O O O
RULES
• TURNS - The Musketeers always go first. Each player makes one move before passing to their opponent.
• MUSKETEER - On the Musketeers’ turn, a musketeer can move to an adjacent orthogonal (neighboring,
non-diagonal) cell occupied by a guard, capturing it and occupying that cell.
• GUARD - On the Guards’ turn, a guard can move to an adjacent orthogonal empty cell.
• GOALS -
– The Musketeers win if they cannot capture any guards AND if they are not on the same row or
column.
– The guards win if all the musketeers are on the same row or column at any point in the game.
1
An Example
The Guards’ turn:
| A B C D E
−−+−−−−−−−−−−
1 | X
2 | O
3 | X O O
4 | O
5 | O O X
– Guard moves D4 → E4
| A B C D E
−−+−−−−−−−−−−
1 | X
2 | O
3 | X O O
4 | O
5 | O O X
– Musketeers’ only move is to capture the guard on C5
| A B C D E
−−+−−−−−−−−−−
1 | X
2 | O
3 | X O O
4 | O
5 | O X
– Guard moves A5 → B5
| A B C D E
−−+−−−−−−−−−−
1 | X
2 | O
3 | X O O
4 | O
5 | O X
– Musketeers can only capture the guard on B5
| A B C D E
−−+−−−−−−−−−−
1 | X
2 | O
3 | X O O
4 | O
5 | X
– Guards win because 3 musketeers are all on the B column
2
Tasks
You are given starter code to implement classes and methods.
Your implementation will include a collection of features for the GUI, including:
• The game board itself
• The ability to load custom boards from text files
• A main menu for game modes (Human VS Human, Human VS Computer Random, Human VS Computer
Greedy)
• Game controls (New game, Save game, Undo)
• Player side selection menu (Musketeers or Guards)
• Interactive UI: Enabling/Disabling game pieces depending on whose turn it is and the possible moves
In your implementation you are REQUIRED to:
• Appropriately document your code
• Use inheritance, composition, and polymorphism where possible
• Follow the provided descriptions for the TODO functions
In your implementation you are allowed to:
• Add more private methods
• Add additional classes
• Use static and instance variables/methods as appropriate, with appropriate protections
You are NOT allowed to:
• Remove provided methods
• Change the preset ID for JavaFX Nodes (Buttons, ListViews, Labels, TextFields, ...)
• Modify pom.xml
3
TODO
ModeInputPanel.java
The main menu view containing game mode selection and board loading options
• getFiles(ListView listView): (Line 99)
Gets all the text files from the boards directory and puts them into the given listView.
• selectBoard(Label selectBoardLabel, ListView boardsList):
Loads the board file that is selected in the boardsList and updates the selectBoardLabel with
the name of the new Board file
SideInputPanel.java
A side selector menu to choose which side a Human agent wants to play against a Computer agent
• handle(ActionEvent actionEvent):
Handles click of human player side options (’MUSKETEER’ or ’GUARD’), Calls V iew.setSide
with the appropriate P iece.T ype selected
BoardPanel.java
The game view containing the game board and the game controls
• setupBoard():
BoardPanel.java extends a GridPane. Create Cells and add them to the BoardPanel to create
a 5 by 5 board. Set the onAction of the cells to ’this’ to make the BoardPanel handle function
get called when a cell is clicked.
• updateCells():
Updates the BoardPanel to represent the board with the latest information. This is where the
board will get updated to show the possible pieces the player can move and if that’s already
selected then show the possible destinations the player can move to. Disable the cells that
should not be able to be clicked.
• handle(ActionEvent actionEvent):
Handles cell clicks on the board and updates the board accordingly depending on if the player
is selecting a piece to move or is selecting the destination of the piece they are moving.
4
View.java
A view + controller that manages what is visible in the GUI and handles model updates
• runMove(): (Line 172)
Handles running the moves for both human and computer agents. Update the view after
performing the move, the board can be updated by calling BoardP anel.updateCells. On
game over, messageLabel must contain the winner (’MUSKETEER’ or ’GUARD’) and all
Cells must be disabled.
• setUndoButton():
Enables or disables the undo button depending on if there are moves to undo.
• setGameMode(ThreeMusketeers.GameMode mode):
Sets the game mode to the given mode then shows a side selector (Not needed for Human vs
Human) or the game view.
• setSide(Piece.Type sideType):
Handles setting the correct agents based on the selected game mode and player’s piece type
by calling model.selectMode then shows the game view.
• undo():
The handler for the undo button. Undoes the last move by calling T hreeMusketeers.undoMove
and updates the boardPanel to show the correct players turn.
• saveBoard():
The handler for the save board button. Saves the current board state to a text file with a file
name of whatever is in the saveF ileN ameT extF ield. Should display any error messages or
saved messages in the saveF ileErrorLabel.
• restart():
The handler for the new game button. Restarts the game by resetting the board and updating
the view back to the main menu.
5
Getting Started
Install
Starter Code Invitation Link: https://classroom.github.com/...
Important: Edit the utorid file with your utorid (all lowercase)
The main function in App.java runs the game and starts the GUI. Boards are located in the boards directory
and boards are saved as .txt files with the current piece turn type on the first line followed by the 5 by 5
board just like in Assignment 1 (”X” = Musketeer, ”O” = Guard, ” ” = Empty cell).

你可能感兴趣的:(后端)