首页 > 编程语言 >COMP2396 面向对像编程

COMP2396 面向对像编程

时间:2023-11-22 19:33:45浏览次数:32  
标签:COMP2396 GUI 编程 method button player 面向 cards class

您对GUI和事件处理的理解,以及它们Java实现。您将为Big Two卡设计和实现GUI 你在作业3中开发的游戏。除了中提供的类和接口之外任务3,提供了一个CardGameUI界面来为通用 纸牌游戏。您可以参考他们的Javadoc来了解这些类和接口的详细信息。你在完成您的分您将重用作业3中实现的所有类。您需要 实现BigTwoGUI类,该类为游戏构建GUI并处理所有用户操这个类实现了CardGameUI接口,并有几个内部类负责 用于呈现用户界面和处理用户动作。使用BigTwoGUI,则需要相应地修改BigTwo类。您需要更换 BigTwoUI对象与BigTwoGUI对象。您可以自由引入新实例变量和方法。此外,您还可以自由设计和介绍新产品 类。使用适当的OO设计,您不需要触摸作业3中的其余课程。您需要为所有公共对象编写Javadoc

The University of Hong Kong
Department of Computer Science
COMP2396 Object-oriented Programming and Java
Assignment 4
Deadline: 11:55pm, 22
nd Nov, 2023.
Overview
This assignment tests your understanding of GUI and event-handling, and their
implementations in Java. You are going to design and implement a GUI for the Big Two card
game you developed in assignment 3. In addition to the classes and interface provided in
assignment 3, a CardGameUI interface is provided to model a user interface for a general
card game. You may refer to their Javadoc for details of these classes and interfaces. You
should NOT modify any of these provided classes and interfaces in completing your
assignment.
You will be reusing all the classes implemented in assignment 3. You are required to
implement a BigTwoGUI class which builds a GUI for the game and handles all user actions.
This class implements the CardGameUI interface and has several inner classes responsible
for rendering the user interface and handling user actions. To make use of the BigTwoGUI
class, you will need to modify your BigTwo class accordingly. You will need to replace the
BigTwoUI object with a BigTwoGUI object. You are free to introduce new instance
variables and methods to these classes. Besides, you are also free to design and introduce new
classes in the inheritance trees as appropriate. With a proper OO design, you do not need to
touch the rest of the classes in assignment 3. You are required to write Javadoc for all public
classes and their public class members.
Specifications
Graphical user interface
You are free to design a GUI for your Big Two card game. As a minimum requirement, your
GUI should
• Have a panel showing the cards of each player as well as the cards played on the table.
The cards should be shown in a partially overlapped manner (see Figure 1).
• For each player, the panel should show his/her name and an avatar for him/her.
• For the active player, the panel should show the faces of his/her cards.
• For other players, the panel should show only the backs of their cards.
• For cards played on the table, the panel should show at least (the faces of) the last
hand of cards played on the table and the name of the player for this hand.
• Allow the active player to select and deselect his/her cards by mouse clicks on the
cards. The selected cards should be drawn in a “raised” position with respect to the
rest of the cards (see Figure 1).
• Have a “Play” button for the active player to play the selected cards. Nothing should
happen if the “Play” button is clicked with no card selected.
• Have a “Pass” button for the active player to pass his/her turn to the next player.
• Have a text area to show the current game status as well as end of game messages.
• Have a text area showing the chat messages sent by the players.
• Have a text input field for the active player to send out chat messages.
• Have a “Restart” menu item under a “Game” menu for restarting the game.
• Have a “Quit” menu item under a “Game” menu for quitting the game.
• Your application window should support maximizing, minimizing, and resizing.
The BigTwoGUI class
The BigTwoGUI class implements the CardGameUI interface. It is used to build a GUI for
the Big Two card game and handle all user actions. Below is a detailed description for the
BigTwoGUI class.
Specification of the BigTwoGUI class:
public constructor:
BigTwoGUI(BigTwo game) – a constructor for creating a BigTwoGUI. The parameter
game is a reference to a Big Two card game associated with this GUI.
private instance variables: *
BigTwo game – a Big Two card game associated with this GUI.
boolean[] selected – a boolean array indicating which cards are being selected.
int activePlayer – an integer specifying the index of the active player.
JFrame frame – the main window of the application.
JPanel bigTwoPanel – a panel for showing the cards of each player and the cards
played on the table.
JButton playButton – a “Play” button for the active player to play the selected cards.
JButton passButton – a “Pass” button for the active player to pass his/her turn to the
next player.
JTextArea msgArea – a text area for showing the current game status as well as end of
game messages.
JTextArea chatArea – a text area for showing chat messages sent by the players.
JTextField chatInput – a text field for players to input chat messages.
* These are just suggestions to aid your design. It is perfectly fine if your actual
implementation deviates from these suggestions.
CardGameUI interface methods:
void setActivePlayer(int activePlayer) – a method for setting the index of the
active player (i.e., the player having control of the GUI).
void repaint() – a method for repainting the GUI.
void printMsg(String msg) – a method for printing the specified string to the message
area of the GUI.
void clearMsgArea() – a method for clearing the message area of the GUI.
void reset() – a method for resetting the GUI. You should (i) reset the list of selected
cards; (ii) clear the message area; and (iii) enable user interactions.
void enable() – a method for enabling user interactions with the GUI. You should (i)
enable the “Play” button and “Pass” button (i.e., making them clickable); and (ii)
enable the BigTwoPanel for selection of cards through mouse clicks.
void disable() – a method for disabling user interactions with the GUI. You should (i)
disable the “Play” button and “Pass” button (i.e., making them not clickable); and (ii)
disable the BigTwoPanel for selection of cards through mouse clicks.
void promptActivePlayer() – a method for prompting the active player to select cards
and make his/her move. A message should be displayed in the message area showing it
is the active player’s turn.
inner classes: *
class BigTwoPanel – an inner class that extends the JPanel class and implements the
MouseListener interface. Overrides the paintComponent() method inherited from the
JPanel class to draw the card game table. Implements the mouseReleased() method
from the MouseListener interface to handle mouse click events.
class PlayButtonListener – an inner class that implements the ActionListener
interface. Implements the actionPerformed() method from the ActionListener interface
to handle button-click events for the “Play” button. When the “Play” button is clicked,
you should call the makeMove() method of your BigTwo object to make a move.
class PassButtonListener – an inner class that implements the ActionListener
interface. Implements the actionPerformed() method from the ActionListener interface
to handle button-click events for the “Pass” button. When the “Pass” button is clicked,
you should call the makeMove() method of your BigTwo object to make a move.
class RestartMenuItemListener – an inner class that implements the ActionListener
interface. Implements the actionPerformed() method from the ActionListener interface
to handle menu-item-click events for the “Restart” menu item. When the “Restart”
menu item is selected, you should (i) create a new BigTwoDeck object and call its
shuffle() method; and (ii) call the start() method of your BigTwo object with the
BigTwoDeck object as an argument.
class QuitMenuItemListener – an inner class that implements the ActionListener
interface. Implements the actionPerformed() method from the ActionListener interface
to handle menu-item-click events for the “Quit” menu item. When the “Quit” menu
item is selected, you should terminate your application. (You may use System.exit()
to terminate your application.)
* These are just suggestions to aid your design. It is perfectly fine if your actual
implementation deviates from these suggestions.
Sample output
Figure 1 shows an example of GUI for the Big Two card game that satisfies the minimum
requirement1
. You are not required to reproduce the same GUI exactly.
Figure 1. An example of GUI for the Big Two card game.
Marking Scheme
Marks are distributed as follows:
- Implementation of the BigTwoGUI class
o Rendering of players’ cards and cards on the table (20%)
o Implementation of card selection using mouse clicks (20%)
o Implementation of the game message area (5%)
o Implementation of the chat message area (5%)
o Implementation of the chat input field (5%)
o Implementation of the “Play” button (5%)
o Implementation of the “Pass” button (5%)
o Implementation of the “Restart” menu item (5%)
o Implementation of the “Quit” menu item (5%)
o Overall design of the GUI (10%)
- Integration with the BigTwo class (5%)
- Javadoc and comments (10%)
1 You may download the card images used in this example from
https://www.waste.org/~oxymoron/cards/. You are free to use any other card images.
Submission
Please pack the source code (*.java) and images of your application into a single zip file,
and submit it to the course Moodle page.
A few points to note:
- Always remember to write Javadoc for all public classes and their public class
members.
- Always remember to submit the source code files (*.java) but NOT the bytecode
files (*.class).
- Always double check after your submission to ensure that you have submitted the
most up-to-date source code files.
- Your assignment will not be marked if you have only submitted the bytecode files
(*.class). You will get zero mark for the assignment.
- Please submit your assignment on time. Late submission will not be accepted.

