5、Player.java
package com.home.jiangfan;
public class Player {
//玩家人物属性
public int id,lv,hp,mp,attack,armor,exp,weapon;
public String name,skill,iteams;
//玩家人物普通攻击方法
public void generalAttack(Monster a){
a.hp-=this.attack;
System.out.println("你对"+a.name+"发起了普通攻击!造成了:"+this.attack+"点伤害");
}
//玩家人物法术攻击方法
public void magicAttack(Monster a){
a.hp-=this.attack+this.mp;
this.mp=this.mp-this.lv*10;
System.out.println("你对"+a.name+"使用了:"+skill+"造成了:"+(this.attack+this.lv*10)+"点伤害");
}
//玩家逃跑事件
public void escape(){
System.out.println("你感觉不妙,所以转身拔腿就跑!");
}
//玩家死亡
public void fail(Monster a){
System.out.println(a.name+",战胜了你!大侠请重新来过~");
this.hp = this.lv*100;
}
//玩家胜利事件
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*100;
this.mp = lv*30;
this.attack = (lv*lv+10)*lv+this.weapon;
this.armor = lv*lv;
this.skill = skill;
this.iteams = iteams;
this.name = name;
this.exp=0;
}
}
6、UserFace.java
package com.home.jiangfan;
import java.util.*;
public class UserFace {
public String name;
//欢迎提示
public void welcome(){
System.out.println("您好!欢迎进入游戏!");
System.out.println("现在创建新人物,请您输入人物昵称:");
Scanner in=new Scanner(System.in);
this.name=in.nextLine();
}
//显示人物当前数据
public void printPlayer(Player p){
System.out.println("人物昵称:"+p.name);
System.out.println("等级:"+p.lv);
System.out.println("hp:"+p.hp);
System.out.println("mp:"+p.mp);
System.out.println("攻击力:"+p.attack);
System.out.println("防御力:"+p.armor);
System.out.println("技能:"+p.skill);
System.out.println("装备:"+p.iteams);
System.out.println("当前经验:"+p.exp);
System.out.println("升级到下级所需经验:"+(p.lv+p.lv)*10);
System.out.println("");
System.out.println("按任意键继续");
Scanner in=new Scanner(System.in);
String choose=in.nextLine();
printOperations(p);
if(choose==null || choose==""){
printOperations(p);
}
}
public void printMonster(Monster m,Player p){
System.out.println("怪物名称:"+m.name);
System.out.println("等级:"+m.lv);
System.out.println("hp:"+m.hp);
System.out.println("mp:"+m.mp);
System.out.println("攻击力:"+m.attack);
System.out.println("防御力:"+m.armor);
System.out.println("技能:"+m.skill);
System.out.println("");
System.out.println("按任意键继续");
Scanner in=new Scanner(System.in);
String choose=in.nextLine();
printOperations(p);
if(choose==null || choose==""){
printOperations(p);
}
}
//游戏操作总菜单
public void printOperations(Player player){
Operations o1=new Operations();
System.out.println("1,刷怪练级 2,挑战Boss 3,治疗 4,人物状态");
Scanner in=new Scanner(System.in);
int choose=in.nextInt();
if(choose==1){
o1.lianji(player);
}
if(choose==2){
System.out.println("挑战boss");
}
if(choose==3){
o1.heal(player);
System.out.println("治疗");
}
if(choose==4){
printPlayer(player);
}
}
//程序入口点
public static void main(String[] args){
//创建人物
UserFace uf=new UserFace();
uf.welcome();
Player p1=new Player(1,1,"天神下凡","黑龙*爪",uf.name);
//uf.printPlayer(p1);
System.out.println(p1.name+",欢迎进入梦游世界!");
//新人物进入操作界面
uf.printOperations(p1);
}
}