//Beta 1.0 版本
1.实现了角色类的定义,分为Man与Monster。
2.实现了血量统计与报告。
3.增加了死亡后无法攻击与无法被攻击的判断,防止出现不死的BUG。
package com.company;
public class Main {
public static void main(String[] args) {
Man man = new Man();
man.name = "Eric";
man.weapon = "圣殿皇家巨剑";
man.HP = 100;
man.isalive=true;
Monster monster=new Monster();
monster.type="地狱犬";
monster.HP = 40;
monster.isalive=true;
Monster monster1=new Monster();
monster1.type="玉藻前";
monster1.HP=100;
monster1.isalive=true;
int i;
for(i=0;man.isalive;i++) {
monster.kill(man);
System.out.println();
man.hit(monster);
System.out.println();
monster1.kill(man);
System.out.println();
man.hit(monster1);
System.out.println();
}
}
}
class Man{
String name;
String weapon;
int HP;
boolean isalive;
public void hit(Monster monster){
if(!monster.isalive) {
return;
}
if(!isalive) {
return;
}
System.out.println(name+":挥舞着"+weapon+"无情的制裁了"+monster.type);
monster.injured();
}
public void injured(){
HP-=20;
System.out.println(name+":你敢打老子?");
if(HP<=0){
dead();
return;
}
if(!isalive) {
return;
}
show();
}
public void dead(){
isalive=false;
System.out.println("系统提示:"+name+"已经牺牲了");
}
public void show(){
System.out.println("系统提示:"+name+"还剩下"+HP+"点生命值");
}
}
class Monster{
String type;
int HP;
boolean isalive=true;
public void kill(Man man){
if(!man.isalive) {
return;
}
if(!isalive) {
return;
}
System.out.println(type+":撕咬着"+man.name);
man.injured();
}
public void injured(){
HP-=20;
System.out.println(type+":Aaaa~");
if(HP<=0){
dead();
return;
}
if(!isalive) {
return;
}
show();
}
public void dead(){
isalive=false;
System.out.println("系统提示:"+type+"已经被干掉了");
}
public void show(){
System.out.println("系统提示:"+type+"还剩下"+HP+"点生命值");
}
}
网友评论