Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Card Game Question? !!! Power Magic Game - *****make sure dont use Array list**** In this program you are to create three classes (Deck/Hand

Java Card Game Question?

!!! Power Magic Game - *****make sure dont use Array list****

In this program you are to create three classes (Deck/Hand and Card). Each of these cards work together to manage the cards in a card game.

In our game we are concentrating on the management of cards. You will create a Card class to represent one card that contains the name, the amount of magic it costs (health) and the damage the card does when used. The class will also have a number of methods related to a single card (See below the table for methods needed). You will also have a Deck which contains an array of Cards (100) and a Hand which contains 5 Cards. Your job is to write the code to represent the Card, Deck and Hand.

You must use a array to store your cards in hand and deck. You are not permitted to use any collection Classes (or Array class methods) in this assignment. You will need to implement the entire class based on the requirements below table. This class will encapsulate all the functionality required. Each method will contain a list of the permissible method calls.

Class Card

public class Card

The representation of single game card. This class defines a card as a playing card that has a name a health Cost (how much magic needed to cast it), and the amount of damage that this card will do to the other player.

Requirement class Card

Fields: int damageDone, String name, int healthCost

Constructor: Card(int healthCost, int damageDone, String name)

Methods: toString, getName, getHealthCost, get damageDone,

toString format Card[name= Lock it link, healthCost = 5, damageDone = 50]

Requirement class Deck

Fields: Card [] cards, boolean random, int cardsRemaining, static int DECKSIZE = 100

Constructor: Deck (boolean random) Whether to turn on the random features. Defaults to false.

**Constructor for the Deck. Add the following cards to the Deck in the following order

4 x Money Chines, Damage 100, health 2

6 x Magic Dreams, Damage 80, health 2

10 x Lock it link, Damage 50, health 5

10 x Dragon riches, Damage 40, health 7

15 x Big Red, Damage 30, health 10

15 x Indian Princes, Damage 15, health 10

40 x Eastern Trader, Damage 5, health 5

Methods: int getCardsRemaining(), Card getRandomCard(), void shuffle(), String - toString

toString format Returns a string representation of the entire deck in the format

Deck [

1:Card [name= Money Chines, healthCost=2, damageDone=100]

2:Card [name= Money Chines, healthCost =2, damageDone=100]

3:Card [name= Money Chines, healthCost =2, damageDone=100]

4:Card [name= Money Chines, healthCost =2, damageDone=100]

]

Public Card getRandomCard - method details

Uses a random number generator to get a card from the deck somewhere then swaps the last card in the deck to that position and reduces the cardsRemaining by one. This is important. if the random flag is false you should always get the card at position 0. When you swap the card out you should also set the old position to null for safety.

Returns: the card drawn or null if no cards left in deck

Class Hand

public class Hand

Represents the current players hand of cards. It tracks five cards in the hand along with the amount of magic the player has.

Requirement class Hand

Fields Deck cardDeck (the deck of cards, int currentHealth (amount of magic), Card [] hand (the current hand of cards), int totalDamage(total amount of damage dealt from this game)

Constructor

public Card play(int cardNumber)

Play a card This is the process of taking a card from your hand and putting it on the table. When you play a card the following process is followed 1. Increase health by 1 2. Check if the specified card number is valid (1-5) (return null on error) 3. Check if there is enough health to use the card (return null on error) 4. Check if there are any more cards left in the deck (return null if out of cards) 5. Reduce the health by the appropriate amount 6. Record the damage done 7. Returns the played card to the caller 8. Add a card to the hand

Parameters: cardNumber - the card to be played (valid range 1-5)

Returns: The card removed from the deck (null if an error)

Methods: -

powerOfHand() - The current power of the cards in the hand or returns the total damage of all cards in hand.

public Card getStrongest() - Get the strongest card from the hand. The card is removed from the hand. If there are two of equal value use the first one you find. Returns - the strongest card in the deck. (Removing it from the hand).

public Card getStrongest(int health)

Get the strongest damage that does not exceed the specified health. The card is removed from the hand. If there are two of equal value use the first one you find.

Parameters: health - the maximum health that can be used.

Returns: the strongest card in hand to a max of health

public Card getCard(int damage)

Get the card that does the specified damage (or next greater) with the least health used. The card is removed from the hand. If there are two of equal value use the first one you find.

Returns: the strongest card with the set damage for the least health

String toString()

String representation of the cards in the hand. Should be in the form

Hand [health=100, hand=

Card [name= Big Red, healthCost=10, damageDone=30]

Card [name=EasternTrader, healthCost =5, damageDone=5]

Card [name= Big Red, healthCost =10, damageDone=30]

Card [name= Big Red, healthCost =10, damageDone=30]

Card [name= Eastern Trader, healthCost=5, damageDone=5]

]

swapOutCard

public Card swapOutCard(int cardNumber)

Swap out a card. Get the card at the designated position then get a new card to replace it.

Parameters: cardNumber - the card to remove from the hand

Returns: the card swapped out

public Card swapOutCard(int cardNumber, Card replacementCard)

Swap out a card from your hand with a card you got from somewhere else. Eg cheaters method.

Parameters:

cardNumber - the card to remove from the hand

replacementCard - the card to replace the current card with

Returns: the Card swapped out

getHealth

public int gethealth()

Return the players current health

Returns: current amount of health

getTotalDamage

public int getTotalDamage()

Return the players total damage done

Returns: total damage

numberOfCardsInHand

public int numberOfCardsInHand()

Debug function for checking checking the hand is full with 5 cards. If working correctly should never be anything but 5. Returns:number of cards in hand

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

Elucidate the difference between data and information

Answered: 1 week ago

Question

=+ (c) The same, but suppose that 22 is uncountable.

Answered: 1 week ago