Class Main
//Beta 2.1
//1 增加了属性:经验值,最大生命,当前生命,当前等级,实现升级功能,以及升级后的攻击力,防御力,回满血等属性变动。
//2 优化了部分文本消息
package com.company;
public class Main {
public static void main(String[] args) {
Man p1=new Man("勇者","菜刀");
Monster m1=new Monster(1);
Monster m2=new Monster(2);
Monster m3=new Monster(3);
Monster m4=new Monster(4);
}
}
Class Man
package com.company;
public class Man{
String name;
String weapon;
//生命值改造;
int maxHP;
int culHP;
boolean isalive;
int attack;
int defend;
//增加经验值与等级
int exp=0;
int maxExp=100;
int level=1;
public Man(String name,String weapon){
this.name=name;
this.weapon=weapon;
maxHP=400;
culHP = 400;
isalive =true;
attack=30;
defend=20;
}
public void hit(Monster monster){
if(!monster.isalive) {
return;
}
if(!isalive) {
return;
}
System.out.println(name+"挥舞着"+weapon+"无情的制裁了"+monster.type+"。");
monster.injured(this);
}
public void injured(Monster monster){
int lostHP;
int lostBase=5;
lostHP=monster.attack-this.defend;
if(lostHP<=0){
culHP-=lostBase;
}else{
culHP-=lostHP+lostBase;
}
if(culHP<=0){
dead();
return;
}
if(!isalive) {
return;
}
show();
}
public void dead(){
isalive=false;
System.out.println("###################系统提示###################:"+"\n"+name+"已经牺牲了。"+"\n");
}
public void show(){
System.out.println("###################系统提示###################:"+"\n"+"伟大的"+name+"当前生命值为"+culHP+"/"+maxHP
+"点生命值"+",攻击力为"+attack+",防御力为"+defend+
",经验值为"+exp+"/"+maxExp+"。"+"\n");
}
public void upLevel(){
if(exp>=maxExp){
level++;
exp=exp-maxExp;
maxExp+=level*50;
attack+=10;
defend+=5;
maxHP+=30*level;
culHP=maxHP;
System.out.println("###################系统提示###################:"+"\n"+name+"升级了,当前等级为"+level+"。"+"\n");
}
}
}
Class monster
package com.company;
class Monster{
String type;
String way;
int culHP;
boolean isalive;
int attack;
int defend;
int getExp;
public Monster(int mt){
isalive=true;
if(mt==1){
type="地狱小犬";
way="疯狂地撕咬着";
culHP=40;
attack=15;
defend=10;
getExp=30;
}else if(mt==2){
type="地狱法师";
way="召唤出地狱亡灵攻击了";
culHP=30;
attack=25;
defend=5;
getExp=50;
}else if(mt==3){
type="地狱火";
way="身旁的火焰灼伤了";
culHP=60;
attack=5;
defend=25;
getExp=80;
}else if(mt==4){
type="BOSS";
way="聚集了邪恶力量包裹着";
culHP=350;
attack=40;
defend=25;
getExp=150;
}
}
public void kill(Man man){
if(!man.isalive) {
return;
}
if(!isalive) {
return;
}
System.out.println(type+way+man.name+"。");
man.injured(this);
}
public void injured(Man man){
int lostHP;
int lostBase=1;
lostHP=man.attack-this.defend;
if(lostHP<=0){
culHP-=lostBase;
}else{
culHP-=lostHP+lostBase;
}
if(culHP<=0){
dead(man);
return;
}
if(!isalive) {
return;
}
show();
System.out.println(type+"发起了反击!");
kill(man);
}
public void dead(Man man){
isalive=false;
man.exp+=getExp;
System.out.println("###################系统提示###################:"+"\n"+type+"已经被干掉了。"+"\n");
man.upLevel();
man.show();
}
public void show(){
System.out.println("###################系统提示###################:"+"\n"+type+"还剩下"+culHP+"点生命值"
+",攻击力为"+attack+",防御力为"+defend+"。"+"\n");
}
}