package game;import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;public class DoubleBallTest {/** 双色球投注区分为红色球号码区和蓝色球号码区, 红色球号码区由1-33共三十三个号码组成,* 蓝色球号码区由1-16共十六个号码组成。投注时选择6个红色球号码和1个蓝色球号码组成一注进行单式投注*//** 需要注意一点的是,有的方法有返回值有的没有:若需要得到的参数是引用数据类型,可不做返回值,因为对于引用数据类型来说,* 地址值不变,变的是内容,若需要返回基本数据类型,则方法需要有返回值* * 即为下面的内容: 1.对于基本数据类型的形参,形式参数的改变,不影响实际参数的值。* 即方法中修改的参数只是传递的小括号中的形参的值,即使实参与形参的变量名相同, 也不会影响到实参的值,只会更改小括号中形参的值。 2.* 对于引用数据类型的形参,形式参数的改变,会影响实际参数的值。(堆栈内存,引用的是同一个地址的缘故)* */public static void main(String[] args) {Scanner input = new Scanner(System.in);Random range = new Random();int[] red = new int[6];// 用于存储随机生成的6个红球int blue = 0;// 用于存储蓝球号int isgamblemoney = 0;// 用于存储用户输入的下注金额double bonus = 0.0;// 通过用户的下注得到若获奖得到的中奖金额double[] result = null;while (true) {int[] lottery = new int[7];// 用于存储最后选定的7个号码,每次循环要先清空原本数组的数据System.out.println("-------------------欢迎来到袁梦码双色球娱乐中心-----------------");System.out.println("-----------------------1.开始游戏--------------------------");System.out.println("-----------------------2.系统自动选号-----------------------");System.out.println("-----------------------3.一夜暴富-----------------------");System.out.println("-----------------------4.退出游戏--------------------------");System.out.print("请选择您的操作:");int selectVal = input.nextInt();switch (selectVal) {case 1:// 选择6个红球号码selectRedBall(input, lottery);// 选择篮球号码selectABlueBall(input, lottery);result = askingIsBetting(1, input, range, bonus, isgamblemoney);bonus = result[0];isgamblemoney = (int) result[1];// 系统自动产生7个球,并排除重复的红球blue = systemSelect(0, input, range, red, blue);break;case 2:// 系统自动产生7个球,并排除重复的红球blue = systemSelect(1, input, range, red, blue);for (int i = 0; i < red.length; i++) {lottery[i] = red[i];}lottery[6] = blue;// 下注result = askingIsBetting(2, input, range, bonus, isgamblemoney);bonus = result[0];isgamblemoney = (int) result[1];blue = systemSelect(0, input, range, red, blue);break;case 3:// 系统自动产生7个球,并排除重复的红球blue = systemSelect(2, input, range, red, blue);for (int i = 0; i < red.length; i++) {lottery[i] = red[i];}lottery[6] = blue;// 下注result = askingIsBetting(3, input, range, bonus, isgamblemoney);bonus = result[0];isgamblemoney = (int) result[1];blue = systemSelect(3, input, range, red, blue);break;case 4:System.out.println();System.out.println("******************退出成功,欢迎下次光临!!******************");System.out.println();return;default:System.out.println();System.out.println("******************输入的内容不符合要求,请重新输入!!******************");System.out.println();continue;}// 打印刚才自己选择的7个球号码,以及已经下注资金数System.out.println("您选择彩票号码是:" + Arrays.toString(lottery));System.out.println("已下注:" + isgamblemoney + "元");// 开奖结果getResult(lottery, red, blue, isgamblemoney, bonus);}}//------------------------------------------------方法---------------------------------------------------/*** 选择6个红球* * @param input* @param lottery* @return*/public static void selectRedBall(Scanner input, int[] lottery) {System.out.println("请选择您的6个红色球号;");for (int i = 0; i < 6; i++) {while (true) {System.out.print("第" + (i + 1) + "个:");lottery[i] = input.nextInt();int resultIndex01 = myRemoveRed(lottery, lottery[i]);if (resultIndex01 == 2) {System.out.println();System.out.println("******************该值已重复,请重新输入!!******************");System.out.println();continue;} else {if (lottery[i] < 1 || lottery[i] > 33) {System.out.println();System.out.println("******************红球号码的范围为1-33!!******************");System.out.println();continue;}}break;}}}/*** 选择一个篮球号码* * @param input* @param lottery* @return*/public static void selectABlueBall(Scanner input, int[] lottery) {System.out.print("请选择您的蓝色球号;");while (true) {lottery[6] = input.nextInt();if (lottery[6] < 1 || lottery[6] > 16) {System.out.println();System.out.println("******************蓝球的号码范围为:1-16!******************");System.out.println();System.out.print("请重新选择蓝球的号码:");continue;}break;}}/*** 询问是否下注* * @param input* @param range* @param bonus* @param isgamblemoney* @return*/public static double[] askingIsBetting(int flag, Scanner input, Random range, double bonus, int isgamblemoney) {while (true) {if (flag == 3) {isgamblemoney = 10000000;break;} else {System.out.println("请输入下注金额(1元、5元、10元、200元、3000元、5000000元、10000000元):");isgamblemoney = input.nextInt();}switch (isgamblemoney) {case 0:bonus = 0;break;case 1:bonus = isgamblemoney * 1;break;case 5:bonus = isgamblemoney * 2.5;break;case 10:bonus = isgamblemoney * 5;break;case 200:bonus = isgamblemoney * 100;break;case 3000:bonus = isgamblemoney * 1500;break;case 5000000:bonus = isgamblemoney * (range.nextInt(501) + 1500);break;case 10000000:bonus = isgamblemoney * (range.nextInt(501) + 1500);break;default:System.out.println();System.out.println("******************您输入的内容不符合要求,请重新输入!******************");System.out.println();continue;}break;}double[] result = new double[2];result[0] = bonus;result[1] = isgamblemoney;// 自动类型转换,在接收结果时,需要强转return result;}/*** 系统自动产生7个球,并排除重复的红球* * @param input* @param range* @return* @return*/public static int systemSelect(int flag, Scanner input, Random range, int[] red, int blue) {if (flag == 0) {blue = myTools01(input, range, red, blue);System.out.println("红球开奖号码为:" + Arrays.toString(red));System.out.println("蓝球开奖号码为:" + blue);} else if (flag == 1) {blue = myTools01(input, range, red, blue);System.out.println("系统为您开的红球号码为:" + Arrays.toString(red));System.out.println("系统为您开的蓝球号码为:" + blue);} else if (flag == 2) {blue = myTools01(input, range, red, blue);} else if (flag == 3) {System.out.println("红球开奖号码为:" + Arrays.toString(red));System.out.println("蓝球开奖号码为:" + blue);}return blue;}/*** 用于简化 systemSelect 的代码* * @param input* @param range* @param red* @param blue* @return*/public static int myTools01(Scanner input, Random range, int[] red, int blue) {System.out.println("");System.out.println("-------------$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$-------------------");blue = range.nextInt(16) + 1;// 用于存储蓝球号for (int i = 0; i < 6; i++) {red[i] = range.nextInt(33) + 1;}
//      排除红球号码有重复的数字for (int i = 0; i < red.length - 1; i++) {// 外层需要遍历4次;即范围是:0-3:4个下标;外层循环是要比较的次数int dest = red[i];for (int j = 1 + i; j < red.length; j++) {// 内层是从角标+1开始,不与自身比较了,范围为4,所以< 5if (dest == red[j]) {red[j] = range.nextInt(33) + 1;// 如果有重复的,就再自动生成一个随机数替换一个重复的值}}}return blue;}/*** 开奖结果* * @param lottery       存储最后选定的7个号码* @param red           存储的是系统选定的6个红球号码* @param blue          存储的是系统选定的篮球号码* @param isgamblemoney 下注金额* @param bonus         赔率*/public static void getResult(int[] lottery, int[] red, int blue, int isgamblemoney, double bonus) {int rednumber = 0;// 用于记录红球中的个数
//      将自己选的红球号码与随机生成的号码进行比较for (int i = 0; i < lottery.length - 1; i++) {for (int j = 0; j < red.length; j++) {if (lottery[i] == red[j]) {rednumber++;}}}System.out.println("红球中奖的号码个数为:" + rednumber);if (lottery[6] == blue) {System.out.println("恭喜您:蓝色球号已中1");} else {System.out.println("很遗憾:蓝色球号没中0");}double money = 0;switch (rednumber) {case 0:if (lottery[6] == blue) {System.out.println("恭喜中奖(六等奖):中奖说明:中" + rednumber + "+" + "1");if (isgamblemoney == 1) {money = 5 + bonus;System.out.println("您的奖金为:" + money + "元");} else {money = 5;System.out.println("您的奖金为:" + money + "元");}} else {System.out.println("没有中奖:经验证可以跳楼了");}break;case 1:if (lottery[6] == blue) {System.out.println("恭喜中奖(六等奖):中奖说明:中" + rednumber + "+" + "1");if (isgamblemoney == 1) {money = (rednumber + 1) * 5 + bonus;System.out.println("您的奖金为:" + money + "元");} else {money = (rednumber + 1) * 5;System.out.println("您的奖金为:" + money + "元");}} else {System.out.println("恭喜中奖(六等奖):中奖说明:中" + rednumber + "+" + "0");if (isgamblemoney == 1) {money = rednumber * 5 + bonus;System.out.println("您的奖金为:" + money + "元");} else {money = rednumber * 5;System.out.println("您的奖金为:" + money + "元");}}break;case 2:if (lottery[6] == blue) {System.out.println("恭喜中奖(六等奖):中奖说明:中" + rednumber + "+" + "1");if (isgamblemoney == 1) {money = (rednumber + 1) * 5 + bonus;System.out.println("您的奖金为:" + money + "元");} else {money = (rednumber + 1) * 5;System.out.println("您的奖金为:" + money + "元");}} else {System.out.println("恭喜中奖(六等奖):中奖说明:中" + rednumber + "+" + "0");if (isgamblemoney == 1) {money = rednumber * 5 + bonus;System.out.println("您的奖金为:" + money + "元");} else {money = rednumber * 5;System.out.println("您的奖金为:" + money + "元");}}break;case 3:if (lottery[6] == blue) {System.out.println("恭喜中奖(五等奖):中奖说明:中" + rednumber + "+" + "1");if (isgamblemoney == 1) {money = (rednumber + 1) * 10 + bonus;System.out.println("您的奖金为:" + money + "元");} else {money = (rednumber + 1) * 10;System.out.println("您的奖金为:" + money + "元");}} else {System.out.println("恭喜中奖(五等奖):中奖说明:中" + rednumber + "+" + "0");if (isgamblemoney == 1) {money = rednumber * 10 + bonus;System.out.println("您的奖金为:" + money + "元");} else {money = rednumber * 10;System.out.println("您的奖金为:" + money + "元");}}break;case 4:if (lottery[6] == blue) {System.out.println("恭喜中奖(四等奖):中奖说明:中" + rednumber + "+" + "1");if (isgamblemoney == 1) {money = (rednumber + 1) * 200 + bonus;System.out.println("您的奖金为:" + money + "元");} else {money = (rednumber + 1) * 200;System.out.println("您的奖金为:" + money + "元");}} else {System.out.println("恭喜中奖(五等奖):中奖说明:中" + rednumber + "+" + "0");if (isgamblemoney == 1) {money = rednumber * 10 + bonus;System.out.println("您的奖金为:" + money + "元");} else {money = rednumber * 10;System.out.println("您的奖金为:" + money + "元");}}break;case 5:if (lottery[6] == blue) {System.out.println("恭喜中奖(三等奖):中奖说明:中" + rednumber + "+" + "1");if (isgamblemoney == 1) {money = (rednumber + 1) * 3000 + bonus;System.out.println("您的奖金为:" + money + "元");} else {money = (rednumber + 1) * 3000;System.out.println("您的奖金为:" + money + "元");}} else {System.out.println("恭喜中奖(四等奖):中奖说明:中" + rednumber + "+" + "0");if (isgamblemoney == 1) {money = rednumber * 200 + bonus;System.out.println("您的奖金为:" + money + "元");} else {money = rednumber * 200;System.out.println("您的奖金为:" + money + "元");}}break;case 6:if (lottery[6] == blue) {System.out.println("恭喜中奖(一等奖):中奖说明:中" + rednumber + "+" + "1");if (isgamblemoney == 1) {money = (rednumber + 1) * 10000000 + bonus;System.out.println("您的奖金为:" + money + "元");} else {money = (rednumber + 1) * 10000000;System.out.println("您的奖金为:" + money + "元");}} else {System.out.println("恭喜中奖(二等奖):中奖说明:中" + rednumber + "+" + "0");if (isgamblemoney == 1) {money = rednumber * 5000000 + bonus;System.out.println("您的奖金为:" + money + "元");} else {money = rednumber + 1 * 5000000;System.out.println("您的奖金为:" + money + "元");}}break;}System.out.println("-------------$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$-------------------");System.out.println("");}/*** 顺序查找,实现排除后球重复* * @param arr* @param selectValue* @return*/public static int myRemoveRed(int[] arr, int selectValue) {int count = 0;for (int i = 0; i < arr.length; i++) {if (selectValue == arr[i]) {count++;}}return count;}}

Java代码实现双色球小游戏2.0:完整代码(待完善)相关推荐

  1. Java 开发打飞机小游戏(附完整源码)

    上图 写在前面 技术源于分享,所以今天抽空把自己之前用java做过的小游戏整理贴出来给大家参考学习.java确实不适合写桌面应用,这里只是通过这个游戏让大家理解oop面向对象编程的过程,纯属娱乐.代码 ...

  2. 20行python代码的入门级小游戏-200行Python代码实现的2048小游戏

    2048这个小游戏大家都不陌生,应该都玩过,之前已经在网上见过各个版本的2048实现了,有JAVA.HTML5等,今天我就给大家来一个我自己在 实验楼 学到的python版2048.所有代码加起来才2 ...

  3. Java实现贪吃蛇小游戏(附完整源码)

    今天我就从零开始来完成这个小游戏,完成的方式也是一步一步的添加功能这样的方式来实现. 第一步完成的功能:写一个界面 大家见到的贪吃蛇小游戏,界面肯定是少不了的.因此,第一步就是写一个小界面. 实现代码 ...

  4. HTML+js实现贪吃蛇小游戏(内含完整代码)

    案例分析 看图拆解游戏 首先我们根据图片上的内容把这个游戏拆解成几个部分去单独看: 最外面的大盒子包裹着内容加边框限制蛇的活动范围,整个范围可以看成由许多小方格排列构成的,例如这样子的:: 两个按钮, ...

  5. 编程语言用 Java 开发一个打飞机小游戏(附完整源码)

    编程语言用 Java 开发一个打飞机小游戏(附完整源码) 上图 写在前面 技术源于分享,所以今天抽空把自己之前用java做过的小游戏整理贴出来给大家参考学习.java确实不适合写桌面应用,这里只是通过 ...

  6. java2048小游戏源码及解析_200行java代码实现2048小游戏

    本文实例为大家分享了java实现2048小游戏的具体代码,供大家参考,具体内容如下 效果图: 游戏介绍: 1.2048是一款益智类小游戏,刚开始随机出现两个数字,可以上下左右控制数字的移动. 2.当选 ...

  7. Java控制台游戏~600行代码实现打怪小游戏

    Java控制台游戏~600行代码实现打怪小游戏(多图预警) 一,先放个启动界面(一些英雄,怪物技能介绍跟装备属性都写在里边): 二,在这个简单的小游戏里,你可以体验到: 1.打怪: 2.随机玩法寻宝: ...

  8. 【Java】推箱子小游戏(带背景音乐)完整代码

    Java实现推箱子小游戏 一.整体框架 二.游戏效果图 三.推箱子四大类 1. GameFrame类 2. Map类 3. MapFactory类 4. Sound类 四.游戏分析 1.游戏操作 2. ...

  9. 【Java】Java基础飞机大战小游戏完整代码

    Java基础飞机大战小游戏完整代码 先来展示一下代码实现结果图 主函数ShootGame 初始化游戏原始背景图片,游戏人物图片,游戏开始结束图片:构建产生敌人算法:产生英雄机算法:发射子弹算法:判断是 ...

最新文章

  1. 微信小程序日期相减得出天数
  2. 机器学习基础-数据降维
  3. Dubbo自定义异常message过长解决
  4. 前9个免费的Java流程监视工具以及如何选择一种
  5. 螺旋矩阵 java实现(待消化)
  6. Python学习笔记——变量和字符串
  7. 现在学java的都是傻子?
  8. 电脑当路由使用(目前只在win7上用过)
  9. Nginx网站根目录更改及导致403 forbidden的问题解决
  10. hook原理介绍与简单实例
  11. python程序停止运行、重新开始_求教,程序执行到末尾如何重新开始的问题。
  12. Arrays和比较器
  13. jupyter notebook添加conda虚拟环境
  14. ITIL4讲解: 组合管理
  15. linux下find搜索jpg格式图片,Linux文件查找命令-find
  16. ## Asset Store(unity商店) 如何下载已购买的资源?*
  17. word打印机显示服务器脱机,教你怎样解决打印机脱机打印-word资料(精).docx
  18. 微信小程序阅读器功能
  19. Useing rvm
  20. Oracle 中LONG RAW BLOB CLOB类型介绍

热门文章

  1. html中td,dd属性,HTML的dl、dt、dd标记制作表格对决Table制作表过
  2. 2018年9月13日训练日记
  3. 阿里研究院发布《2020中国区块链发展报告》,毛球科技助力数字经济加速发展
  4. 陪伴型机器人主场到来:热衷跳舞的波士顿“狗”开始搬砖、Sophia量产恐怖谷效应显现、与人类互动的机器狗来了 | 硅谷速递...
  5. 陶泓达:最新黄金,原油短线交易策略!
  6. ASP使用MD5加密
  7. win7 生成jar包
  8. python 全栈开发,Day62(外键的变种(三种关系),数据的增删改,单表查询,多表查询)...
  9. 第五章 机械加工工艺过程设计 小结
  10. 色散关系与等离子体色散函数的解析性质