用简单Java代码尝试在控制台写游戏(附源码)

article/2025/10/12 16:13:29

尝试写了一个在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;//直接退出maindefault: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       ===================");//1System.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:                   ");//5System.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             ");//10System.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            ");//15System.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("*********************************************************************************");//20System.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("**********************************************************************************");//25System.out.print("                                      ");//24}public static void skill(String a, String b, String c, int mode) {System.out.println("*********************************************************************************");//20System.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("**********************************************************************************");//25System.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("*********************************************************************************");//20System.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("**********************************************************************************");//25System.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("*********************************************************************************");//20System.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("**********************************************************************************");//25System.out.print("                                      ");//24}public static void enterNext() {System.out.println("*********************************************************************************");//20treasure(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("**********************************************************************************");//25System.out.print("                                      ");//24}public static void titleImg() {System.out.println("                                                                                 ");//1System.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 ");//5System.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("                                ....                                             ");//24System.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("                                      ");//24String 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("*********************************************************************************");//20break 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;} elseplayerHp[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;} elseplayerHp[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;}//无Mpcase 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;}//无Mpcase 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;}//无Mpcase 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("*您在与巨龙的战斗中遗憾落败,游戏结束!*");}
}

http://chatgpt.dhexx.cn/article/FxQMgbcb.shtml

相关文章

Java小游戏练习---超级玛丽代码实现

B站教学视频&#xff1a; 01_超级玛丽_创建窗口_哔哩哔哩_bilibili 素材提取&#xff1a; 【超级会员V2】我通过百度网盘分享的文件&#xff1a;Java游戏项目… 链接:百度网盘 请输入提取码 提取码:k6j1 复制这段内容打开「百度网盘APP 即可获取」 百度网盘 请输入提取码 百度…

java 300行代码 冒险闯关小游戏(代码+讲解)

作为一个男孩子&#xff0c;从小就喜欢晚一些游戏。今天就用java写一个类似马里奥的冒险闯关小游戏&#xff0c;但这也不是一两天能完成的事情&#xff0c;我将会持续更新这个游戏&#xff08;有什么好的介意也非常欢迎大家提出来&#xff0c;也能在我的基础上自己接着写&#…

宝塔php防盗链,[宝塔面板]如何开启防盗链?

为了节省建站成本&#xff0c;大多数站长都会选择一些小服务器&#xff0c;在另加CDN、云存储之类的来减轻服务器的压力&#xff0c;但是这类功能大多收费。 如果自己网站的图片都让别人复制图片链接地址&#xff0c;那么自己CDN流量就跑得贼快&#xff0c;花了钱得不到好处。 …

HTTP防盗链(Referer)

HTTP请求防盗链&#xff1a;只允许某些域名请求来源才可以访问。比如A网站有一张图片或音频等资源被B网站直接通过img等标签属性引入使用&#xff0c;这样就是B网站盗用了A网站的资源。那么对于A网站来说&#xff0c;流量怎么被消耗的都不知道。 解决思路&#xff1a; 判断http…

Nginx防盗链的配置

Nginx防盗链的配置 通常站点&#xff0c;都会想让自己网站的视频和图片&#xff0c;免被盗用&#xff0c;毕竟视频流量&#xff0c;花的都是白花花银子   首先我们没有配置防盗链的情况下&#xff0c;放开静态资源你的访问。我们来看看效果 location ~* .*\.(gif|jpg|ico|pn…

python爬虫的防盗链

文章目录 前言一、防盗链是什么&#xff1f;二、 防盗链如何实现三、分析四、 对有防盗链的网站进行爬取对有视频连接的网站发出请求并且获取源码信息提取出我们的视频网站对我们提取的网址进行修改&#xff0c;和拼凑下载视频结束爬取 完整代码 前言 随着python的发展网页的反…

Nginx静态资源防盗链

1.什么是资源盗链 简单地说&#xff0c;就是将别人的资源用到自己的页面展示给用户。 2.效果演示 1&#xff09;准备图片 这两张图片直接在浏览器中访问都是可以打开的。 github图片地址&#xff1a;https://github.githubassets.com/images/modules/site/home-campaign/her…

取消文件服务器防盗链,如何取消防盗链保护

http标准协议中有专门的字段记录referer 一来可以追溯上一个入站地址是什么 二来对于资源文件&#xff0c;可以跟踪到包含显示他的网页地址是什么。 因此所有防盗链方法都是基于这个Referer字段 网上比较多的2种 一种是使用apache文件FileMatch限制&#xff0c;在httpd.conf中增…

视频防盗链

