首先说一下在学习java中非常重要的一点,就是常写备注!这一点非常的重要,虽然前期看不出来,但是以后的日子里代码一定会越来越长,可能过几天回去看的时候就会出现“哎呀我去,这写的是啥啊”等情况,所以除了部分格式能套用之外,其他的句子都最好写上备注。然后就是debug这个功能,非常的强大,每次运行发现代码并没有按照自己的意愿进行时,用debug就能轻松发现问题的所在,然后及时的为程序更新代码,解决那些由于特殊情况产生的无法运行的状态或者是运行错误等情况。
下面是我自己学了6天写的代码(几乎是学一天更新一个版本的那种),内容大概包括了前几天学的所有知识点。新人报道,大佬们请嘴下留情,不喜勿喷。[Java] 纯文本查看 复制代码 package version04;
import java.util.Random;
import java.util.Scanner;
/**
* @author zl
* @date 2019-06-25 14:14
*/
public class Ver04_01 {
private static String[] Person = {"小黑", "阿力", "苍牙", "琳", "小椒"};
private static String[] weapon = {"炎宿·朱雀", "御火芭蕉扇", "祝融", "龙神飨宴", "雷宿·麒麟", "三日月·雷切", "漩雷一文字", "爱疯xxx", "风宿·苍龙", "风妖镰鼬", "鬼泪村正", "天音灵萧", "霜宿·苍玄", "神使·沧溟", "天晶苦无", "真·凌玉弓"};
private static String[] weapon1 = {"朱雀", "火焰蒲扇", "秘制烤串", "火焰刀", "追雷弓", "绝地光剑", "雷元剑", "爱疯10", "西斯光剑", "龙鳞扇", "村正", "琅君灵萧", "永恒冰晶", "苍雪剑", "寒晶苦无", "绝寒弓","双弦寒冰弓","爆炎辣锅"};
private static int cast = 0; //定义剩余勾玉
private static int count = 0; //定义累积消费
private static Scanner sc = new Scanner(System.in);
private static Random r = new Random();
public static void main(String[] args) {
System.out.println("欢迎进入抽卡游戏");
home();
}
public static void home(){
while (true) {
System.out.println("请选择你要进入的界面:");
System.out.println("1.我的卡包" + " " + "2.商城");
int home = sc.nextInt();
while (true) {
if (home == 2) {
shop();
break;
} else if (home == 1) {
System.out.println("暂未更新");
} else {
System.out.println("你输入的数据有误");
}
}
}
}
public static void shop() {
System.out.println("正在打开商城");
System.out.println("请选择你要执行的选项");
System.out.println("");
System.out.println("1.充值" + " " + "2.抽卡" + " " + "3.返回");
while (true) {
int b = sc.nextInt(); //商城界面输入数值
if (b == 1) {
chongzhi();
System.out.println("1.充值" + " " + "2.抽卡" + " " + "3.返回");
} else if (b == 2) {
chouka();
System.out.println("1.充值" + " " + "2.抽卡" + " " + "3.返回");
} else if (b == 3) {
break;
} else {
System.out.println("你输入的数据有误");
System.out.println("1.充值" + " " + "2.抽卡");
}
}
}
public static void chongzhi() {
System.out.println("您共消费了" + count + "元");
System.out.print("请输入你要充值的面额:1.60勾玉 ");
System.out.println("2.300勾玉 3.600勾玉 4. 1280勾玉 5.3280勾玉 6.6480勾玉");
int d = sc.nextInt(); //选择购买的礼包,共6种礼包
switch (d) {
case 1:
System.out.println("恭喜你获得60勾玉");
cast += 60; //购买第一个礼包获得60勾玉
count += 6;
break;
case 2:
System.out.println("恭喜你获得300勾玉");
cast += 300;
count += 30;
break;
case 3:
System.out.println("恭喜你获得600勾玉");
cast += 600;
count += 60;
break;
case 4:
System.out.println("恭喜你获得1280勾玉");
cast += 1280;
count += 128;
break;
case 5:
System.out.println("恭喜你获得3280勾玉");
cast += 3280;
count += 328;
break;
case 6:
System.out.println("恭喜你获得6480勾玉");
cast += 6480;
count += 648;
break;
default:
System.out.println("你输入的数值有误");
}
System.out.println("你当前剩余勾玉为" + cast);
}
public static void chouka() {
System.out.println();
System.out.println("请选择你要抽卡的类型");
System.out.println("1.单抽" + " " + "2.十连抽" +" "+ "(输入其他数字返回上一层)");
int a = sc.nextInt();
if (a == 1) {
if (cast > 100) {
danchou();
} else {
System.out.println("你的勾玉不足");
}
} else if (a == 2) {
if (cast >= 1000) {
shichou();
} else {
System.out.println("你的勾玉不足");
}
}
}
public static void danchou() {
int card = r.nextInt(10000);//定义抽卡范围
int W = card;//将抽卡数值转化成一个具体数值用来映射到具体名字
if (card > 9994) { //抽卡结算,UR
System.out.println("您是如此的lucky,抽到了UR卡"); // 先判定抽中UR
int P = r.nextInt(5); //再从五个人物中抽取一个
System.out.println(weapon[P]); // 直接输出人物名字
cast -= 100; //消耗100勾玉
System.out.println("你当前剩余勾玉为" + cast);
} else if (card > 9794) { //抽卡结算,SSR
System.out.print("您是如此的lucky,抽到了SSR"); //原理同SR,见下
int wssr = r.nextInt(16);
System.out.println(weapon[wssr]);
cast -= 100;
System.out.println("你当前剩余勾玉为" + cast);
} else if (card > 6794) { //抽卡结算,SR
System.out.println("恭喜你抽到SR");//先判定抽到SR
System.out.print("SR "); //再输入抽到的类别(不分行)
int wsr = r.nextInt(16); //再在SR武器数组(16把武器)中随机抽取一把
System.out.println(weapon1[wsr]); //在抽到的类别后(由于不分行),直接加上武器名字
cast -= 100; //每次单抽消耗100勾玉
System.out.println("你当前剩余勾玉为" + cast);
} else if (card <= 6794) { //抽卡结算,R
System.out.println("恭喜你抽到R卡");
cast -= 100;
System.out.println("你当前剩余勾玉为" + cast);
}
}
public static void shichou() {
int i = 1;
System.out.print("恭喜你抽到");
System.out.println("");
cast -= 1000; //每次十抽消耗1000勾玉
while (i <= 10) { //十连抽执行
int card = r.nextInt(10000);
if (card > 9994) { //抽卡结算,UR
System.out.print("UR");
int P = r.nextInt(5);
System.out.println(weapon[P] + " ");
} else if (card > 9794) { //抽卡结算,SSR
System.out.println("");
System.out.print("SSR");
int wssr = r.nextInt(16);
System.out.println(weapon[wssr]);
} else if (card > 6794) { //抽卡结算,SR
System.out.println("");
System.out.print("SR");
int wsr = r.nextInt(16);
System.out.println(weapon1[wsr]);
} else if (card <= 6794) { //抽卡结算,R
System.out.println("");
System.out.println("R*1 ");
}
i++;
}
}
}
|