首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
COMP2396代做、代写Java编程设计
项目预算:
开发周期:
发布时间:
要求地区:
The University of Hong Kong
Department of Computer Science
COMP2396 Object-oriented Programming and Java
Assignment 3
Deadline: 11:55pm, 8
th Nov, 2023.
Overview
This assignment tests your understanding of inheritance and polymorphism, and their
implementations in Java. You are going to implement a card game called Big Two. A number
of classes will be provided to aid your implementation. These include a Card class which
models a card, a CardList class which models a list of cards, a Deck class which models a
deck of cards, a CardGamePlayer class which models a card game player, and a BigTwoUI
class which models a user interface for the Big Two card game. A CardGame interface is also
provided to model a general card game. You may refer to their Javadoc for details of these
classes. You should NOT modify any of these provided classes and interface in completing
your assignment.
As a minimum requirement, you are required to implement the following classes: BigTwo,
BigTwoCard, BigTwoDeck, Hand, Single, Pair, Triple, Straight, Flush, FullHouse, Quad, and
StraightFlush. The BigTwo class models the Big Two card game logics. The BigTwoCard
class and the BigTwoDeck class model a card and a deck of cards used in a Big Two card
game, respectively. The Hand class models a hand of cards in general card games. The Single,
Pair, Triple, Straight, Flush, FullHouse, Quad, and StraighFlush classes model hands of legal
combinations of cards in a Big Two card game. 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. You are required to write Javadoc for all public
classes and their public class members.
Specifications
General game rules
Please refer to https://www.pagat.com/climbing/bigtwo.html for a detailed description of the
Big Two card game. To simplify your implementation, we will adopt the following rules:
• A standard 52 card pack is used.
• The order of ranks from high to low is 2, A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3.
• The order of suits from high to low is Spades, Hearts, Clubs, Diamonds.
• There are always four players in a game.
• Each player holds 13 (randomly assigned) cards at the beginning of the game.
• The player holding the Three of Diamonds will begin the game by playing a hand of
legal combination of cards that includes the Three of Diamonds. He/she cannot pass
his/her turn to the next player without making his/her move.
• Players take turns to play by either playing a hand of legal combination of cards that
beats the last hand of cards played on the table, or by passing his/her turn to the next
player.
• A player cannot pass his/her turn to the next player if he/she is the one who played the
last hand of cards on the table. In this case, he/she can play a hand of any legal
combination of cards regardless of the last hand he/she played on the table.
• A hand of legal combination of cards can only be beaten by another better hand of
legal combination of cards with the same number of cards.
• The game ends when any of the players has no more cards in his/her hand.
Legal combinations of Cards
• Single. This hand consists of only one single card. The only card in a single is
referred to as the top card of this single. A single with a higher rank beats a single
with a lower rank. For singles with the same rank, the one with a higher suit beats the
one with a lower suit.
• Pair. This hand consists of two cards with the same rank. The card with a higher suit
in a pair is referred to as the top card of this pair. A pair with a higher rank beats a
pair with a lower rank. For pairs with the same rank, the one containing the highest
suit beats the other.
• Triple. This hand consists of three cards with the same rank. The card with the
highest suit in a triple is referred to as the top card of this triple. A triple with a higher
rank beats a triple with a lower rank.
• Straight. This hand consists of five cards with consecutive ranks. For the sake of
simplicity, 2 and A can only form a straight with K but not with 3. The card with the
highest rank in a straight is referred to as the top card of this straight. A straight
having a top card with a higher rank beats a straight having a top card with a lower
rank. For straights having top cards with the same rank, the one having a top card
with a higher suit beats the one having a top card with a lower suit.
• Flush. This hand consists of five cards with the same suit. The card with the highest
rank in a flush is referred to as the top card of this flush. A flush always beats any
straights. A flush with a higher suit beats a flush with a lower suit. For flushes with
the same suit, the one having a top card with a higher rank beats the one having a top
card with a lower rank.
• Full House. This hand consists of five cards, with two having the same rank and three
having another same rank. The card in the triplet with the highest suit in a full house
is referred to as the top card of this full house. A full house always beats any straights
and flushes. A full house having a top card with a higher rank beats a full house
having a top card with a lower rank.
• Quad. This hand consists of five cards, with four having the same rank. The card in
the quadruplet with the highest suit in a quad is referred to as the top card of this quad.
A quad always beats any straights, flushes, and full houses. A quad having a top card
with a higher rank beats a quad having a top card with a lower rank.
• Straight Flush. This hand consists of five cards with consecutive ranks and the same
suit. For the sake of simplicity, 2 and A can only form a straight flush with K but not
with 3. The card with the highest rank in a straight flush is referred to as the top card
of this straight flush. A straight flush always beats any straights, flushes, full houses,
and quads. A straight flush having a top card with a higher rank beats a straight flush
having a top card with a lower rank. For straight flushes having top cards with the
same rank, the one having a top card with a higher suit beats the one having a top card
with a lower suit.
The BigTwo class
The BigTwo class implements the CardGame interface and is used to model a Big Two card
game. It has private instance variables for storing the number of players, a deck of cards, a
list of players, a list of hands played on the table, an index of the current player, and a user
interface. Below is a detailed description for the BigTwo class.
Specification of the BigTwo class:
public constructor:
BigTwo() – a constructor for creating a Big Two card game. You should (i) create 4
players and add them to the player list; and (ii) create a BigTwoUI object for providing
the user interface.
private instance variables:
int numOfPlayers – an int specifying the number of players.
Deck deck – a deck of cards.
ArrayList
playerList – a list of players.
ArrayList
handsOnTable – a list of hands played on the table.
int currentPlayerIdx – an integer specifying the index of the current player.
BigTwoUI ui – a BigTwoUI object for providing the user interface.
public methods (CardGame interface):
int getNumOfPlayers() – a method for getting the number of players.
Deck getDeck() – a method for retrieving the deck of cards being used.
ArrayList
getPlayerList() – a method for retrieving the list of
players.
ArrayList
getHandsOnTable() – a method for retrieving the list of hands played
on the table.
int getCurrentPlayerIdx() – a method for retrieving the index of the current player.
void start(Deck deck) – a method for starting/restarting the game with a given
shuffled deck of cards. You should (i) remove all the cards from the players as well as
from the table; (ii) distribute the cards to the players; (iii) identify the player who holds
the Three of Diamonds; (iv) set both the currentPlayerIdx of the BigTwo object and
the activePlayer of the BigTwoUI object to the index of the player who holds the
Three of Diamonds; (v) call the repaint() method of the BigTwoUI object to show the
cards on the table; and (vi) call the promptActivePlayer() method of the BigTwoUI
object to prompt user to select cards and make his/her move.
void makeMove(int playerIdx, int[] cardIdx) – a method for making a move by a
player with the specified index using the cards specified by the list of indices. This
method should be called from the BigTwoUI after the active player has selected cards
to make his/her move. You should simply call the checkMove() method1 with the
playerIdx and cardIdx as the arguments.
void checkMove(int playerIdx, int[] cardIdx) – a method for checking a move
made by a player. This method should be called from the makeMove() method.
boolean endOfGame() – a method for checking if the game ends.
1 We will implement a network version of the game in assignment 5 where makeMove() is
used by the current player to broadcast his/her move to others over the network and
checkMove() is used by all users to validate the move made by the current player upon
receiving the information of the move over the network.
public static methods:
void main(String[] args) – a method for starting a Big Two card game. It should (i)
create a Big Two card game, (ii) create and shuffle a deck of cards, and (iii) start the
game with the deck of cards.
Hand composeHand(CardGamePlayer player, CardList cards) – a method for
returning a valid hand from the specified list of cards of the player. Returns null if no
valid hand can be composed from the specified list of cards.
The BigTwoCard class
The BigTwoCard class is a subclass of the Card class and is used to model a card used in a
Big Two card game. It should override the compareTo() method it inherits from the Card
class to reflect the ordering of cards used in a Big Two card game. Below is a detailed
description for the BigTwoCard class.
Specification of the BigTwoCard class:
public constructor:
BigTwoCard(int suit, int rank) – a constructor for building a card with the specified
suit and rank. suit is an integer between 0 and 3, and rank is an integer between 0 and
12.
overriding method:
int compareTo(Card card) – a method for comparing the order of this card with the
specified card. Returns a negative integer, zero, or a positive integer when this card is
less than, equal to, or greater than the specified card.
The BigTwoDeck class
The BigTwoDeck class is a subclass of the Deck class and is used to model a deck of cards
used in a Big Two card game. It should override the initialize() method it inherits from the
Deck class to create a deck of Big Two cards. Below is a detailed description for the
BigTwoDeck class.
Specification of the BigTwoDeck class:
overriding method:
void initialize() – a method for initializing a deck of Big Two cards. It should
remove all cards from the deck, create 52 Big Two cards and add them to the deck.
The Hand class
The Hand class is a subclass of the CardList class and is used to model a hand of cards. It has
a private instance variable for storing the player who plays this hand. It also has methods for
getting the player of this hand, checking if it is a valid hand, getting the type of this hand,
getting the top card of this hand, and checking if it beats a specified hand. Below is a detailed
description for the Hand class.
Specification of the Hand class:
public constructor:
Hand(CardGamePlayer player, CardList cards) – a constructor for building a hand
with the specified player and list of cards.
private instance variable:
CardGamePlayer player – the player who plays this hand.
public methods:
CardGamePlayer getPlayer() – a method for retrieving the player of this hand.
Card getTopCard() – a method for retrieving the top card of this hand.
boolean beats(Hand hand) – a method for checking if this hand beats a specified hand.
abstract methods:
boolean isValid() – a method for checking if this is a valid hand.
String getType() – a method for returning a string specifying the type of this hand.
The Single, Pair, Triple, Straight, Flush, FullHouse, Quad, and StraightFlush classes
These classes are a subclass of the Hand class and are used to model a hand of single, pair,
triple, straight, flush, full house, quad, and straight flush in a Big Two card game,
respectively. They should override methods of the Hand class as appropriate. In particular,
the getType() method should return the name of the class as a String object in these classes
modelling legal hands in a Big Two card game. For examples, calling the getType() method
on a Triple object should return "Triple", while calling the getType() method on a
FullHouse object should return "FullHouse".
Sample output
Showing cards on the table
At each player’s turn, your program should print out the cards held by each player as well as
the last hand played on the table (see figure 1). You can achieve this by calling the repaint()
method of the BigTwoUI object.
Figure 1. Showing cards on the table.
Getting user input
At each player’s turn, your program should read from the keyboard a space-separated list of
indices that represent the list of cards played by the player. You can achieve this by calling
the promptActivePlayer() method of the BigTwoUI object.
Showing the hand played by a player
After the current player has selected a list of cards to play, your program should produce the
followings to the console (see figure 2):
• Print "Not a legal move!!!" to the console if the cards selected do not compose a
valid hand or the move is not legal, and prompt the player to select again.
• Print to the UI the type of the hand followed by the cards in the hand if the cards
selected do compose a valid hand and is a legal move.
[Empty]
• Print "{Pass}" to the UI if the player enters an empty list and {Pass} is a legal move.
Figure 2. Sample output after the current player has selected a list of cards to play.
The game ends when any of the players has no more cards in his/her hand. Your program
should then print out the number of cards held by each player (see figure 3).
Figure 3. Sample output when the game ends.
You may refer to the Appendix for an example game play.
Marking Scheme
Marks are distributed as follows:
- Implementation of the BigTwo class (15%)
- Implementation of the BigTwoCard and BigTwoDeck classes (5% each)
- Implementation of the Hand class and its subclasses (5% each)
- Proper design using OOP approach (20%)
- Javadoc and comments (10%)
Submission
Please pack the source code (*.java) 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.
~ End ~
Game ends
Player 0 has 2 cards in hand.
Player 1 has 8 cards in hand.
Player 2 wins the game.
Player 3 has 5 cards in hand.
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
urba6006代写、java/c++编程语...
2024-12-26
代做program、代写python编程语...
2024-12-26
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!