1. Engineering
  2. Computer Science
  3. 24 game 20 marks the class game implements the logic...

Question: 24 game 20 marks the class game implements the logic...

Question details

2.4 Game (20 marks) The class Game implements the logic of the single player game of Rummy An object of the class Game has two decks of cards, one is the main deck, whereas the second one represents the players . hand. An object of the class Game also has a die (reference to an object of the class Die) game. When a Game object is created, it also creates the main deck and the die. A Game object has only one public instance method, which is called play. The method implements the logic of the . The class declares one constructor. This constructor has one parameter, which specifies the number of ranks for this game Here is a description of the game: Step 0. The strange deck is created and shuffled. (In order to test your game more quickly you can reduce the number of ranks to less than 13 and more than 3). In your implementation, the created deck is an object of the class Deck. Top of the deck is considered the last card. .Step 1. The player is dealt 7 cards from the top of the strange deck . Step 2. The following steps are repeated until the player runs out of the cards i.e. until the players hand is empty: The player rolls a die: * If the player gets a l The player can discard any one card she likes. After that, the current round is over and the game goes back to Step 2 If instead the player gets 2, 3, 4, 5 or 6: The player is first delt, from the top of the deck, a number of cards corresponding to the value of the die, or size of the deck of cards, whichever is smaller. The player then keeps un discarding illelds from her hand until she has no more melds. You program has to check that the set of cards that the player chooses indeed forms a valid meld before discarding them from the players hand. Once she decides she is out of melds, the round is over and the game goes back to Step 2
Here is a description of the game: Step 0. The strange deck is created and shuffled. (In order to test your game more quickly you can reduce the number of ranks to less than 13 and more than 3). In your implementation, the created deck is an object of the class Deck. Top of the deck is considered the last card. Step 1. The player is dealt 7 cards from the top of the strange deck. . Step 2. The following steps are repeated until the player runs out of the cards i.e. until the players hand is empty: - The player rolls a die: If the player gets a The player can discard any one card she likes. After that, the current round is over and the game goes back If instead the player gets 2, 3, 4, 5 or 6 The player is first delt, from the top of the deck, a number of cards corresponding to the value of the die, or size of the deck of cards, whichever is simaller. The player then keeps on discarding melds from her hand until she has no more melds. You program has to check that the set of cards that the player chooses indeed forms a valid meld before discarding them from the players hand. Once she decides she is out of melds, the round is over and the game goes back to Step 2 Finally, once the player is out of cards (i.e. once the players hand is empty), the total number of rounds is reported and Note that if the deck is empty and the player has no more melds, no melds can ever be created again. Thus the player has to wait for 1 on the die. In order to avoid that frustration, your game should roll 1 i.e. set num to 1, in each round that starts with As usual, whenever you ask the player for some input you should make sure they give you the required kind of input. You may assume that the player will follow instructions and give you a correct type of data, but not the correct values. For example, if you are asking for an integer between 3 and 99, you may assume that the player will give you an integer, but not that she will give you an integer in the correct range. Thus you should keep on repeating the question until you get a valid answer. Similarly if you ask the player for a meld, you may assume that the player will give you a set of 3 cards, but you will need to test if these cards are indeed in the players hand and that they form a meld. We provide you with several methods to help you with this part of the assignment. See 02/Utils.java.
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution