java代码实现双色球小游戏(待完善)

package game;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class DoubleBall {

	/*
	 * 双色球投注区分为红色球号码区和蓝色球号码区, 红色球号码区由1-33共三十三个号码组成,
	 * 蓝色球号码区由1-16共十六个号码组成。投注时选择6个红色球号码和1个蓝色球号码组成一注进行单式投注
	 */
	public static void main(String[] args) {

		// 选择号码
		Random range = new Random();
		Scanner input = new Scanner(System.in);
		int[] lottery = new int[7];// 用于存储最后选定的7个号码
		System.out.println("------------请选择6个红球号码----------");
		int count = 0;// 用于记录红球重复的个数
		for (int i = 0; i < 6; i++) {
			count = 0;// 每次循环重新初始化
			System.out.print("请选择第" + (i + 1) + "个红球号码:");
			lottery[i] = input.nextInt();
			// 红球号码去重
			for (int j = 0; j < lottery.length; j++) {
				if (lottery[i] == lottery[j]) {
					count++;
				}
			}
			if (count == 2) {
				System.out.println("------该红球号码已重复!!------");
				i--;
				continue;
			} else {
				// 判断红球号码是否超出范围
				if (lottery[i] < 1 || lottery[i] > 33) {
					System.out.println("----------红球的号码范围是1-33!!-------");// break、continue、return
					i--;
					continue;
				}
			}
		}

		// 选择蓝球的号码
		System.out.println("请选择蓝球号码:");
		while (true) {
			lottery[6] = input.nextInt();
			if (lottery[6] < 1 || lottery[6] > 16) {
				System.out.println("----------蓝球的号码范围是1-16!!-------");// break、continue、return
				System.out.print("请重新选择蓝球的号码:");
				continue;
			}
			break;
		}
		// 询问是否下注
		double bonus = 0.0;
		int isgamblemoney = 0;// 用于存储用户输入的下注金额
		while (true) {
			System.out.println("请输入下注金额(1元、5元、10元、200元、3000元、5000000元、10000000元):");
			isgamblemoney = input.nextInt();
			switch (isgamblemoney) {
			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("-------您输入的内容不符合要求,请重新输入!-------");
				continue;
			}
			break;
		}

		System.out.println("您选择彩票号码是:" + Arrays.toString(lottery));
		System.out.println("已下注;" + isgamblemoney + "元");

//		系统随机(伪随机:有规则的随机)
		int[] red = new int[6];// 用于存储随机生成的6个红球
		int blue = range.nextInt(16) + 1;// 用于存储蓝球号 1-16

		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,所以< 5
				if (dest == red[j]) {
					red[j] = range.nextInt(33) + 1;// 如果有重复的,就再自动生成一个随机数替换一个重复的值
				}
			}
		}

		System.out.println("红球开奖号码为:" + Arrays.toString(red));
		System.out.println("蓝球开奖号码为" + blue);

		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;
		}
	}
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

袁梦码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值