1. Homepage
  2. Programming
  3. COMP2396 Object-oriented Programming and Java Assignment 3: Big Two Card Game

COMP2396 Object-oriented Programming and Java Assignment 3: Big Two Card Game

Engage in a Conversation
HKUCOMP2396Object-oriented Programming and JavaJavaBig Two Card Game

COMP2396 Object-oriented Programming and Java Assignment 3
CourseNana.COM

Deadline: 11:55pm, 8th Nov, 2023. CourseNana.COM

Overview CourseNana.COM

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. CourseNana.COM

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. CourseNana.COM

Specifications CourseNana.COM

General game rules CourseNana.COM

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: CourseNana.COM

  • A standard 52 card pack is used. CourseNana.COM

  • The order of ranks from high to low is 2, A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3. CourseNana.COM

  • The order of suits from high to low is Spades, Hearts, Clubs, Diamonds. CourseNana.COM

  • There are always four players in a game. CourseNana.COM

  • Each player holds 13 (randomly assigned) cards at the beginning of the game. CourseNana.COM

  • The player holding the Three of Diamonds will begin the game by playing a hand of CourseNana.COM

    legal combination of cards that includes the Three of Diamonds. He/she cannot pass CourseNana.COM

    his/her turn to the next player without making his/her move. CourseNana.COM

  • Players take turns to play by either playing a hand of legal combination of cards that CourseNana.COM

    beats the last hand of cards played on the table, or by passing his/her turn to the next CourseNana.COM

    player. CourseNana.COM

  • A player cannot pass his/her turn to the next player if he/she is the one who played the CourseNana.COM

    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. CourseNana.COM

  • 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. CourseNana.COM

  • The game ends when any of the players has no more cards in his/her hand. Legal combinations of Cards CourseNana.COM

  • 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. CourseNana.COM

  • 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. CourseNana.COM

  • 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. CourseNana.COM

  • 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. CourseNana.COM

  • 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. CourseNana.COM

  • 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. CourseNana.COM

  • The BigTwo class CourseNana.COM

    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. CourseNana.COM

Specification of the BigTwo class: CourseNana.COM

public constructor: CourseNana.COM

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. CourseNana.COM

private instance variables: CourseNana.COM

int numOfPlayers an int specifying the number of players.
Deck deck a deck of cards.
ArrayList<CardGamePLayer> playerList a list of players.
ArrayList<Hand> 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. CourseNana.COM

public methods (CardGame interface): CourseNana.COM

int getNumOfPlayers() a method for getting the number of players. Deck getDeck() a method for retrieving the deck of cards being used. CourseNana.COM

ArrayList<CardGamePlayer> getPlayerList() a method for retrieving the list of players. CourseNana.COM

ArrayList<Hand> getHandsOnTable() a method for retrieving the list of hands played on the table. CourseNana.COM

int getCurrentPlayerIdx() a method for retrieving the index of the current player. CourseNana.COM

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. CourseNana.COM

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. CourseNana.COM

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. CourseNana.COM

boolean endOfGame() a method for checking if the game ends. CourseNana.COM

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. CourseNana.COM

public static methods: CourseNana.COM

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. CourseNana.COM

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. CourseNana.COM

The BigTwoCard class CourseNana.COM

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. CourseNana.COM

Specification of the BigTwoCard class: CourseNana.COM

The BigTwoDeck class CourseNana.COM

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. CourseNana.COM

Specification of the BigTwoDeck class: CourseNana.COM

overriding method: CourseNana.COM

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. CourseNana.COM

The Hand class CourseNana.COM

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. CourseNana.COM

Specification of the Hand class: CourseNana.COM

public constructor: CourseNana.COM

boolean isValid() a method for checking if this is a valid hand. CourseNana.COM

String getType() a method for returning a string specifying the type of this hand. CourseNana.COM

The Single, Pair, Triple, Straight, Flush, FullHouse, Quad, and StraightFlush classes CourseNana.COM

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". CourseNana.COM

Sample output CourseNana.COM

Showing cards on the table CourseNana.COM

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. CourseNana.COM

Figure 1. Showing cards on the table. CourseNana.COM

Getting user input CourseNana.COM

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. CourseNana.COM

Showing the hand played by a player CourseNana.COM

After the current player has selected a list of cards to play, your program should produce the followings to the console (see figure 2): CourseNana.COM

  • 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. CourseNana.COM

  • 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. CourseNana.COM

Print "{Pass}" to the UI if the player enters an empty list and {Pass} is a legal move. CourseNana.COM

Figure 2. Sample output after the current player has selected a list of cards to play. CourseNana.COM

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). CourseNana.COM

Figure 3. Sample output when the game ends. CourseNana.COM

You may refer to the Appendix for an example game play. CourseNana.COM

Marking Scheme CourseNana.COM

Marks are distributed as follows: CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
HKU代写,COMP2396代写,Object-oriented Programming and Java代写,Java代写,Big Two Card Game代写,HKU代编,COMP2396代编,Object-oriented Programming and Java代编,Java代编,Big Two Card Game代编,HKU代考,COMP2396代考,Object-oriented Programming and Java代考,Java代考,Big Two Card Game代考,HKUhelp,COMP2396help,Object-oriented Programming and Javahelp,Javahelp,Big Two Card Gamehelp,HKU作业代写,COMP2396作业代写,Object-oriented Programming and Java作业代写,Java作业代写,Big Two Card Game作业代写,HKU编程代写,COMP2396编程代写,Object-oriented Programming and Java编程代写,Java编程代写,Big Two Card Game编程代写,HKUprogramming help,COMP2396programming help,Object-oriented Programming and Javaprogramming help,Javaprogramming help,Big Two Card Gameprogramming help,HKUassignment help,COMP2396assignment help,Object-oriented Programming and Javaassignment help,Javaassignment help,Big Two Card Gameassignment help,HKUsolution,COMP2396solution,Object-oriented Programming and Javasolution,Javasolution,Big Two Card Gamesolution,