/**
* Java语言实现的一个回血程序
* 每隔0.1秒回血1-5点
*/
public class Huixue{
public static void main(String[] args){
//当前血量
int chp = 204;
//最大血量
final int MAXHP = 600;
//回血循环
while(chp < MAXHP){
//暂停0.1秒
try{
Thread.sleep(100);
}catch(Exception e){
}
int d = (int)(Math.random() * 4) + 1;
//回血
chp = chp + d;
//如果回血超过最大血量,则修改为最大血量
if(chp > MAXHP){
chp = MAXHP;
}
System.out.println(chp);
}
}
}