package _04_双色球;

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

public class Test1 {
    public static void main(String[] args) {
        // 生成中奖号码
        int[] prizeArr = createPrizeNumber();
        System.out.println("中奖号码为");
        for (int i = 0; i < prizeArr.length; i++) {
            System.out.print(prizeArr[i]+" ");
        }
        System.out.println();
        // 用户购买双色球
        int[] userPrizeArr = userInputPrizeNumber();
        // 红球中奖数量
        int redCountNumber = 0;
        // 蓝球中奖数量
        int blueCountNumber = 0;
        // 那用户每一个红球和 双色球中奖红球进行依次比较
        for (int i = 0; i < 6; i++) {
            // 用户输入红球
            int userInputRedNumber = userPrizeArr[i];
            for (int j = 0; j < 6; j++) {
                // 那双色球红球
                int prizeRedNumber = prizeArr[j];
                if(userInputRedNumber ==  prizeRedNumber){
                    redCountNumber ++;
                    break;
                }
            }
        }
        // 比较篮球
        if(prizeArr[prizeArr.length-1] == userPrizeArr[userPrizeArr.length-1]){
            blueCountNumber ++;
        }


        if((redCountNumber == 0 && blueCountNumber == 1)
                || (redCountNumber == 1 && blueCountNumber == 1)
        ){
            System.out.println("恭喜你中了六等奖 5元");
        }else if((redCountNumber == 2 && blueCountNumber == 1)
                || (redCountNumber == 3 && blueCountNumber == 1)
                || (redCountNumber == 4 && blueCountNumber == 0)
        ){
            System.out.println("恭喜你中了五等奖 10元");
        }else if((redCountNumber == 4 && blueCountNumber == 1)
                || (redCountNumber == 5 && blueCountNumber == 0)
        ){
            System.out.println("恭喜你中了四等奖200元");
        }else if((redCountNumber == 5 && blueCountNumber == 1)){
            System.out.println("恭喜中了三等奖 3000元");
        }else if((redCountNumber == 6 && blueCountNumber == 0)){
            System.out.println("恭喜中了二等奖 500万");
        }else if((redCountNumber == 6 && blueCountNumber == 1)){
            System.out.println("恭喜中了一等奖 1000万");
        }
    }
    // 用户购买号码
    private static int[] userInputPrizeNumber() {
        Scanner scanner = new Scanner(System.in);
        // 创建一个长度为7 存储购买号码
        int[] userArr = new int[7];
        // 先让用用户输入红球号码 不允许重复  在1-33 之间
        for (int i = 0; i < 6;) {
            System.out.println("请输入第"+(i+1)+" 个红球");
            int redNumber = scanner.nextInt();
            // 判断红球是否在数组当中
            boolean flag = contains(userArr, redNumber);
            if(!flag){
                userArr[i] = redNumber;
                i++;
            }else{
                System.out.println("输入号码已经存在了, 请重新输入");
            }
        }
        // 让用户输入蓝球号码在1-16 之间
        System.out.println("请输入蓝球");
        userArr[userArr.length-1]=scanner.nextInt();
        return userArr;
    }

    // 生成中奖号码
    private static int[] createPrizeNumber() {
        //1长度为7 的数组
        int[] arr = new int[7];
        //2 生成红球 6位  1-33
        Random random = new Random();
        for (int i = 0; i < 6; ) {
            //0 - 32  +1
            int redNumber = random.nextInt(33) +1;
            // 判断红球是否在数组当中已经存在了
            // 红球是不允许重复
            boolean flag = contains(arr,redNumber);
            if(!flag){
                arr[i] = redNumber;
                i++;
            }
        }
        //3 生成篮球   1-16
        arr[arr.length-1] = random.nextInt(16) + 1;
        return arr;
    }

    private static boolean contains(int[] arr, int redNumber) {
        boolean flag = false;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] == redNumber){
                flag = true;
                break;
            }
        }
        return flag;
    }
}