标签:COMP2396,GUI,编程,method,button,player,面向,cards,class
From: https://www.cnblogs.com/whenjava/p/17850109.html

相关文章

  • SEHH2042 计算机编程飞机调度管理系统
    在一个或多个高级语言编程环境中开发计算机程序;设计和开发结构化和文档化的计算机程序;解释面向对象编程的基本原理并将其应用于计算机程序发展结合计算机编程技术解决实际问题。介绍在本任务中,您将开发一个“飞行时间表管理系统”,该系统运行在命令行环境。系统存储到达和离开的时......
  • CSC1001 编程方法描述
    您应该在.py文件中为每个问题编写代码(请使用问题名称,例如,对于问题1,将其命名为q1.py)。请将所有.py文件打包到一个.zip文件,使用您的学生ID命名(例如,如果您的学生标识是123456,则文件应命名为123456.zip),然后通过Blackboard提交.zip文件。还请编写一个文本文件,其中提供了如何为每个代......
  • 深入Android多线程编程与性能优化
    引言在上一篇的入门篇中,我们对Android线程的基础概念和多线程编程模型有了初步了解。本篇将深入探讨多线程编程技术和性能优化策略,以提升应用的效率和响应性。高级多线程编程技术使用线程池管理线程线程池是一组预先创建的线程,用于执行任务。通过使用线程池,可以避免不断创建和销毁......
  • 面向对象03:回顾方法的调用
    一.静态与非静态初识:1.为什么会有静态和非静态?解释:Java中的静态和非静态是指成员变量和成员方法的修饰符,Java中有静态和非静态,是为了满足不同的编程需求。2.静态和非静态的定义:静态:(有static)静态变量和方法是属于类的,而不属于类的实例或对象。它们可以通过类名直接访问,不需要创建......
  • 面向对象02:回顾方法的定义
    //Demo01类publicclassDemo01{//main方法publicstaticvoidmain(String[]args){}/*修饰符返回值类型方法名(......){//方法体return返回值;}*/publicStringsayHello(){retu......
  • 面向对象01:什么是面向对象
    属性+方法=类  ......
  • Spring5学习随笔-基础注解编程
    学习视频:【孙哥说Spring5:从设计模式到基本应用到应用级底层分析,一次深入浅出的Spring全探索。学不会Spring?只因你未遇见孙哥】注解编程-第一章、注解基础概念1.什么是注解编程指的是在类或方法上加入特定的注解(@XXX),完成特定功能的开发.2.为什么要讲解注解编程注解开发......
  • (二十三)C#编程基础复习——Struct结构体
    在C#中,结构体也称为结构类型("structuretype”或“structtype”),它是一种可封装数据和相关功能的值类型,在语法上结构体与类(class)非常相似,它们都可以用来封装数据,并且都可以包含成员属性和成员方法。一、定义结构体要定义一个结构体需要使用struct关键字,每个结构体都可以被看作......
  • 实验2 C语言分支与循环基础应用编程
    实验任务11#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN24658intmain(){9intnumber;10inti;11srand(time(0));12for(i=0;i<N;++i){13nu......
  • shell 编程条件语句
    shelltest  测试0为真test-a/etc/fstabecho$?test-e/etc/fstabecho$? -a,-e#测试文件是否存在-a有bug#取反会有变化test+选项对象参数test-f#只看文件-r#是否有读的权限-w#是否有写的权限-x#是否有执行的权限-d#目录-f#文件[-e/etc/fs......