CSC 207 mvc模型

看板狂
• 阅读 543

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<String> listView): (Line 99)
Gets all the text files from the boards directory and puts them into the given listView.
• selectBoard(Label selectBoardLabel, ListView<String> 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).
WX:codehelp

点赞
收藏
评论区
推荐文章
blmius blmius
4年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
美凌格栋栋酱 美凌格栋栋酱
10个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(
Wesley13 Wesley13
4年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Easter79 Easter79
4年前
typeScript数据类型
//布尔类型letisDone:booleanfalse;//数字类型所有数字都是浮点数numberletdecLiteral:number6;lethexLiteral:number0xf00d;letbinaryLiteral:number0b101
Wesley13 Wesley13
4年前
VBox 启动虚拟机失败
在Vbox(5.0.8版本)启动Ubuntu的虚拟机时,遇到错误信息:NtCreateFile(\\Device\\VBoxDrvStub)failed:0xc000000034STATUS\_OBJECT\_NAME\_NOT\_FOUND(0retries) (rc101)Makesurethekern
Wesley13 Wesley13
4年前
FLV文件格式
1.        FLV文件对齐方式FLV文件以大端对齐方式存放多字节整型。如存放数字无符号16位的数字300(0x012C),那么在FLV文件中存放的顺序是:|0x01|0x2C|。如果是无符号32位数字300(0x0000012C),那么在FLV文件中的存放顺序是:|0x00|0x00|0x00|0x01|0x2C。2.  
Wesley13 Wesley13
4年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
4年前
PHP创建多级树型结构
<!lang:php<?php$areaarray(array('id'1,'pid'0,'name''中国'),array('id'5,'pid'0,'name''美国'),array('id'2,'pid'1,'name''吉林'),array('id'4,'pid'2,'n
Wesley13 Wesley13
4年前
Java日期时间API系列36
  十二时辰,古代劳动人民把一昼夜划分成十二个时段,每一个时段叫一个时辰。二十四小时和十二时辰对照表:时辰时间24时制子时深夜11:00凌晨01:0023:0001:00丑时上午01:00上午03:0001:0003:00寅时上午03:00上午0
Stella981 Stella981
4年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
4年前
MBR笔记
<bochs:100000000000e\WGUI\Simclientsize(0,0)!stretchedsize(640,480)!<bochs:2b0x7c00<bochs:3c00000003740i\BIOS\$Revision:1.166$$Date:2006/08/1117
看板狂
看板狂
Lv1
夜来风雨声,花落知多少。
文章
4
粉丝
0
获赞
0