这些是我使用的类和主要方法。它应该向用户输出提示,以便管理很少的战斗"。为什么它没有输出呢?
public class Hero
{
private String name;
private int health;
private int strength;
private int agility;
private int stamina;
Die die1;
Die die2;
Die die3;
public Hero(String name)
{
this.name = name;
this.health = 50;
this.stamina = 25;
this.strength = 5;
this.agility = 5;
}
public void setName(String Name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setHealth(int health)
{
this.health = health;
}
public int getHealth()
{
return health;
}
public void setStrength(int strength)
{
this.strength = strength;
}
public int getStrength()
{
return strength;
}
public void setAgility(int agility)
{
this.agility = agility;
}
public int getAgility()
{
return agility;
}
public void setStamina(int stamina)
{
this.stamina = stamina;
}
public int getStamina()
{
return stamina;
}
public int addHealth()
{
if(health < 45 || health >= 0)
{
health = health + 5;
}
return health;
}
public int removeHealth()
{
if(health <= 50 || health >= 5)
{
health = health - 5;
}
return health;
}
public int addStamina()
{
if(stamina <= 20 || stamina >= 0)
{
stamina = stamina + 5;
}
return stamina;
}
public int removeStamina()
{
if(stamina <= 25 || stamina >= 5)
{
stamina = stamina - 5;
}
return stamina;
}
private void rest()
{
health = health + addHealth();
stamina = stamina + addStamina();
}
public int attack(int damage)
{
die1 = new Die(20);
die1.roll();
if(stamina <= 5)
{
rest();
}
else
{
damage = strength + die1.getValue();
stamina = stamina - 6;
}
return damage;
}
public int defend(int block)
{
die1 = new Die(20);
die1.roll();
if(stamina <= 3)
{
rest();
}
if(die1.getValue() <= 6)
{
block = getAgility() + (die1.getValue() * 2);
}
else
{
block = getAgility() + (die1.getValue());
}
stamina = stamina - 4;
return block;
}
public void printStats()
{
System.out.println("Thy hero's name is: " + getName());
System.out.println("Thy strengh is: " + getStrength());
System.out.println("Thy agility is: " + getAgility());
System.out.println("Thy stamina is " + getStamina());
System.out.println("Thy health is: " + getHealth());
}
}
public class Battle_Manager
{
public static void main(String[] args)
{
Hero hA = new Hero("Ayy");
Hero hB = new Hero("Bee");
Die die1 = new Die(12);
Die die2 = new Die(8);
Die die3 = new Die(6);
die1.roll();
die2.roll();
die3.roll();
}
}
import java.util.Random;
public class Die
{
private int sides;
private int dieValue;
public void roll()
{
Random r = new Random();
dieValue = (r.nextInt(sides) + 1);
}
public int getSides()
{
return sides;
}
public void setSides(int sides)
{
this.sides = sides;
}
public Die()
{
sides = 1;
dieValue = 1;
}
public Die (int sides)
{
sides = 1;
dieValue = 1;
if(sides >= 0)
{
this.sides = sides;
}
}
public int getValue()
{
int value = dieValue;
return value;
}
}
&#13;
这些是我使用的类和主要方法。它应该向用户输出提示,以便管理很少的战斗&#34;。为什么它没有输出呢?
答案 0 :(得分:1)
我没有看到任何提示用户输入的代码。您可以查看How can I get the user input in Java?以引导您提示用户输入。打印到控制台后,您需要一个Scanner和System.in。你可能也想打电话给Hero的printStats。