Question: If I could kindly gain some help for the OOP Java code with developing the logic of a card game that is similar to Uno.

If I could kindly gain some help for the OOP Java code with developing the logic of a card game that is similar to Uno. The title of the game is Quattro (due to having four players)

Game Materials:

- There are 40 cards in the pack in total

- Cards can be of four different colours - Red, Yellow, Green, Blue; and have a number value between 0 - 9

The game is played with four players.

An example selection of 5 cards could be: Blue 5, Red 7, Green 0, Red 2, Green 5

Gameplay Rules:

  1. Each player receives a set number of cards to play (for this game players will receive three cards each). These are referred to as the player hand.

  2. The remaining cards are placed in a draw pile.

  3. The first card in the draw pile is placed in the discard pile and its colour and number revealed. It is

    now the turn of the first player.

  4. The player checks the cards in their hand to see if any match against the top card of the discard

    pile in terms of:

    1. The numbers of the two cards

    2. The colours of the two cards

  5. If they have a match on colour or number, the player removes the matching card from their hand, and it becomes the first (top) card in the discard pile.

  6. If they do not have a match, they need to instead take the top card from the draw pile and add it to their hand.

  7. Play then moves onto the next player, who works their way through steps 4-6

  8. Play continues until one player has no cards remaining. This player is declared the winner of the

    game.

There are numerous online videos of people playing Uno which is a more complicated version of the game we are developing. Search People Playing Uno and check out a couple to get a better idea of gameplay in action if you are unsure of the game mechanics. Note that unlike Uno we are not including any Wild, Draw Two, Reverse, or Skip cards into our game.

Additional Notes regarding the solution:

  • This is a text based game only i.e. you do not have to implement any imagery of cards.

  • You can complete the solution however you like, within the following boundaries

o You must use the class structure as outlined in the Class Diagram below o You need to include the functionality as outlined Task 2 below o You must complete all Tasks below

Class Diagram

I've done some preliminary work for the class diagram:

If I could kindly gain some help for the OOP Java code

  • The classes with a blue background are active classes in this project. They will contain code for the solution that you are creating

  • The classes with an orange background are part of a proposed future expansion of the game. They need to be implemented but only as a shell (i.e. they will contain no code towards your current solution)

Tasks

Task 1: Design

I've created the respective eight classes required based from the UML class above.

with developing the logic of a card game that is similar to

I've also created a class stub for each class such as below e.g:

public class ClassName { }

I've added the necessary additional keywords for classes that inherit from interfaces or abstract classes and I've also created clases that do not have to include current functionality (as per the Orange highlighted in the diagram above)

Task 2: Functionality

