public class Hunter {
String name;
int life; //生命值
String weapon; //武器
boolean isLive; //是否活着
int att; // 人类的伤害值
int blood; // 僵尸剩余血量
Hunter(String name,int life,String weapon,boolean isLive){ //构造方法
this.name=name;
this.life=life;
this.isLive=isLive;
if(weapon.equals("大型武器")){ //选择武器
att=50;
}else{
att=20;
}
}
public void fight(Monster m){ //定义一个方法,僵尸暂时的状态。
m.life=m.life-att; //调用僵尸生命值=生命值-伤害值
blood=m.life;
if(blood<=0){
m.dead();
}else{
m.injured();
show();
}
}
public void injured(){ //三个方法
System.out.println(name+"受伤了");
}
public void dead(){
System.out.println(name+"已经死亡");
}
public void show(){
System.out.println("此时还剩余:"+blood+"HP");
}
}
public class Monster {
String type; //类型
boolean isLive;
int life;
int arr; //僵尸伤害值
int bloodd; //猎人剩余血量
Monster(String type,boolean isLive,int life){
this.type=type;
this.isLive=isLive;
this.life=life;
if(type.equals("僵尸王")){ //僵尸类型
life=1000;
arr=30;
}
if(type.equals("小僵尸")){
life=700;
arr=20;
}
}
public void injured(){ //定义一个受伤的方法
System.out.println(type+"受伤");
}
public void kill(Hunter h){
h.life=h.life-arr;
bloodd=h.life;
if(bloodd<=0){
h.dead();
}else{
h.injured();
show();
}
}
public void dead(){
System.out.println("僵尸死亡");
}
public void show(){
System.out.println("此时还剩余"+bloodd+"HP");
}
}
public class TestGame {
public static void main(String[] args) {
Hunter h=new Hunter("强强猎人",500,"大型武器",true); //创建猎人的对象
Monster m=new Monster("僵尸王",true,1000); //创建僵尸的对象
for(int i=1;;i++){
System.out.println();
System.out.println("第"+i+"回合");
h.fight(m);
m.kill(h);
if(h.life<=0){
System.out.println(h.name+"已经阵亡,游戏结束");
break;
}if(m.life<=0){
System.out.println(m.type+"已经阵亡,游戏技术");
break;
}
}
}
}