4、JudgementPK.java
package com.home.jiangfan;
public class JudgementPK {
//判断等级提升
public void judgementLv(Player player){
if(player.exp>=(player.lv+player.lv)*10){
player.lv++;
player.hp = player.lv*200;
player.mp = player.lv*30;
player.attack = (player.lv*player.lv+10)+player.weapon;
player.armor = player.lv*(player.lv-1);
player.exp=0;
System.out.println("★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★");
System.out.println("恭喜您~等级提升到:"+player.lv);
System.out.println("您的hp提升到:"+player.hp);
System.out.println("您的mp提升到:"+player.mp);
System.out.println("您的攻击力提升到:"+player.attack);
System.out.println("您的防御力提升到:"+player.armor);
}
}
//普通攻击
public void judgementGA(Player player,Monster monster){
if(player.hp>0 && monster.hp>0){
player.generalAttack(monster);
monster.generalAttack(player);
System.out.println("本回合较量完毕!");
System.out.println("你的当前hp:"+player.hp);
System.out.println("敌人当前hp:"+monster.hp);
//处理玩家死亡
if(player.hp<=0){
player.fail(monster);
System.out.println("战斗结束!");
player.exp-=player.lv*50;
System.out.println("损失经验:"+player.lv*30);
if(player.exp<0){
player.exp=0;
}
//返回主菜单
UserFace back=new UserFace();
back.printOperations(player);
}
//处理怪物死亡
if(monster.hp<=0){
player.victory(monster);
System.out.println("战斗结束!");
player.exp+=monster.lv*10;
System.out.println("战斗获得经验值:"+monster.lv*10);
player.gold+=monster.lv*40;
System.out.println("战斗获得梦游币:"+monster.lv*40);
judgementLv(player);
//返回主菜单
UserFace back=new UserFace();
back.printOperations(player);
}
}
}
//法术攻击
public void judgementMA(Player player,Monster monster){
if(player.hp>0 && monster.hp>0){
//判断玩家mp是否足够释放技能,如果通过就执行下面
if(player.mp>=player.lv*10){
player.magicAttack(monster);
monster.generalAttack(player);
System.out.println("本回合较量完毕!");
System.out.println("你的当前hp:"+player.hp);
System.out.println("敌人当前hp:"+monster.hp);
}
//玩家mp不足执行下面
else{
System.out.println("mp不足!");
monster.generalAttack(player);
System.out.println("mp不足,无法施放技能!!");
System.out.println("敌人对你造成:"+monster.attack+"点伤害!");
System.out.println("你的当前hp:"+player.hp);
System.out.println("敌人当前hp:"+monster.hp);
}
//处理玩家死亡
if(player.hp<=0){
player.fail(monster);
System.out.println("战斗结束!");
player.exp-=player.lv*50;
System.out.println("损失经验:"+player.lv*30);
if(player.exp<0){
player.exp=0;
}
//返回主菜单
UserFace back=new UserFace();
back.printOperations(player);
}
//处理怪物死亡
if(monster.hp<=0){
player.victory(monster);
System.out.println("战斗结束!");
player.exp+=monster.lv*10;
System.out.println("战斗获得经验值:"+monster.lv*10);
player.gold+=monster.lv*40;
System.out.println("战斗获得梦游币:"+monster.lv*40);
judgementLv(player);
//返回主菜单
UserFace back=new UserFace();
back.printOperations(player);
}
}
}
}
5、Player.java
package com.home.jiangfan;
public class Player {
//玩家人物属性
public int id,lv,hp,mp,attack,armor,exp,weapon,gold,bag1,bag2;
public String name,skill,iteams,bagIteam1,bagIteam2;
//玩家人物普通攻击方法
public void generalAttack(Monster a){
if(a.armor>=this.attack){
a.hp-=1;
System.out.println("你对"+a.name+"发起了普通攻击!造成了:1点伤害");
}else{
a.hp-=this.attack-a.armor;
System.out.println("你对"+a.name+"发起了普通攻击!造成了:"+(this.attack-a.armor)+"点伤害");
}
}
//玩家人物法术攻击方法
public void magicAttack(Monster a){
if(a.armor>=this.attack){
a.hp-=1;
System.out.println("你对"+a.name+"使用了:"+skill+"造成了:1点伤害");
}else{
a.hp-=this.attack+this.lv*20-a.armor;
this.mp=this.mp-this.lv*10;
System.out.println("你对"+a.name+"使用了:"+skill+"造成了:"+(this.attack+this.lv*10-a.armor)+"点伤害");
}
}
//玩家逃跑事件
public void escape(){
System.out.println("你感觉不妙,所以转身拔腿就跑!");
}
//玩家死亡
public void fail(Monster a){
System.out.println(a.name+",战胜了你!大侠请重新来过~");
this.hp = this.lv*200;
}
//玩家胜利事件
public void victory(Monster a){
System.out.println(a.name+",被你打败了!");
}
//构造方法
public Player(){}
public Player(int id, int lv, String skill, String iteams, String name) {
this.weapon=10;
this.id = id;
this.lv = lv;
this.hp = lv*200;
this.mp = lv*30;
this.attack = (lv*lv+10)+this.weapon;
this.weapon=10;
this.armor = lv*(lv-1);
this.skill = skill;
this.iteams = iteams;
this.name = name;
this.exp=0;
this.gold=0;
this.bag1=0;
this.bag2=0;
bagIteam1="无";
bagIteam2="无";
}
}
6、Monster.java
package com.home.jiangfan;
//怪物类
public class Monster {
//怪物属性
public int id,lv,hp,mp,attack,armor;
public String name,skill;
//怪物普通攻击方法
public void generalAttack(Player a){
if(a.armor>=this.attack){
a.hp-=1;
System.out.println(this.name+",对你发起了攻击!造成了:1 点伤害!");
}else{
a.hp-=this.attack-a.armor;
System.out.println(this.name+",对你发起了攻击!造成了:"+(this.attack-a.armor)+" 点伤害!");
}
}
//怪物法术攻击方法(暂时还没用到)
public void magicAttack(Player a){
System.out.println(this.name+",对你使用了"+this.skill);
if(a.armor>=this.attack){
a.hp-=1;
}else{
a.hp-=this.attack+this.lv*20-a.armor;
this.mp=this.mp-this.lv*10;
}
}
//怪物逃跑事件
public void escape(){
System.out.println(this.name+",由于害怕而灰溜溜的逃跑了!");
}
//构造方法
public Monster(){}
public Monster(int id, int lv, String skill, String name) {
super();
this.id = id;
this.lv = lv;
this.hp = lv*100;
this.mp = lv*30;
this.attack = (lv*lv+10);
this.armor = lv*(lv-1);
this.skill = skill;
this.name = name;
}
}
使用说明:见之前的一篇文章
自写游戏(梦游世界)源代码(总结)