Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im doing a program that uses superclasses and subclasses. Players can attack each other with weapons. When a Player is attacked, the player suffers damage.

Im doing a program that uses superclasses and subclasses. Players can attack each other with weapons. When a Player is attacked, the player suffers damage. In my player class I want to:

Write a void method sufferDamage(int damage) in the Player class. When this method is called on a player, the player's health points are reduced by the given amount of damage. Damage never goes below 0.

public void sufferDamage(int damage) { // the player's health is reduced by damage points (Im using this.health for players health) }

Attack takes three arguments: an opponent to attack, a weapon to attack the opponent with, a boolean isUltimate, specifying whether this is an ultimate attack. The attack method should reduce the opponent's health level by the weapon's damage amount. This method should use the sufferDamage method you wrote earlier. Make sure you have enough manna to attack. You must have at least the weapon's cost in manna to do any damage. Without sufficient manna, the attack produces no damage in your opponent. The Player's manna is reduced by the cost of using the weapon. If it is an ultimate move, the Player's manna is reduced to 0.

public void attack(Player opponent, Weapon weapon) { ..(im using this.manna, this.cost ,this.damage }

In my other superclass Potion: Players can restore their health by drinking potions. I want to Write a void method drink() that takes a Potion as an argument. It should increase the Player's health points by the potion's benefit. However, the maximum health of a Player is 100 and cannot increase beyond that. public void drink(Potion potion) { ... (Im using this.benefit for potion benefit) }

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

How is communication important to business? Section C

Answered: 1 week ago