📄 player.java
字号:
import java.util.Random;
import java.util.Scanner;
import java.util.Vector;
public class Player {
static String name = "";
static int x = 0;
static int y = 0;
static int maxHP = 500;
static int maxMP = 200;
static int HP = 500;
static int MP = 200;
static int attack = 100;
static int defence = 15;
static int money =0;
private int speed = 1;
private int point = 0;
static int Exp = 0;
static int LV = 1;
static Vector Utools = new Vector();
static Vector Phead = new Vector();
static Vector Pbody = new Vector();
static Vector Pshoes = new Vector();
static Vector Parm = new Vector();
static Vector skill =new Vector();
String head = "没有头部装备。";
String body = "没有身体装备。";
String shoes = "没有脚部装备。";
String arm = "没有武器";
public Player() {
System.out.print("请输入玩家的名字:");
Scanner s = new Scanner(System.in);
String s2 = s.next();
name = s2;
initPosition();
Phead.addElement("N.牛仔帽(+防御力 5)");
Pbody.addElement("N.牛仔衣(+防御力 10)");
Pshoes.addElement("P.皮靴(+防御力 5)");
Parm.addElement("S.闪灵手枪(+攻击力 20)");
}
/**
* 玩家状态
*/
static void state() {
System.out.println("______________");
System.out.println("");
System.out.println(name + "当前的状态为:\n 生命:" + HP + "\\" + maxHP
+ "\n 魔法:" + MP + "\\" + maxMP + "\n 攻击力:" + attack + "\n 防御力:"
+ defence + "\n 金钱:" + money + "\n 经验值:" + Exp + "\n 等级:" + LV);
System.out.println(" 升级所需经验"
+ (1000 * LV * ((100 + LV * 10) / 100) + 500 * LV));
System.out.println("所习得技能:"+skill);
}
/**
* 玩家随机出现地点
*/
public void initPosition() {
Random rand = new Random();
x = rand.nextInt(65535) % 400;
y = rand.nextInt(65535) % 400;
System.out.println("英雄随机出现在(" + x + "," + y + ")。");
}
/**
* 玩家移动
*/
public void move(int direction) {
Random random =new Random();
switch (direction) {
case 1:
if (this.x + this.speed >= 400)
System.out.println("已走到世界尽头,回头吧!");
else {
this.x += this.speed;
System.out.println("英雄目前位置为(" + x + "," + y + ")。");
int InCombat=random.nextInt(10);
if(InCombat<=3){
Main.combat.Combat();
LeveUp(Combat.getExp);
Main.main(null);
}
}
break;
case 2:
if (this.x - this.speed < 0)
System.out.println("已走到世界尽头,回头吧!");
else {
this.x -= this.speed;
System.out.println("英雄目前位置为(" + x + "," + y + ")。");
int InCombat=random.nextInt(10);
if(InCombat<=3){
Main.combat.Combat();
LeveUp(Combat.getExp);
Main.main(null);
}
}
break;
case 3:
if (this.y - this.speed < 0)
System.out.println("已走到世界尽头,回头吧!");
else {
this.y -= this.speed;
System.out.println("英雄目前位置为(" + x + "," + y + ")。");
int InCombat=random.nextInt(10);
if(InCombat<=3){
Main.combat.Combat();
LeveUp(Combat.getExp);
Main.main(null);
}
}
break;
case 4:
if (this.y + this.speed >= 400)
System.out.println("已走到世界尽头,回头吧!");
else {
this.y += this.speed;
System.out.println("英雄目前位置为(" + x + "," + y + ")。");
int InCombat=random.nextInt(10);
if(InCombat<=3){
Main.combat.Combat();
LeveUp(Combat.getExp);
Main.main(null);
}
}
break;
}
}
/**
* 属性加点
*/
public void cPoint() {
int i = -1;
while (i == -1) {
System.out.println(" 你当前剩余的属性点数为:" + point);
System.out.println("(1)生命(每加一点增加 20点HP)");
System.out.println("(2)魔法(每加一点增加 10点MP)");
System.out.println("(3)攻击力(每加一点增加 5点攻击力)");
System.out.println("(4)防御力(每加一点增加 2点防御力)");
System.out.println("(5)退出");
System.out.println(" 请输入要加的属性:");
Scanner pointInput = new Scanner(System.in);
int pI = pointInput.nextInt();
if (pI < 5 && pI >= 1) {
switch (pI) {
case 1:
System.out.println("请输入要加点数量");
Scanner pointInput1 = new Scanner(System.in);
int pI1 = pointInput1.nextInt();
if (pI1 > point) {
System.out.println("点数不够,请重新输入");
break;
} else {
maxHP += pI1 * 20;
point -= pI1;
continue;
}
case 2:
System.out.println("请输入要加点数量");
Scanner pointInput2 = new Scanner(System.in);
int pI2 = pointInput2.nextInt();
if (pI2 > point) {
System.out.println("点数不够,请重新输入");
break;
} else {
maxMP += pI2 * 10;
point -= pI2;
continue;
}
case 3:
System.out.println("请输入要加点数量");
Scanner pointInput3 = new Scanner(System.in);
int pI3 = pointInput3.nextInt();
if (pI3 > point) {
System.out.println("点数不够,请重新输入");
break;
} else {
attack += pI3 * 20;
point -= pI3;
continue;
}
case 4:
System.out.println("请输入加点数量");
Scanner pointInput4 = new Scanner(System.in);
int pI4 = pointInput4.nextInt();
if (pI4 > point) {
System.out.println("点数不够,请重新输入");
break;
} else {
HP += pI4 * 20;
point -= pI4;
continue;
}
}
} else if (pI == 5) {
i = 0;
} else if (pI < 1 || pI > 5) {
System.out.println("输入错误的数,请重新输入!");
continue;
}
}
Main.main(null);
}
/**
* 升级等级判断与技能学习
*/
void LeveUp(int getEX) {
Exp += getEX;
if (Exp >= (1000 * LV * ((100 + LV * 10) / 100) + 500 * LV)) {
this.point += 10;
this.maxHP +=40;
this.maxMP += 20;
this.attack += 2;
this.defence += 1;
this.LV++;
System.out.println("恭喜升级到" + LV + "级!");
if(LV==3){
System.out.println("习得技能: ◎爆头一击◎");
skill.addElement("B. ◎爆头一击◎(给予敌方目标 无视防御的 200点伤害,消耗MP 30点)");
}else if(LV==7){
System.out.println("习得技能:◎精确射击◎");
skill.addElement("J. ◎精确射击◎(给予敌方目标 无视防御的 450点伤害,消耗MP 60点) ");
}else if(LV==12){
System.out.println("习得技能:◎快速拔抢◎");
skill.addElement("K. ◎快速拔抢◎(对敌方进行2次物理攻击 消耗MP 80点) ");
}else if(LV==20){
System.out.println("习得技能:◎快速拔抢◎");
skill.addElement("L. ◎狂暴乱射◎(对敌方进行随机的0~4次物理伤害 消耗MP 140) ");
}
System.out.println("要进行点数分配吗?");
System.out.println("1.分配 2.不分配");
Scanner yn = new Scanner(System.in);
int YN = yn.nextInt();
if (YN == 1) {
this.cPoint();
} else if (YN == 2) {
Main.main(null);
}
}
}
/***
* 玩家装备
*/
public void Equip() {
System.out.println("当前头部装备为:" + head);
System.out.println("当前身体装备为:" + body);
System.out.println("当前脚部装备为:" + shoes);
System.out.println("当前武器为:" + arm);
System.out.println("");
System.out.println("当前背包里的装备有"+Phead+Pbody+Pshoes+Parm);
while (true) {
System.out.println("是否要更换装备?(Y/N)");
Scanner s = new Scanner(System.in);
String ps = s.next();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -