Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 3: You are required to build a mini game. The Game consists of a base class (Creature), 2 derived classes of type Creature (Monster

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Exercise 3: You are required to build a mini game. The Game consists of a base class (Creature), 2 derived classes of type Creature (Monster and Player) and Dragon class derived from Monster. In addition to Game class that manages creatures. The class hierarchies are shown below: Creature Class public Player Class + Creature Methods -Player Attack DrawOnScreen Fields creatureName FirePower Health is killed Game Class Dragon Class + Monster Player Fields creaturesList objCnt Methods AddCreature drawAll Creatures Fight public public Methods Creature Attack Creature Dec Health Draw OnScreen getName move SamePosition Monster Class + Creature Methods - Monster Attack DranOnScreen Monster Fields age CanFire Methods - Dragon Attack Dragon DrawOnScreen Grow Up Game MoveCreature RemoveCreature Description of each class: Creature class: This is the base class of all game creatures. Each creature has its own name, its position (x, y), its status if it has been killed yet or not, and has health and fire power. Creatures may attack each other but each creature may attack under certain conditions and each has its own way of attacking. Implement the getters and setters of a creature's attributes. Player class: The player is a creature which can attack any other creature. It has the following functions: a) DrawOnScreen(): display all information about the player. b) Attack(Creature) which decrease the attacked creature's health by (2 * Player fire power). It returns true if attacked creature is killed, and returns false otherwise. Monster class: The monster is a creature that can attack only Player. It does not attack any other creatures. It has the following functions: a) DrawOnScreen(): display all information about the Monster. b) Attack(Creature): It attacks Player only and decreases its health by Monster fire power. It returns true if Player is killed, and returns false otherwise Dragon class: Dragon is a blind Monster which can attack other monsters and dragons in addition to attacking Player. However, for a Dragon to attack, its age must be greater than 10. "CanFire" data member is used to store Dragon's ability to attack. It has the following functions: a) DrawOnScreen(): display all information about the Dragon b) Attack(Creature): If a Dragon can fire, it will attack the given creature by decreasing its health by (age/5 + fire power). It returns true if attacked creature is killed, and returns false otherwise. Game class: Class Game is the class that controls the game logic. It has a list of creatures (creatures List). It has the following functions: a) AddCreature(Creature): add new creature to the list b) DrawAllCreatures(): print all information about all creatures in the list c) RemoveCreature(killedCrt): Removes a killed creature from the list i. It first prints the name of the creature to be removed ii. Then removes that creature from the list d) Fight(ertl, crt2): i. Makes crl attack crt2 and crt2 attack crtl ii. If any of them is killed, remove it from the list and end the fight iii. Calls DrawAllCreatures() to show the fight effect. iv. If none is killed repeat the above three steps until anyone kills the other. e) MoveCreature(CrtName, x, y): Moves a creature, given its name to position x, y. If there is another creature at position (x, y), function Fight(..) is called for the two creatures at the same position to fight each other. Use the provided driver code to test your output against the following output: Add Creatures Alive Creatures Player ---> Name = P. Position = (5,2), Health = 20, Fire Power = 7 Dragon ---> Name - dl. Position - (10, 10), Health - 20, Fire Power - 3. Age - 15, Can Fire: True Dragon ---> Name = d2, Position = (10. 15), Health = 26, Fire Power = 6. Age = 16. Can Fire: True Monster ---> Name - mi, Position - (2, 2), Health = 6, Fire Power - 4 Monster ---> Name = m2, Position = 120, 20), Health = 20, Fire Power = 100 Fight Between Dragon2 and Monster2 Alive Creatures Player ---> Name - B, Position - (5,2), Health - 20, Pire Power - 7 Dragon ---> Name = dl, Position = (10, 10). Health = 20. Fire Power = 3. Age = 15. Can Fire: True Dragon ---> Name - d2, Position - (20, 20), Health - 26. Fire Power 6, Age - 16, Can Fire: True Monster --> Name = mi, Position = (2, 2), Health = 6, Fire Power = 4 Monster ---> Name - m2, Position - (20, 20), Health - 10.8, Fire Power - 100 Alive Creatures Player ---> Name - B, Position - 15, 2), Health - 20, Fire Power - 7 Dragon ---> Name = di, Position = (10, 10), Health = 20, Fire Power = 3, Age = 15, Can Fire: True Dragon ---> Name - d2, Position - (20, 20), Health - 26, Fire Power - 6. Age - 16. Can Fire: True Monster ---> Name = mi, Position = (2, 2), Health = 6, Fire Power = 4 Monster ---> Name = m2, Position - 20. 20), Health - 1.6000000000000014, Fire Power = 100 Creature m2 has been killed! Alive Creatures Player ---> Name - P. Position - (5.2), Health - 20. Fire Power - 7 Dragon ---> Name = di, Position = (10. 10), Health = 20. Fire Power = 3, Age = 15. Can Fire: True Dragon ---> Name = d2, Position - (20, 20), Health - 26, Fire Power = 6, Age - 16, Can Fire: True Monster ---> Name = ml, Position = (2, 2), Health = 6, Fire Power = 4 Move Dragon2 to unoccupied position Pight Between Dragonl and Dragon2 Fight Between Dragoni and Dragon2 Alive Creatures Player ---> Name - P, Position - 15, 2), Health - 20, Fire Power = 7 Dragon ---> Name = d1, Position - (4, 9), Health - 10.8. Fire Power = 3, Age - 15, Can Fire: True Dragon ---> Name - d2, Position = (4.9), Health = 20.0, Fire Power = 6, Age - 16, Can Fire: True Monster ---> Name = m. Position = (2, 2), Health = 6, Fire Power - 4 Alive Creatures Player ---> Name - P. Position - 15, 2), Health - 20. Fire Power - 7 Dragon ---> Name - dl. Position = (4.9) Health - 1.6000000000000014, Fire Power = 3. Age = 15, Can Fire: True Dragon ---> Name - d2, Position - (4, 9), Health - 14.0, Fire Power = 6, Age - 16. Can Fire: True Monster ---> Name = ml, Position - (2, 2), Health - 6. Fire Power - 4 creature dl has been killed! Alive Creatures Player ---> Name - P, Position - (5,2), Health - 20, Fire Power - 7 Dragon ---> Name - d2. position = ( 49) Health - 8.0, Fire Power - 6, Age - 16. Can Fire: True Monster ---> Name - mi, Position - (2, 2), Health - 6, Fire Power - 4 Fight Between Player and Dragon2 Creature d2 has been killed! Alive Creatures Player ---> Name - P. Position = (4.9), Health - 10.8, Fire Power = 7 Monster ---> Name - ml, Position - (2, 2), Health - 6, Fire Power - 4 - Fight Between Player and Monster1 Creature mi has been killed! Alive Creatures Player ---> Name = P. Position = (2, 2), Health = 6.800000000000001, Fire Power = 7 >>>

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

What is the coefficient for NO. DEGREES b2?

Answered: 1 week ago

Question

=+ Is this unemployment undesirable?

Answered: 1 week ago