【发布时间】:2018-03-18 11:48:10
【问题描述】:
我如何设置最大数量,以使某个变量不能超过我的代码中的限制,玩家可以反复去治疗,因此他们的健康变得超过他们的最大生命值
public class HEAL {
public static int maxhp = 25;
public static int hp = 10;
public static void main(String[] args) throws IOException {
heal();
}
public static void heal() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Would you like me to heal you? \n[1] Yes\n[2]No");
int choice = Integer.parseInt(br.readLine());
if (choice == 1) {
System.out.println("You have been healed for 10 hp");
HEAL.hp = HEAL.hp + 10;
System.out.println("Your current HP: "+HEAL.hp);
}
else if (choice == 2) {
System.out.println("Leave");
}
}
}
【问题讨论】:
-
你在这方面真的尝试过吗?