It is expected that the solution will implement the following functionality (I've included 'Rules for Gameplay under Background for more context on the functionality with the implementation to include clear comments regarding purpose of classes and methods used.

The card game has four players Only one of the players is a human player (the remaining three players are bots) The program will ask for the human player to give their name.

Bot players should have a name as well. This should be given to them by the program. The deck of cards will consist of forty cards in total made up of:

o 10 Blue cards numbered 0-9

o 10 Yellow cards numbered 0-9

o 10 Red cards numbered 0-9

o 10 Green cards numbered 0-9

The order of any collection of cards must be randomized (i.e. the cards need to be shuffled) Each player will be dealt three cards initially from the deck (or draw pile) The human (and bot) players will be able to view what cards they have in their hand The human (and bot) players will not be able to view of what cards opponents have.

Once cards have been distributed to players from the draw pile, the first card from this pile is moved to become the first/top card in the discard pile.

A player needs to match the top card of the discard pile with a card they have in their hand.

o If they have a matching card, it is selected and is then moved from their hand to become the top card of the discard pile. Play then moves onto the next player

o If they do not have a matching card, the first card from the draw pile needs to be selected and added to their hand. Play then moves onto the next player

Each player should have their turn in order Once any player has played their last card a message should be displayed indicating that this player is the winner of the game. The game should end at this point. The human player should be asked at the start of the game what their name is The human player should be provided with the following information during the game where appropriate

o Their name o What cards they hold in their hand o What the top card of the discard pile is o What cards other players played o If other players had to select a card from the draw pile o How many cards the other players have in their hands

The human player should have some means of indicating which card they would like to play via the console If the human does not enter details of a valid card to play, they should be advised to enter details again

If the human does not have a valid card to play, they should be able to indicate this via the console If the draw pile is exhausted (i.e. there are no more cards in this pile)

o The top card of the discard pile should be retained in the discard pile

o All other cards in the discard pile should be moved to the draw pile and randomized (shuffled).

Suggestions for implementation...

  • Give each of the cards a code to identify it i.e. Red 5 could be given the code R5 or even just a number like 16. What matters is that the code is unique. This code could then be used for the human player to indicate which card they would like to play (along with other functionality)

  • Consider making use of Arraylists for the following reasons:

o Arrays lists can be used to manage cards in the following locations Hold cards in the deck or draw pile Hold cards in the discard pile Hold the cards for individual players (i.e. each player has their own arraylist of cards)

o Arraylists can be used to move cards i.e. A player that has a valid card to play can have that card moved from their personal arraylist of cards to the top of the discard arraylist i.e. a player than has no valid card to play can

o Arraylists can have their contents randomized through the function Collections.shuffle(arraylistname) available through importing java.util.*

  • Use the QuattroTest class to run and test your program frequently. It may be that much of the logic that you write for the program ends up in this class.

  • Start by creating the deck of cards making use of the StandardColourCard class. As suggested above consider adding the created cards to an arraylist, and develop logic to move cards between a deck and draw pile as required by the game

  • From there, add in a player (Using the Player class), and develop the logic to move cards between the player hand, and the deck and draw piles

  • From there add in the logic to manage the three bot players and player turns.

  • Note the above are suggestions only so long as all functionality is included and all directions in

    Tasks 1-4 are followed you can create the program how you wish.

Task 3: Exceptions

You will need to run some checks on the validity of data been entered. It is expected that the program will throw an exception in the following circumstances:

  • If no name is entered for the human player of the game

  • If the human player makes an invalid selection when entering details of a card to play

    You must have a catch block that catches these exceptions and displays an appropriate error message. (You can use the getMessage method of the Throwable class to achieve this).

    You do need to manage the exceptions appropriately i.e. the program should alert the user that an exception has occurred, and advise the user how to proceed.

Task 4: Testing

As part of your program implementation you should test to determine how the program performs when the user makes an invalid selection when choosing a card to play (refer Task 3)

  1. Describe one of the error scenarios that could unfold if a user does enter incorrect data.

  2. Design a custom Java Class to represent a custom exception for Q3. Your solution must follow best- practices from Javas Exception class hierarchy including:

    • A default constructor

    • A one-time argument with a message

    • The getMessage() accessor method.

      Note there is no need to implement this custom exception class.

I've included a sample of the extended gameplay and expected Output to assist:

Uno. The title of the game is Quattro (due to having four

players) Game Materials: - There are 40 cards in the pack in

Key: Fully Implemented Card (Abstract) Partially Implemented Colour Card Wild Card Player Standard Colour Card Special Colour Card Special Ability (Interface) Quattro Test Projects X Files Services QuattroTest Source Packages quattrotest Card.java ColourCard.java Player.java QuattroTest.java SpecialAbility.java Special ColourCard.java Standard ColourCard.java WildCard.java Libraries 1 Enter Player Name 2 3 Enter a name with one or more non-space characters 4 Enter Player Name 5 Fiona 6 Player name is: Fiona 7 Cards that Fiona has are 8 Card Code:26 - Yellow 5 9 Card Code: 8 - Red 7 10 Card Code:14 - Blue 3 11 12 The top card is: 13 Blue 8 14 Enter the Card Code of the card you would like to play 15 If you don't have a valid card enter 0 16 14 17 Fiona has played Blue 3 18 Fiona has the following number of cards: 2 19 20 Player 2 has picked up a card 21 Player 2 has the following number of cards: 4 22 23 Player 3 has played the following card: 24 Blue 2 25 Player 3 has the following number of cards: 2 26 27 Player 4 has played the following card: 28 Yellow 2 29 Player 4 has the following number of cards: 2 30 31 Cards that Fiona has are 32 Card Code:26 - Yellow 5 33 Card Code: 8 - Red 7 34 35 The top card is: 36 Yellow 2 37 Enter the Card Code of the card you would like to play 38 If you don't have a valid card enter 0 39 26 40 Fiona has played Yellow 5 41 Fiona has the following number of cards: 1 42 43 Player 2 has played the following card: 44 Yellow 9 45 Player 2 has the following number of cards: 3 46 47 Player 3 has picked up a card 48 Player 3 has the following number of cards: 3 49 50 Player 4 has played the following card: 51 Yellow 0 52 Player 4 has the following number of cards: 1 53 54 cards that Fiona has are 55 Card Code: 8 - Red 7 56 57 The top card is: 58 Yellow o 59 Enter the Card Code of the card you would like to play 60 If you don't have a valid card enter 0 61 0 62 A card has been added to your hand. 63 Cards that Fiona has are 64 Card Code: 8 - Red 7 65 Card Code:11 - Blue 0 66 67 Fiona has the following number of cards: 2 68 69 Player 2 has picked up a card 70 Player 2 has the following number of cards: 4 71 72 Player 3 has picked up a card 73 Player 3 has the following number of cards: 4 74 75 Player 4 has played the following card: 76 Yellow 6 77 Player 4 is the winner 78

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!