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 PlayercharacterString name, double position, int health;
a public method attackPlayerCharacter playerToAttack that allows the character to attack
another character and diminish its health by 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
and initial health of points.
Create a second Playercharacter object orc with the following attributes: name "Orc", position
and initial health of 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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