解析器链接&#xff1a; https://www.administratorw.com/index/qqvod.php?url 清晰度高url后面支持mp4、m3u8地址 https://z1.m1907.cn?jx 清晰度底&#xff0c;链接后面只支持电影名 此接口解析出来的m3u8地址为&#xff1a;&#xff08;雄狮少年&#xff09; https…

html 图片防盗链,【反防盗链】介绍一个对付图片防盗链的方法

悲催的声明: 由于腾讯也采用了防盗链技术,本文方法已经失效了! 当我们想在文章里引用某张图片时,如果对方设置了防盗链,我们看到的将是404或forbidden或其他图片,而不是想要的那张图片,为此,我们有无方法进行“反防盗链”呢?答案是有的,本文将介绍一个对付图片防盗链…

简单的视频防盗链

1.使用hls.js播放视频&#xff0c;页面中无法获得视频的src hls.js是视频播放的工具文件&#xff0c;在官网上有播放方式&#xff0c;可以产生如上图所示的效果&#xff0c;没有source标签&#xff0c;也就是说&#xff0c;在页面上隐藏掉了视频的url hls.js文件地址&#xff…

html设置referer防盗链,referer与防盗链

referer是什么 referer 中文意思是:参照页面,引用页。 下图直观感受,(づ ̄ 3 ̄)づ image 直接在浏览器中输入url地址来直接访问图片/js/css等资源时是没有referer的, 如果有referer说明是引用过来的,要么是从HTML页面,要么是通过css @import,再或则通过background(url)引用…

防盗链使用

现在很多网站启用了防盗链反爬&#xff0c;防止服务器上的资源被人恶意盗取。什么是防盗链呢&#xff1f; 以图片为例&#xff0c;访问图片要从他的网站访问才可以&#xff0c;否则直接访问图片地址得不到图片 练习&#xff1a;抓取微博图片&#xff1a;http://blog.sina.com…

nginx配置防盗链

现在流行前后端分离开发的情况下&#xff0c;一般我们都会将静态资源放在nginx的html目录下。这种情况下&#xff0c;我们就无法通过Java代码写拦截器来防盗链了。所以这里我们来说明一下如何使用nginx来配置防盗链。 1.我们先修改本地hosts文件&#xff0c;将 www.czx.com 映…

java防盗链_javaWeb防止恶意登陆或防盗链的使用

使用场景:明明引用了一个正确的图片地址,但显示出来的却是一个红叉或写有“此图片仅限于***网站用户交流沟通使用”之类的“假图片”。用嗅探软件找到了多媒体资源的真实地址用下载软件仍然不能下载。下载一些资源时总是出错,如果确认地址没错的话,大多数情况都是遇上防盗链…

防盗链机制

防盗链机制的几种实现 通常防盗链是为了防止图片&#xff0c;视频被盗用。下面简单介绍几种防盗链的机制&#xff1a; 1. 利用HTTP Referer字段 HTTP请求中会包含来自哪个url的点击来源&#xff0c;通过这个referer字段可以检测是否别的网站发送的请求。 2.利用登录验证信息 有…

网络中的防盗链是指什么?

什么是盗链&#xff1f; 比如,别人上传的东西,你直接拿了LINK去,贴到别的论坛或者网站,宣称"有好东西,快来下载",又或者告诉你的朋友"你要这个文件?俺有连接,快下",然后在那里接受别人的滔滔不绝的景仰之情。 “盗链” 的定义是&#xff1a; 此内容不在…

Nginx防盗链

Nginx防盗链的实现原理&#xff1a; 了解防盗链的原理之前&#xff0c;我们得先学习一个HTTP的头信息Referer,当浏览器向web服务器发送请求的时候&#xff0c;一般都会带上Referer,来告诉浏览器该网页是从哪个页面链接过来的。 后台服务器可以根据获取到的这个Referer信息来判…

Nginx-防盗链

目录 一、什么是盗链 如何区分哪些是不正常的用户&#xff1f; Referer理解 二、Nginx配置防盗链 三、使用 curl 测试防盗链 四、企业实战 1.设置返回错误页面 2.整合 rewrite 返回报错图片 一、什么是盗链 在实际生产过程中&#xff0c;我们线上的图片等静态资源&#…

Nginx:防盗链原理和配置

目录 一、防盗链概念 二、Nginx防盗链的具体实现 配置&#xff1a; 三、验证和验证时的问题 真正的验证&#xff1a; 没有none的验证 加上none参数的验证 让报错返回的是一张图片 注意事项&#xff1a; 一、防盗链概念 防盗链简单来说就是存在我们服务中的一些资源&#xff…