Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The last two images are to show the extra files I was given to assist with this project. The QuattroGameTester.java looks like this, added this
The last two images are to show the extra files I was given to assist with this project. The QuattroGameTester.java looks like this, added this just so you know. Thanks!
Background You are working in a programming role at GreatestSoft, an organization that has a focus on developing mobile games. You have been asked to develop the logic for a version of a card game that has aspects similar to the popular card game 'Uno'. The working title for the game is Quattro (as it has four players). Game Materials: - There are 40 cards in the pack in total - Cards can be of: four different colors - Red, Yellow, Green, Blue; and have a number value between 09 - 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. Rules for Gameplay 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's '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 are revealed. 4. It is now the turn of the first player. 5. The player checks the cards in their 'hand' to see if any match against the top card of the 'discard' pile in terms of: a. Numbers b. Colour 6. If they have a match on colour or number, the player removes the matching card from their 'hand' and this card becomes the first (top) card in the 'discard' pile. 7. 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". 8. Play then moves on to the next player, who works their way through steps 4-6 9. 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. Also, review 'Sample Gameplay' below for a description of how a game may play out Items to note in relation to 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 - You must use the class structure as outlined in the 'Class Diagram' section. - You need to include the functionality as outlined in Tasks section. A class diagram has been provided for you in Figure 1. Note the following in relation to this diagram - 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 '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) Functionality It is expected that your solution will implement the following functionality (check 'Rules for Gameplay' section. Check as well the 'Suggested Tips for Implementing' section. Functionality to Implement: - 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 the human player to give their name. - Bot players will be assigned names by the program. - The deck of cards will consist of forty cards in total made up of: 10 Blue cards numbered 09 10 Yellow cards numbered 0-9 10 Red cards numbered 0-9 10 Green cards numbered 09 - 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 '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 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 can attempt to 'match' the top card of the 'discard' pile with a card they have in their 'hand'. - 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 on to the next player. 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 on to 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 provided with the following information during the game where appropriate Their name What cards they hold in their 'hand' What the top card of the 'discard' pile is What cards other players play If other players had to select a card from the 'draw' pile How many cards the other players have in their "hand' - The human player should be able to indicate which card they would like to attempt to play via the console. - If the human player selects an invalid card to play, they should be prompted to enter again. - The human player should be able to indicate that they have no valid cards via the console only if there are no valid cards in the human player's 'hand'. - If the 'draw' pile is exhausted (i.e. there are no more cards in this pile) - The top card of the 'discard' pile should be retained in the 'discard' pile All other cards in the 'discard' pile should be moved to the 'draw' pile and randomized (shuffled). Igested tips for implementing: - 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: Arrays lists can be used to manage cards in the following locations - Hold cards in the 'draw' pile - Hold cards in the 'discard' pile - Hold the cards for individual players (i.e. each player has their own arraylist of cards) 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 who has no valid card to play can 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 'discard' 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's 'hand', and the 'discard' 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. Helper UML diagram The following is a UML class diagram that a solution can be based on. You can use it for your implementation if you find it useful. Your implementation may be different. In QuattroGame class - numberOfPlayer is 4 , so you can declare or skip it. - startingCardNumber is the card on the top of the discard pile to be matched. - cardCodeSeed is a variable used to generate cardCode. You can choose to generate your codes in different ways. Please note: You can insert more fields and methods as you want. The diagram in Figure 2 is a helper only. Task 1: 'Card', 'ColourCard', and 'StandardColourCard' class Write the following classes as mentioned in instruction: - The abstract class Card - The class ColourCard that extends Card class - The class StandardColourCard that extends ColourCard class Task 2: 'Player' class Write the class Player as mentioned in instruction. This class should have at least three fields as below: - name of the player as a string. - a collection of cards (Card objects) that the player has on 'hand'. You are recommanded to use an ArrayList but any choise is accepted. - A Boolean variable to represent if the player is a human player or bots. If the value is true, the player is the human player. Write all necessary setters and getters for all declaired fields and any methods that you want to implement. Task 3: 'QuattroGame' class This class will be the key part of your project. This is the class that manage how the game is played. Fields: This class should have at least three following fields: - A collection of cards for draw pile - A collection of cards for discard pile - A collection of players where player 1 is the human player and players 2, 3, 4 are bots. Methods: This class should have many separated methods that show the following main flows: - All cards are created (method createcards) - All players are created (method createPlayers) - Cards are dealed to players (method dealCards) - First (top) card is show (turn over) and its information is printed in console so that the human player can see (method playFirstCard) - Repeatedly let the players taking turns to move until one player wins the game (method playByTurn). This process should includes the following actions: - Print cards that the human player has on 'hand' and the top card from 'discard' pile before the human player plays so that the human player can know what to do. - Let the human player enter option and process the game arcodingly. - Display the action that has been done by the human player. - Display information of each player action in turn, including what card is played and how many cards on 'hand' after playing. Information of cards entered by human player each turn needs to be verified if it is from her/his 'hand' and if it matches the top card of discard pile. - Once the 'draw' pile is empty, all cards from 'discard' pile, except the top card, are transferred to the 'draw' pile and suffled before a player can draw. Helper methods: You can insert as many helper methods as you want. You are asked to add comments for these methods, stating which step it is for. Examine the method playGame that call sequences of importance methods you are asked to write. This method is provided, and you don't have to modify it. You are recommended not to modify it. This method is called in the tester class QuattroGameTester. To play the game, an object of QuattroGame class is created in QuattroGameTester and only this method is called. Task 4: Extension In this task, you are asked to prepare for possible extensions that may be developed in the future. Write three classes: - Interface SpecialAbility that has - A method activateAbility - Class WildCard that implements interface SpecialAbility and extends Card class. It also has - A field specialAbility as a strring. - Class SpecialColourCard that implements interface SpecialAbility and extends Card class. It also has A field specialAbility as a string. Task 5 Exceptions You will need to run some checks on the validity of the data 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 'try 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 on how to proceed. Task 6 - Comments Ensure you include appropriate comments in your code including: - Purpose of classes - Purpose of methods - Purpose of complex code blocks - Explanatory notes for any potentially confusing elements. Task 7: Testing Testing Tasks 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. In a Word document, answer the following questions in your own words: 1. What is white box testing and how would you use it to test your solution? 2. What is black box testing and how would you use it to test your solution? 3. Describe one of the error scenarios that could unfold if a user does enter incorrect data. 4. Design a custom Java Class to represent a custom exception for Task 5. Your solution must follow best practices from Java's 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. Short Sample Gameplay The following is a sample game - The human is asked what their name is, and enters 'Joe' - The program welcomes Joe to the game. - Joe receives three cards - Red 6 - Blue 8 - Green 7 - The program advises Joe that the top card of the 'discard' pile is a Green 9. - Joe enters a code that advises the program that they wish to play the Green 7 - The Green 7 then becomes the top card of the 'discard' pile - Player 02 , one of the bot players, plays a Green 2 - Joe is advised of this - Player 03, one of the bot players, plays a Blue 2 - Joe is advised of this - Player 04 has no valid cards to play, and an extra card is added to their 'hand' - Joe is advised of this - Joe plays the Blue 8 and now only has one card left - Play continues around until it is Joe's next turn. The top card on the 'discard' pile happens now to be a Yellow 6 . Joe is advised of this - Joe plays the final card in their 'hand', a Red 6, and wins the game. ample Gameplay and Output ample output of a game followed by explanatory notes Enter Player Name Enter a name with one or more non-space characters Enter Player Name Fiona Player name is: Fiona Cards that Fiona has are Card Code:26 - Yellow 5 Card Code: 8 - Red 7 Card Code:14 - Blue 3 The top card is: Blue 8 Enter the Card Code of the card you would like to play If you don't have a valid card enter 0 14 Fiona has played Blue 3 Fiona has the following number of cards: 2 Player 2 has picked up a card Player 2 has the following number of cards: 4 Player 3 has played the following card: Blue 2 Player 3 has the following number of cards: 2 Player 4 has played the following card: Yellow 2 Player 4 has the following number of cards: 2 Cards that Fiona has are Card Code:26 - Yellow 5 Card Code: 8 - Red 7 The top card is: Yellow 2 Enter the Card Code of the card you would like to play If you don't have a valid card enter 0 26 Fiona has played Yellow 5 Fiona has the following number of cards: 1 Figure 4A Sample Output - Part 01 Figure 4B Sample Output - Part 02 Sample Game Explanatory Notes The following explains the steps shown in Figure 3 : - Line 1: Player is asked to enter their name - Line 3: Player has not entered a valid name and is asked to enter it again - Line 5: Player has entered their name (Fiona) - Line 7-10: Details of the cards that Fiona holds (Yellow 5, Red 7 and Blue 3) - Line 12-13: Details of what the top card on the 'discard' pile is (i.e. what card Fiona needs to match against with one of her cards) - Lines 14-15: Instructions for playing a card. - Lines 16-17: Details of the card that Fiona has played. Fiona has selected the card with a code number of 14 , which is the Blue 3 (The Blue 3 now becomes the top card on the 'discard' pile) - Line 18: Information about how many cards Fiona now has in her 'hand' (having played the Blue 3 the number of cards in her 'hand' drops from 3 to 2) - Lines 20-30: Information about what is happening with the other players in the game. - Note that Player 2 has picked up a card on Line 20 (added a card to their 'hand'). This would have been due to the fact that they had no valid card to play. Players 3 and Player 4 both have valid cards to play (i.e. they are able to match the top card when it is their turns) - Note that Fiona is given information about the number of cards that each other player has, but not what these cards actually are i.e. the player can only see the cards in their own 'hand'. - Lines 31-33: A summary of the cards that Fiona has in her "hand' prior to taking her turn (Yellow 5 and Red 7) - Lines 35-36: Details of the top card of the 'discard' pile (the last card played by Player 4 - Yellow 2) - Lines 37-41: Details of Fiona's turn. Fiona has played Yellow 5 (Code 26) and now has one card in 'hand'. - Lines 42-53: Information about other player turns (Player 4 has only 1 card left and is on level terms with Fiona) - Lines 54-56: Detials of the card that Fiona has at the start of their turn (Red 7) - Lines 57-58: Details of the top card (Yellow 0) - Lines 59-62: Fiona is unable to match the top card (Yellow 0) with the Red 7 that they have. Fiona enters a Code of 0 to pick up a card. - Lines 63-67: Details of the cards that Fiona now has (Red 7 and Blue 0. The Blue 0 is the card that has been picked up) - Lines 66-74: Information about Player 2 and Player 3 turns - Lines 75-77: Player 4 is able to play their last card. With no more cards Player 4 is declared the winner and the game is over. Task 8: Data storage and manipulation Display 6.1: BooksAuthors table Display 6.2: ISBN table 1. Write an SQL statement to create the BooksAuthorsTable shown in Display 6.1 2. Write an SQL select statement to obtain two columns 4 and 1 from BooksAuthorsTable as shown in ISBN table in Display lay 6.2. 3. What is the difference between the execute and executeQuery methods of the JDBC Statement class Task 0: Programing Environment You are given a NetBeans Java project called QuattroGame. There are nine classes as shown in the UML class diagram (in Figure 1) in a package called unoquattro as shown in Figure 3. QuattroGame Source Packages unoquattro Card.java ColourCard.java - Player.java - QuattroGame.java - QuattroGameTester.java - SpecialAbility.java - 4 SpecialColourCard.java - StandardColourCard.java - WildCard.java Dependencies Java Dependencies Project Files Figure 3: Netbeans project structure In this project, the class QuattroGameTester is complete i.e. you don't have to work on itStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started