I'm writing a text adventure java game and I'm having trouble calling my enemy class this is what I wrote in the enemy class: package package01; import java.util.Random; public class Enemy { private String name; private int hp; private int attackPower; public Enemy(String name, int hp, int attackPower) { this.name = name; this.hp = hp; this.attackPower = attackPower; } public static Enemy getRandomEnemy() { Random rand = new Random(); // Generate random attributes for the enemy String[] names = {"Zombie", "Spider", "Assassin"}; String name = names[rand.nextInt(names.length)]; int hp = rand.nextInt(100) + 1; // Random HP between 1 and 100 int attackPower = rand.nextInt(10) + 1; // R
I'm writing a text adventure java game and I'm having trouble calling my enemy class this is what I wrote in the enemy class:
package package01;
import java.util.Random;
public class Enemy {
private String name;
private int hp;
private int attackPower;
public Enemy(String name, int hp, int attackPower) {
this.name = name;
this.hp = hp;
this.attackPower = attackPower;
}
public static Enemy getRandomEnemy() {
Random rand = new Random();
// Generate random attributes for the enemy
String[] names = {"Zombie", "Spider", "Assassin"};
String name = names[rand.nextInt(names.length)];
int hp = rand.nextInt(100) + 1; // Random HP between 1 and 100
int attackPower = rand.nextInt(10) + 1; // Random attack power between 1 and 10
// Return a new enemy with the random attributes
return new Enemy(name, hp, attackPower);
but when I try to run it in the story class I keep getting errors how can i fix this
Trending now
This is a popular solution!
Step by step
Solved in 2 steps