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+"發(fā)起了普通攻擊!造成了:"+this.attack+"點傷害");
??? }
??? //玩家人物法術(shù)攻擊方法
??? 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("你感覺不妙,所以轉(zhuǎn)身拔腿就跑!");
??? }
??? //玩家死亡
??? public void fail(Monster a){
??? ?System.out.println(a.name+",戰(zhàn)勝了你!大俠請重新來過~");
??? ?this.hp = this.lv*100;
??? ?
??? }
??? //玩家勝利事件
??? public void victory(Monster a){
??? ?System.out.println(a.name+",被你打敗了!");
??? }
??? //構(gòu)造方法
??? 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("現(xiàn)在創(chuàng)建新人物,請您輸入人物昵稱:");
??Scanner in=new Scanner(System.in);
??this.name=in.nextLine();
?}
?//顯示人物當前數(shù)據(jù)
?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("當前經(jīng)驗:"+p.exp);
??System.out.println("升級到下級所需經(jīng)驗:"+(p.lv+p.lv)*10);
??System.out.println("");
??System.out.println("按任意鍵繼續(xù)");
??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("按任意鍵繼續(xù)");
??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,挑戰(zhàn)Boss? 3,治療? 4,人物狀態(tài)");
??Scanner in=new Scanner(System.in);
??int choose=in.nextInt();
??if(choose==1){
???o1.lianji(player);
??}
??if(choose==2){
???
???System.out.println("挑戰(zhàn)boss");
??}
??if(choose==3){
???o1.heal(player);
???System.out.println("治療");
??}
??if(choose==4){
???printPlayer(player);
??}
?}
?
?//程序入口點
?public static void main(String[] args){
??//創(chuàng)建人物
??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);
?}
}