尝试写了一个在Java控制台运行的代码游戏,由于写这个的时候,博主还没学到可视化界面,也没有学到面向对象,甚至没有集合,运用的全是之前C语言的语法,因此应该很容易看懂吧。末尾附上源码。
以下是效果展示
封面
战斗界面
操作方法是控制台输入对应数字,下面来说以下具体逻辑
main: while (true) {//主程序,用标号循环
int a = sc.nextInt();//控制台输入一个数字
switch (a) {
case 1: while (playerHp[0] >= 0){/*游戏主体*/}//开始游戏
case 2:
case 3:
case 4:System.out.println("开发中敬请期待");break;
case 0:System.out.println("退出游戏!");break main;//直接退出main
default:
System.out.println("功能开发中!");break;
}
}
主程序很简单,在死循环内,根据输入的数字打印相应语句即可,这里提到一个标号循环的用法,用来在生命值为0或者退出游戏时,可以直接结束死循环,写法是在while或者for前加任意字符名加冒号(例 main:while(true){/*语句*/}),然后程序内部如果执行到break 字符名时会跳出死循环。
游戏主体在角色血量大于0时循环,否则跳出,内部同样用switch选择并执行对应指令,代码原理同上。
然后是角色和怪物的属性,用static修饰可以方便全局调用,这个写在类里main外,当作静态常量
static int[] playerHpMax = {100, 123, 146, 170, 205, 233, 257, 282, 323, 369};
static int[] playerMpMax = {100, 110, 121, 132, 145, 161, 175, 184, 196, 200};
static int[] playerHp = {100};
static int[] playerMp = {100};
static int playerLevel = 1;
搞懂这些之后,就可以在游戏主体内进行数据的计算,具体可以看源码
目前代码中实现了角色升级,角色技能使用,角色技能切换(但是伤害没有变~),背包,物品获得与使用,随机伤害,怪物击杀,地图互动等功能。
学完面向对象后发现现有写法不足之处颇多,但是很多功能的逻辑还有的。
源码(乱码的的话在右下角加载成GBK格式):
package com.Ea;
import java.util.Random;
import java.util.Scanner;
public class TestDemo3_1 {
static Random r = new Random();
static String[] bag = {"(空)", "小血瓶", "小魔法瓶", "月光·符石", "血瓶", "魔法瓶", "凤凰·符石", "???"};
static String[] event = {"(空)", "[宝箱]", "废墟", "[遗落的木盒]", "遗落的钱袋", "神秘的山洞", "6", "7", "8", "9", "10", "幽暗的水晶", "祝福之泉", "映月之泉", "岩壁上的碑文", "15", "16", "17", "18", "19", "20", "先知", "商人", "23", "24", "25", "26", "27", "28", "29", "30", "龙兵", "龙卫", "龙王", "龙影", "若陀", "白灵龙", "龙卫首领", "小火龙", "火龙守卫", "喷火龙", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "道路(下一层)", "普通的山洞"};
static int[][] floorEvent = {{ 1, 2, 3, 4, 31,51}, { 2, 3, 32, 4, 11,51}, { 2, 3, 32, 4, 12,51}, { 2, 3, 32, 4, 21,51}, { 2, 3, 32, 4, 21,51},{ 2, 3, 32, 4, 21,51}, { 2, 3, 32, 4, 21,51}, { 2, 3, 32, 4, 21,51},{ 2, 3, 32, 4, 21,51}, { 2, 3, 32, 4, 21,51}};
static int[] eventNum = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52};
static int[] bagFull = {1, 2, 3, 0, 0, };
static int[] bagNum = {1, 1, 1, 0, 0, };
static int[] skillCost1 = {20, 15, 50, 5};
static int[] skillCost2 = {25, 20, 45, 5};
static int[] skillCost3 = {10, 15, 20, 5};
static int[] playerHpMax = {100, 123, 146, 170, 205, 233, 257, 282, 323, 369};
static int[] playerMpMax = {100, 110, 121, 132, 145, 161, 175, 184, 196, 200};
static int[] playerHp = {100};
static int[] playerMp = {100};
static int playerLevel = 1;
public static void createFloor(int[][] args, int floor) {
//bag[]
String[] ad = {"失落的飘渺之城", "地下城1层", "地下城2层", "地下城3层", "(4层)龙之城边缘", "(5层)龙距之城", "(6层)熔岩洞窟", "(7层)熔岩之下", "(8层)黑王宫入口", "(9层)黑王宫", "(?)真正的飘渺之城"};
System.out.println(ad[floor]);
for (int i = 0; i < args[floor].length; i++) {
System.out.println((i + 1) + "." + event[args[floor][i]]);
System.out.println();
}
if (floor > 0) System.out.println(0 + ".返回上一层");
}
public static void treasure(int a, int bag[], int num[], int floor, int p) {
switch (a) {
case 1: {
int c = r.nextInt(2) + 4;
putInBag(a, c, bag, num, floor, p);
break;
}
case 2:
case 3:
case 4:
case 15: {//怪物获取
int c = r.nextInt(3);
if (c == 0) {
c = r.nextInt(3);
} else {
c = r.nextInt(2) + 4;
}
putInBag(a, c, bag, num, floor, p);
break;
}
case 13:
case 14:
putInBag(a, a, bag, num, floor, p);
}
}
public static void nothing() {
System.out.println("nothing");
}
public static void putInBag(int a, int d, int bag1[], int number[], int floor, int p) {//摆放背包
boolean flag = false;
for (int i = 0; i < bagFull.length; i++) {
if (bag1[i] == a) {
number[i]++;
if (a == 1) System.out.print("打开了" + event[a] + "!");
else if (a >= 2 && a <= 5) System.out.print("在" + event[a] + "中翻找,");
else if (a == 13) {
System.out.print("沐浴着泉水的微光,仿佛有所感悟,");
d = 3;
} else if (a == 14) {
System.out.print("检查了" + event[a] + "仿佛有所感悟,");
d = 6;
}
System.out.println("获得了" + bag[d] + "!");
if (a >= 1 && a <= 4) floorEvent[floor][p] = 0;//重置事件为空
else if (a == 5) floorEvent[floor][p] = 15;
else if (a == 13) floorEvent[floor][p] = 12;
break;
}
if (i == bagFull.length - 1) flag = true;
}
if (flag) {
for (int i = 0; i < bagFull.length; i++) {
if (bag1[i] == 0) {
if (a == 1) System.out.print("打开了" + event[a] + "!");
else if (a >= 2 && a <= 5) System.out.print("在" + event[a] + "中翻找,");
else if (a == 13) {
System.out.print("沐浴着泉水的微光,仿佛有所感悟,");
d = 3;
} else if (a == 14) {
System.out.print("检查了" + event[a] + "仿佛有所感悟,");
d = 6;
}
System.out.println("获得了" + bag[d] + "!");
bag1[i] = d;
number[i]++;
if (a >= 1 && a <= 4) floorEvent[floor][p] = 0;//重置事件为空
else if (a == 5) floorEvent[floor][p] = 15;
else if (a == 13) floorEvent[floor][p] = 12;
break;
}
if (i == bagFull.length - 1 || bag1[i] == a && bagNum[i] == 9) {
System.out.print("打开了" + event[a] + "!");
System.out.println("但是背包满了,放不下了~");
}
}
}
}
public static void chooseStart() {
{
System.out.println(" ");
System.out.println(" ir :: ii : i . ");
System.out.println(" jS rJL .B. B2 Br s77rri:irrrrrr7 Bi B:1B");
System.out.println(" :..DB. iI... .BL25KXKSX5KS .Q :B M: IIUULKB5j55SSqs Ii ... .B7 J.");
System.out.println(" 75JvvBBrBBi1USi YB ........: .B. B XE7ZB :B :YB BU2vBQYvSL ");
System.out.println(" S: J: : Bi :sBBr:BqLB1 B Bqi .RB.:B X ");
System.out.println(" Kv sj Br 22UII5I21B .u :B: vr .Q .B QB: g Quu: 2 :J ");
System.out.println(" KY iv.B. vS B vr 7U.gr qY :BP K E 1 gr7: ");
System.out.println(" Bi .BB iiYUu212uUr B Ji r1 iM:::. B . .5B:Y r Bs. ");
System.out.println(" :B 1B1. :B Mi :Dgi.B . B. rD rr.:Mviu:D.:: ");
System.out.println(" .Q. rYuYB. .uv7B: . 7L::iJv . Q. 7r i2:iBi: ");
System.out.println(" ***************************** . ");
System.out.println(" * =请输入对应指令= * ");
System.out.println(" * 1. *" + "\33[36;50;4m" + "开始游戏" + "\33[0m" + "* * ");
System.out.println(" :* * ");
System.out.println(" .iY5* 2. *" + "\33[36;50;4m" + "继续游戏" + "\33[0m" + "* * ");
System.out.println(" :LdbP* * ");
System.out.println(" isPqKP* 3. *" + "\33[36;50;4m" + "设置" + "\33[0m" + "* * ");
System.out.println(" .rIPIIJP* * ");
System.out.println(" .7SgXS2S2* 4. *" + "\33[36;50;4m" + "帮助" + "\33[0m" + "* * ");
System.out.println(" .ivPXK57* * ");
System.out.println(" :r72K* 0. *" + "\33[36;50;4m" + "退出" + "\33[0m" + "* * ");
System.out.println(" ..:***************************** ");
System.out.println(" .... ");
}//标题界面
}
public static void chooseWarning() {
{
System.out.println(" ");
System.out.println(" ir :: ii : i . ");
System.out.println(" jS rJL .B. B2 Br s77rri:irrrrrr7 Bi B:1B");
System.out.println(" :..DB. iI... .BL25KXKSX5KS .Q :B M: IIUULKB5j55SSqs Ii ... .B7 J.");
System.out.println(" 75JvvBBrBBi1USi YB ........: .B. B XE7ZB :B :YB BU2vBQYvSL ");
System.out.println(" S: J: : Bi :sBBr:BqLB1 B Bqi .RB.:B X ");
System.out.println(" Kv sj Br ******************************************* g Quu: 2 :J ");
System.out.println(" KY iv.B. * * K E 1 gr7: ");
System.out.println(" Bi .BB * " + "\33[36;50;1m" + "功能正在开发中!" + "\33[0m" + " *5B:Y r Bs. ");
System.out.println(" :B 1B1. * *.:Mviu:D.:: ");
System.out.println(" .Q. rY*******************************************7r i2:iBi: ");
System.out.println(" ***************************** . ");
System.out.println(" * =请输入对应指令= * ");
System.out.println(" * 1. *" + "\33[36;50;4m" + "开始游戏" + "\33[0m" + "* * ");
System.out.println(" :* * ");
System.out.println(" .iY5* 2. *" + "\33[36;50;4m" + "继续游戏" + "\33[0m" + "* * ");
System.out.println(" :LdbP* * ");
System.out.println(" isPqKP* 3. *" + "\33[36;50;4m" + "设置" + "\33[0m" + "* * ");
System.out.println(" .rIPIIJP* * ");
System.out.println(" .7SgXS2S2* 4. *" + "\33[36;50;4m" + "帮助" + "\33[0m" + "* * ");
System.out.println(" .ivPXK57* * ");
System.out.println(" :r72K* 0. *" + "\33[36;50;4m" + "退出" + "\33[0m" + "* * ");
System.out.println(" ..:***************************** ");
System.out.println(" .... ");
}//标题提示界面
}
public static void monsterInfo(int hp, String name, int level) {
System.out.println(" rJ 7 ===================");//1
System.out.println(" .UR. .i. Lq. = 龙 = HP: " + "\33[36;50;1m" + hp + "\33[0m" + " =");
System.out.println(" .rXZKu 1RPdSJdZdi JbKv = " + name + " = LV: " + "\33[36;50;1m" + level + "\33[0m" + " =");
System.out.println(" ..vdBBBBB1. .MPKbdbSgQ1: rBBBQI: ===================");
System.out.println(" .7IBBBQBRBBRv ivQDSS1E2SQi :gBBBBBRU: ");//5
System.out.println(" rPBBBBgZgQQQBI: 1gZgD. .LBQBgQBBBQI7. ");
System.out.println(" :XBBBRDddPgQQMBI7 iQPYJ :BQQBRgZgBQBBDr ");
System.out.println(" ubBBQZEPZPERBRMBgrL. I7rS. .vBQQBgZPdPDgBBZi ");
System.out.println(" iPBBMbZZDEEdBQRMQBBBBZ1: 1r7JL iJ1gBZBQMPEdZbddBBb. ");
System.out.println(" PBBgZRBBBBDgQBgMEgQBBBBBP7i.Yv7vs :.7QBBQBgEQQEDRBggEEdBBX ");//10
System.out.println(" vBBBBBBgjrsBgBQRdEdDRBBBBBgUKvrsIUIqjBBBBBQgbBQRBgPBBBgDEBBv ");
System.out.println(" QBBQI. :BBBgBBBQqLsjJsi7v7777r7v7rs25YYZQBBBv JYBBQQBq. ");
System.out.println(" rBBr iBBB1.:q::PPPdSLr77jsusvrPDKKJ::sBB Yq: iMBQdr ");
System.out.println(" 5Bi SB iivBB:rQs77Jur::i7YZZ LBgvi7v. XQi BBP: ");
System.out.println(" Bb i11Lvq2 Lr717 .jr . :q77PQ: Z7. :BK ");//15
System.out.println(" : DBqvqr X77ui ...... d gjLQr iBr 7Y Bi ");
}
public static void playerInfo1(int a) {
System.out.print("* 玩 家 || HP:" + "\33[36;50;1m" + a + "\33[0m" + " *");
}
public static void playerInfo2(int a, int b) {
System.out.print("* LV: " + "\33[36;50;1m" + a + "\33[0m" + "|| MP:" + "\33[36;50;1m" + b + "\33[0m" + " *");
}
public static void monsterAttack1(String a, int b) {
System.out.println(" 受到龙" + a + "的攻击Hp-" + "\33[31;49;1m" + b + "\33[0m" + " ");
}
public static void baseControl() {
System.out.println("*********************************************************************************");//20
System.out.println("* 请输入您的选择: *");
System.out.println("* *");
System.out.println("* 1." + "\33[36;50;4m" + "攻击" + "\33[0m" + " 2." + "\33[36;50;4m" + "道具" + "\33[0m" + " *");
System.out.println("* 3." + "\33[36;50;4m" + "技能" + "\33[0m" + " 4." + "\33[36;50;4m" + "逃跑" + "\33[0m" + " *");
System.out.println("**********************************************************************************");//25
System.out.print(" ");//24
}
public static void skill(String a, String b, String c, int mode) {
System.out.println("*********************************************************************************");//20
System.out.println("* 请输入您的选择: *");
System.out.println("* *");
System.out.println("* 1." + "\33[36;50;4m" + a + "\33[0m" + "(" + skillCost1[mode] + ") 2." + "\33[36;50;4m" + b + "\33[0m" + "(" + skillCost2[mode] + ") *");
System.out.println("* 3." + "\33[36;50;4m" + c + "\33[0m" + "(" + skillCost3[mode] + ") 0." + "\33[36;50;4m" + "(返回)" + "\33[0m" + " *");
System.out.println("**********************************************************************************");//25
System.out.print(" ");//24
}
public static void boxQueue(int args[], int a[]) {
int empty = 0;
for (int i = 0; i < args.length; i++) {
if (a[i] == 0) {
for (int j = i; j < args.length - 1; j++) {
args[j] = args[j + 1];
a[j] = a[j + 1];
//b[j] = b[j - 1];
empty = j + 1;
}
args[empty] = 0;
a[empty] = 0;
}
}
}
public static void boxEmpty(int a, int a1, int b, int b1, int c, int c1) {
// String[] bag = {"(空)", "小血瓶", "小魔法瓶", "月光·符石", "血瓶", "魔法瓶", "???", "???"};
System.out.println("*********************************************************************************");//20
System.out.println("* 请输入您的选择: *");
System.out.println("* 1." + "\33[36;50;4m" + bag[bagFull[0]] + "\33[0m" + "(" + bagNum[0] + ") 2." + "\33[36;50;4m" + bag[b] + "\33[0m" + "(" + b1 + ") *");
System.out.println("* 3." + "\33[36;50;4m" + bag[bagFull[2]] + "\33[0m" + "(" + bagNum[2] + ") 4." + "\33[36;50;4m" + bag[bagFull[3]] + "\33[0m"+"(" + +bagNum[3]+ ") *");
System.out.println("* 5." + "\33[36;50;4m" + bag[bagFull[4]] + "\33[0m" + "(" + bagNum[4] + ") 0." + "\33[36;50;4m" + "(返回)" + "\33[0m" + " *");
System.out.println("**********************************************************************************");//25
System.out.print(" ");//24
}
public static void trueEffect(int[] a, int[] b, int c, int[] mode) {
int[] arr = {0, 40, 40, 0, 80, 80, 0};
if (c == 1 || c == 4) {
a[0] += arr[c];
} else if (c == 2 || c == 5) {
b[0] += arr[c];
} else if (c == 3) {
mode[0] = 1;
} else if (c == 7) {
mode[0] = 0;
} else ;
System.out.println(mode[0]);
}
public static void useBox(int a,int choose) {
if (a > 0) {
System.out.println(" 使用了" + bag[a] + "! ");
bagNum[choose]--;
} else System.out.println(" 暂未获得道具! ");
}
public static void useEffect(int i) {
String[] effect = {"", "血量恢复!Hp+" + "\33[34;50;1m" + "40" + "\33[0m", "魔法恢复!Mp+" + "\33[34;50;1m" + "40" + "\33[0m", "获得了" + "\33[35;50;1m" + "月光之力" + "\33[0m" + "的庇佑!" + "\33[36;50;1m" + "技能" + "\33[0m" + "获得强化!", "血量恢复!Hp" + "\33[34;50;1m" + "80" + "\33[0m", "魔法恢复!Mp" + "\33[34;50;1m" + "80" + "\33[0m", "", "", ""};
System.out.println(" " + effect[i] + " ");
}
public static void skillAttack(String args, int a, int r) {
if (r >= 20) {
System.out.println(" 使用了" + "\33[31;49;1m" + args + "\33[0m" + "!造成了" + "\33[31;49;1m" + "暴击" + "\33[0m" + "!敌方hp-" + "\33[31;49;1m" + a + "\33[0m" + " ");
} else {
System.out.println(" 使用了" + "\33[31;49;1m" + args + "\33[0m" + "!敌方hp-" + "\33[31;49;1m" + a + "\33[0m" + " ");
}
}
public static void hpRecovery() {//
playerHp[0] = playerHpMax[playerLevel - 1];
playerMp[0] = playerMpMax[playerLevel - 1];
}
public static void waterRecovery() {//
playerHp[0] = Math.min((playerHp[0] + playerHpMax[playerLevel - 1] / 2), playerHpMax[playerLevel - 1]);
playerMp[0] = Math.min((playerMp[0] + playerMpMax[playerLevel - 1] / 2), playerMpMax[playerLevel - 1]);
}
public static void levelUp(String a) {
System.out.println("*********************************************************************************");//20
System.out.println("* 等级提升!获得了" + "\33[33;50;1m" + "新技能" + "\33[0m" + "《" + "\33[37;50;4m" + a + "\33[0m" + "》 *");
System.out.println("* 最大Hp提升了?!最大Mp提升了?! *");
System.out.println("* *");
System.out.println("* " + "\33[36;50;1m" + "输入任意字符继续:" + "\33[0m" + " *");
System.out.println("**********************************************************************************");//25
System.out.print(" ");//24
}
public static void enterNext() {
System.out.println("*********************************************************************************");//20
treasure(4, bagFull, bagNum, 1, 1);
//System.out.println("* 获得了" + "\33[33;50;1m" + "物品" + "\33[0m" + " " + "\33[37;50;4m" + a + "\33[0m" + " *");
//System.out.println("* " + "\33[36;50;1m" + "即将进入下一关" + "\33[0m" + " *");
System.out.println("* *");
System.out.println("* " + "\33[36;50;1m" + "输入任意字符继续:" + "\33[0m" + " *");
System.out.println("**********************************************************************************");//25
System.out.print(" ");//24
}
public static void titleImg() {
System.out.println(" ");//1
System.out.println(" ir :: ii : i . ");
System.out.println(" jS rJL .B. B2 Br s77rri:irrrrrr7 Bi B:1B");
System.out.println(" :..DB. iI... .BL25KXKSX5KS .Q :B M: IIUULKB5j55SSqs Ii ... .B7 J.");
System.out.println(" 75JvvBBrBBi1USi YB ........: .B. B XE7ZB :B :YB BU2vBQYvSL ");//5
System.out.println(" S: J: : Bi :sBBr:BqLB1 B Bqi .RB.:B X ");
System.out.println(" Kv sj Br 22UII5I21B .u :B: vr .Q .B QB: g Quu: 2 :J ");
System.out.println(" KY iv.B. vS B vr 7U.gr qY :BP K E 1 gr7: ");
System.out.println(" Bi .BB iiYUu212uUr B Ji r1 iM:::. B . .5B:Y r Bs. ");
System.out.println(" :B 1B1. :B Mi :Dgi.B . B. rD rr.:Mviu:D.:: ");
System.out.println(" .Q. rYuYB. .uv7B: . 7L::iJv . Q. 7r i2:iBi: ");
System.out.println(" ...:iii71jSj7jjYLr7. . ");
System.out.println(" .i7vKQQQggDEPZggPbqbPPjj: ");
System.out.println(" :7YEQBBguv5dqPZZj::SIXUuIPs. ");
System.out.println(" :vEdDQI:i: ir77r72vLK2S1iIK7 ");
System.out.println(" .iY5PdMS. rrrR..:iIUJ2P7XIsI2: ");
System.out.println(" :LdbPduiqirri: .Bi .::irYIvI5KKi ");
System.out.println(" isPqKPv.:EPLr:. BB. .irvKLKPSi ");
System.out.println(" .rIPIIJPJ5ZJri:: :Q :ijbbYsZY. ");
System.out.println(" .7SgXS2S2K27i:..:.:. :..:r71PdIr ");
System.out.println(" .ivPXK57Y1YurrvL:7vr::iYvJES7. ");
System.out.println(" :r72KZqXdZEgUsXg1EXKq17i. ");
System.out.println(" ..:ir7JSPKPU2js7r:. ");
System.out.println(" .... ");//24
System.out.println(" " + "\33[31;49;1m" + "*输入任意字符开始游戏*" + "\33[0m" + " ");
}
public static void main(String[] args) {
int[] playerHp = {100};
int[] playerMp = {100};
int[] exp = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int[] expUp = {20, 50, 90, 140, 200, 270, 350, 440, 540, 660};
int[] i = {10, 15, 20, 28, 32, 40, 45, 50, 55, 60};
int[] monsterLevel = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int[] monsterHpMax = {30, 60, 98, 120, 160, 200, 200, 200, 200, 200};
int[] monsterHp = {30, 60, 98, 120, 160, 200, 200, 200, 200, 200};
int round = 0;
int[] hurt = new int[3];
String[] monsterName = {"兵", "卫", "王", "影", "若", "陀"};
String[][][] skillName1 = {{{}, {"登龙剑", "(空)", "(空)", ""}, {"登龙剑", "治疗术", "(空)", "月光·符石"}, {"登龙剑", "治疗术", "强力防御", "月光·符石"}}, {{}, {"月光·登龙剑", "愈疗术", "月光·护盾", "光弧·符石"}, {"月光·登龙剑", "愈疗术", "月光·护盾", "光弧·符石"}}};
int[] skillRecovery = {50, 60, 70, 100};
int[] mode = {0, 0};
int floor = 0;
//int defend = 0;
Scanner zhiLing = new Scanner(System.in);
Random damage = new Random();
Scanner startG = new Scanner(System.in);
Scanner skillNum = new Scanner(System.in);
Scanner boxNum = new Scanner(System.in);
//标题
titleImg();//进入界面
System.out.print(" ");//24
String startA = startG.next();
chooseStart();
main:
while (true) {
int a = zhiLing.nextInt();
switch (a) {
case 1:
case 2:
start:
while (playerHp[0] >= 0) {
System.out.println("城镇界面");
createFloor(floorEvent, floor); //生成地图
int chooseM = zhiLing.nextInt() -1;
if (chooseM >= 6) System.out.println("勇者可能打算原地休息一会");
else if (chooseM==-1) {if (floor>=1)floor--;System.out.println("返回上一层");}
else {
if (eventNum[floorEvent[floor][chooseM]] >= 31 && eventNum[floorEvent[floor][chooseM]] <= 50) {
//while ()
{
// playerLevel = round + 1;
{
monsterHp[floor] = monsterHpMax[floor];
monsterInfo(monsterHp[floor], monsterName[round], floor);
System.out.println("* * * * * * * * * * rI 2. i17sL ........ .P . Kv::7P P ");
playerInfo1(playerHp[0]);
System.out.println(" ..:Y7JJ ........ .dv. i.i. ");
playerInfo2(playerLevel, playerMp[0]);
System.out.println(" .:isrrvZ .......::7Z7i.: Q7 ");
}//界面刷新
csm:
while (monsterHp[floor] >= -1 && playerHp[0] >= -1) {
int damage1 = damage.nextInt(20) + 11;
int critic = damage.nextInt(40) + 1;
int damage2 = critic + 10;
// int damage2 = damage.nextInt(40) + 60;
hurt[0] = damage.nextInt(9) + 7;
hurt[1] = damage.nextInt(9) + 17;
hurt[2] = damage.nextInt(9) + 21;
baseControl();//基础选择栏
int playDo = zhiLing.nextInt();
switch (playDo) {
case 1:
monsterHp[floor] -= damage1;
if (monsterHp[floor] <= 0) {
{
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println(" 攻击!敌方hp-" + "\33[31;49;1m" + damage1 + "\33[0m" + " ");
playerInfo2(playerLevel, playerMp[0]);
exp[playerLevel] += i[floor] + r.nextInt(4);
System.out.println(" 成功击败了龙" + monsterName[round] + "!获得了" + i[floor] + "点经验值! ");
enterNext();
}//未暴击技能击杀事件
startA = startG.next();
if (exp[playerLevel] >= expUp[playerLevel]) {
if (playerLevel < 9) playerLevel++;
levelUp(skillName1[mode[0]][playerLevel][playerLevel - 1]);startA = startG.next();
}
break csm;
}//攻击击杀事件
playerHp[0] -= hurt[round];
{
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println(" 攻击!敌方hp-" + "\33[31;49;1m" + damage1 + "\33[0m" + " ");
playerInfo2(playerLevel, playerMp[0]);
monsterAttack1(monsterName[round], hurt[round]);
}//攻击事件
break;
case 2: {
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println(" 勇者准备使用道具! ");
playerInfo2(playerLevel, playerMp[0]);
System.out.println(" ");
boxEmpty(bagFull[0], bagNum[0], bagFull[1], bagNum[1], bagFull[2], bagNum[2]);
}//事件//选择道具
csb:
while (true) {
int chooseBox = boxNum.nextInt();
switch (chooseBox) {
case 0:
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println("*= 勇者放弃了使用道具 ");
playerInfo2(playerLevel, playerMp[0]);
System.out.println(" ");
System.out.println("*********************************************************************************");//20
break csb;
case 1:
case 2: case 3:
case 4:
case 5:
if (bagFull[chooseBox-1] > 0 && bagNum[chooseBox-1] > 0) {
trueEffect(playerHp, playerMp, bagFull[chooseBox-1], mode);
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
useBox(bagFull[chooseBox-1], chooseBox-1);
playerInfo2(playerLevel, playerMp[0]);
useEffect(bagFull[chooseBox-1]);
boxQueue(bagFull, bagNum);
break csb;
}//事件//选择道具
default: {
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println(" 暂未获得道具! ");
playerInfo2(playerLevel, playerMp[0]);
System.out.println(" ");
boxEmpty(bagFull[0], bagNum[0], bagFull[1], bagNum[1], bagFull[2], bagNum[2]);
}//事件//选择道具
}
//事件//选择道具
}//道具
break;
case 3: {
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println(" 勇者准备使用技能! ");
playerInfo2(playerLevel, playerMp[0]);
System.out.println(" ");
skill(skillName1[mode[0]][playerLevel][0], skillName1[mode[0]][playerLevel][1], skillName1[mode[0]][playerLevel][2], mode[0]);
}//事件//选择技能
csk:
while (true) {
int chooseSkill = skillNum.nextInt();
switch (chooseSkill) {
case 1:
if (playerMp[0] >= skillCost1[mode[0]]) {
monsterHp[floor] -= damage2;//登龙剑
playerMp[0] -= skillCost1[mode[0]];
if (damage2 >= 30) {
if (monsterHp[floor] <= 0) {
{
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
skillAttack(skillName1[mode[0]][playerLevel][0], damage2, critic);
playerInfo2(playerLevel, playerMp[0]);
exp[playerLevel] += i[floor] + r.nextInt(4);
System.out.println(" 成功击败了龙" + monsterName[round] + "!获得了" + i[floor] + "点经验值! ");
enterNext();
}//未暴击技能击杀事件
startA = startG.next();
if (exp[playerLevel] >= expUp[playerLevel]) {
if (playerLevel < 9) playerLevel++;
levelUp(skillName1[mode[0]][playerLevel][playerLevel - 1]);startA = startG.next();
}
break csm;
} else
playerHp[0] -= hurt[round];
{
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
skillAttack(skillName1[mode[0]][playerLevel][0], damage2, critic);
playerInfo2(playerLevel, playerMp[0]);
monsterAttack1(monsterName[round], hurt[round]);
}//暴击技能事件
} else {
if (monsterHp[floor] <= 0) {
{
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
skillAttack(skillName1[mode[0]][playerLevel][0], damage2, critic);
playerInfo2(playerLevel, playerMp[0]);
// System.out.println(" 成功击败了龙" + monsterName[round] + "! ");
exp[playerLevel] += i[floor] + r.nextInt(4);
System.out.println(" 成功击败了龙" + monsterName[round] + "!获得了" + i[floor] + "点经验值! ");
enterNext();
}//未暴击技能击杀事件
startA = startG.next();
if (exp[playerLevel] >= expUp[playerLevel]) {
if (playerLevel < 9) playerLevel++;
levelUp(skillName1[mode[0]][playerLevel][playerLevel - 1]);startA = startG.next();
}
break csm;
} else
playerHp[0] -= hurt[round];
{
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
skillAttack(skillName1[mode[0]][playerLevel][0], damage2, critic);
playerInfo2(playerLevel, playerMp[0]);
monsterAttack1(monsterName[round], hurt[round]);
}//未暴击技能事件
}break csk;
}//登龙剑
{
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println(" Mp不足以释放技能! ");
playerInfo2(playerLevel, playerMp[0]);
System.out.println(" ");
skill(skillName1[mode[0]][playerLevel][0], skillName1[mode[0]][playerLevel][1], skillName1[mode[0]][playerLevel][2], mode[0]);
break;
}//无Mp
case 2:
if (playerLevel >= 2 && playerMp[0] >= skillCost2[mode[0]]) {
playerHp[0] += skillRecovery[mode[0]];
playerHp[0] -= hurt[round];
playerMp[0] -= skillCost2[mode[0]];
{
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println(" 使用了" + "\33[34;50;1m" + skillName1[mode[0]][playerLevel][1] + "\33[0m" + "!HP+" + "\33[34;50;1m" + skillRecovery[mode[0]] + "\33[0m" + "! ");
playerInfo2(playerLevel, playerMp[0]);
monsterAttack1(monsterName[round], hurt[round]);
}//治疗术
break csk;
}//恢复技能
{
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println(" Mp不足以释放技能! ");
playerInfo2(playerLevel, playerMp[0]);
System.out.println(" ");
skill(skillName1[mode[0]][playerLevel][0], skillName1[mode[0]][playerLevel][1], skillName1[mode[0]][playerLevel][2], mode[0]);
break;
}//无Mp
case 3:
if (playerLevel >= 3 && playerMp[0] >= skillCost2[mode[0]]) {
playerMp[0] -= skillCost3[mode[0]];
playerHp[0] -= hurt[round];
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println(" 使用了" + "\33[36;50;1m" + skillName1[mode[0]][playerLevel][2] + "\33[0m" + "!防御力提升" + "\33[34;50;1m" + "5" + "\33[0m" + "! ");
playerInfo2(playerLevel, playerMp[0]);
monsterAttack1(monsterName[round], hurt[round]);
break csk;
}//防御技能
{
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println(" Mp不足以释放技能! ");
playerInfo2(playerLevel, playerMp[0]);
System.out.println(" ");
skill(skillName1[mode[0]][playerLevel][0], skillName1[mode[0]][playerLevel][1], skillName1[mode[0]][playerLevel][2], mode[0]);
break;
}//无Mp
case 4: //技能页面
default: {
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println(" Mp不足以释放技能! ");
playerInfo2(playerLevel, playerMp[0]);
System.out.println(" ");
skill(skillName1[mode[0]][playerLevel][0], skillName1[mode[0]][playerLevel][1], skillName1[mode[0]][playerLevel][2], mode[0]);
break;
}//事件//选择技能
case 0:
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println(" 勇者放弃了使用技能 ");
playerInfo2(playerLevel, playerMp[0]);
System.out.println(" ");
break csk;
}
}
break;
case 4:
System.out.println("逃跑了!");
break csm;//逃跑事件
default:
playerHp[0] -= hurt[round];
{
monsterInfo(monsterHp[floor], monsterName[round], floor+1);
System.out.println("* * * * * * * * * * ==============================================================");
playerInfo1(playerHp[0]);
System.out.println(" 勇者使用了发呆!但无事发生 ");
playerInfo2(playerLevel, playerMp[0]);
monsterAttack1(monsterName[round], hurt[round]);
}//发呆事件3
}//主程序
}
// round++;
// exp[playerLevel]+=i[floor]+r.nextInt(4);经验值
}
} else if (eventNum[floorEvent[floor][chooseM]] >= 1 && eventNum[floorEvent[floor][chooseM]] <= 10) {
System.out.println(eventNum[floorEvent[floor][chooseM]]);
treasure(eventNum[floorEvent[floor][chooseM]], bagFull, bagNum, floor, chooseM);
} else if (eventNum[floorEvent[floor][chooseM]] >= 11 && eventNum[floorEvent[floor][chooseM]] <= 20) {
hpRecovery();
}
//System.out.println("获取属性");
else if (eventNum[floorEvent[floor][chooseM]] >= 21 && eventNum[floorEvent[floor][chooseM]] <= 30)
System.out.println("交谈");
else if (eventNum[floorEvent[floor][chooseM]] == 50) {if (floor>=1)System.out.println("返回上一层");floor--;}
else if (eventNum[floorEvent[floor][chooseM]] == 0 || eventNum[floorEvent[floor][chooseM]] == 52)
nothing();
else if (eventNum[floorEvent[floor][chooseM]] == 51) if (floor <= 8) floor++;
else System.err.println("Event Error");
}
//startEvent(floorEvent,floor,walk);//事件,调用其他方法
//if (eventNum[floorEvent[floor][chooseM]] == 0) break start;
}
break main;
case 3:
case 4:chooseWarning();break;
case 0:
break main;
default:
System.out.println("功能开发中!");
}
}
if (playerHp[0] >= 1) {
System.out.println(" *恭喜你,打败了龙王!成功拯救了阿卡亚地下城,游戏结束~*");
System.out.println(" 后续关卡和玩法正在开发中,敬请期待!");
System.out.println();
System.out.println("**********************************************************************************");//25*/
} else System.out.println("*您在与巨龙的战斗中遗憾落败,游戏结束!*");
}
}