Question: Question Goal: Learn how to extend classes. Assignment: Imagine you're developing a video game. Your project includes a Gameobject class and a Playercharacter subclass. The

Question
Goal: Learn how to extend classes.
Assignment: Imagine you're developing a video game. Your project includes a Gameobject class and a
Playercharacter subclass.
The Garreobject class includes:
a private string attribute name, with corresponding getter and setter;
a pivate double array attribute position, with corresponding getter and setter;
a constructor Gameobject (String name, double[] position);
a public method draw() that renders the object on screen.
a public method erase() that makes the character disappear from the screen.
The Playercharacter class extends Gameobject with:
a private int attribute health, with corresponding getter and setter;
a constructor Playercharacter(String name, double[] position, int health);
a public method attack(PlayerCharacter playerToAttack) that allows the character to attack
another character and diminish its health by 5 points.
Write a code snippet that simulates a fight by following these steps:
Create a first Playercharacter object wizard withthe following attributes: name "Wizard", position
(4.0,-5.5), and initial health of 10 points.
Create a second Playercharacter object orc with the following attributes: name "Orc", position
(-4.0,5.5), and initial health of 5 points.
Draw both the characters on screen;
Make the wizard attack the orc and make the orc disappear from the screen.
Don't declare any other variable to accomplish this task.
Question Goal: Learn how to extend classes.

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 Programming Questions!