I'm building a mini game in which two monsters battle each other (an opponent and the player). When the round starts, the monsters are supposed to fight and their health points decrease by 1, 2, 3, 4 or 5.
I'm using Math.random to randomize the damage dealt to each of the monsters.
How do I decrease each monster's health points when the program is run and the round starts?
Here is my code so far (Monster.java file):
import java.util.Random;
public class Monster {
// Monster properties
private String name;
private int health;
private int damage;
// Random damage points that vary from 1 to 5
int randomDamagePoints = (int)(Math.random() * 1 + 5);
// Constructor
public Monster(String name, int health, int damage) {
this.name = "Monster";
this.health = 50;
this.damage = 2;
}
// Opponent attacks Monster 1 - Player
public void AttackPlayer(Monster player) {
while(health > 0) {
// Part I need help with
}
}
// Player attacks Monster 2 - Opponent
public void AttackOpponent(Monster opponent) {
while(health > 0) {
// Part I need help with
}
}
}
Thank you for your help!
Aucun commentaire:
Enregistrer un commentaire