• 【0627】骰子游戏


     1 package com.workprojects;
     2 /**
     3  * 骰子游戏
     4  * 押大押小决定游戏胜负
     5  * 2019-06-27
     6  * @author L
     7  * 
     8  */
     9 import java.util.Scanner;
    10 
    11 public class Work0627 {
    12     static Scanner sc = new Scanner(System.in);
    13 
    14     public static void main(String[] args) {
    15         // 欢迎进入游戏
    16         System.out.println("**欢迎来到暴富赌坊**");
    17         // 1.兑换筹码
    18         System.out.print("请输入想兑换的筹码:");
    19         int money = sc.nextInt();
    20         // 2.开始游戏 (1)摇三个骰子,摇出3个随机数,每个随机数在1-6之间
    21         System.out.println("*进入骰子游戏*");
    22         System.out.println("开始摇骰子....");
    23         while (true) {
    24             int a = (int) (Math.random() * 6 + 1);// 三个随机数
    25             int b = (int) (Math.random() * 6 + 1);
    26             int c = (int) (Math.random() * 6 + 1);
    27             int num = a + b + c;// 三个随机数相加
    28             String result = num < 10 ? "小" : "大";// 判断游戏结果
    29             System.out.println("选择押大,或者押小:");// 玩家选择押大或押小
    30             String guess = sc.next();
    31             // (2)玩家下注,下筹码,选择押大押小 (3-9是小, 10-18是大)
    32             System.out.println("选择下注筹码金额:");
    33             int pay = sc.nextInt();
    34             while (money < pay) {
    35                 // (3)开盘,判断结果是否和玩家一致,一致则本局获胜,反之输掉下注筹码。
    36                 System.out.println("下注金额输入有误,请重新输入!");
    37                 pay = sc.nextInt();
    38             }
    39             System.out.println("下注成功!展示游戏结果!");
    40             System.out.println(a + "	" + b + "	" + c + "
    " + "本轮游戏结果为:" + result);
    41             System.out.println();
    42             if (guess.equals(result)) {
    43                 money = money + pay;
    44             } else {
    45                 money = money - pay;
    46             }
    47             // (4)结算金额,是否继续下局游戏?
    48             System.out.println("您的当前余额为:" + money);
    49             if (money < (money / 5)) {
    50                 System.out.println("余额不足,游戏结束");
    51                 break;
    52             } else {
    53                 System.out.println("是否继续游戏?(y/n)");
    54                 String again = sc.next();
    55                 if ("n".equals(again)) {
    56                     System.out.println("您结束了游戏,感谢光临暴富赌坊,欢迎下次再来!");
    57                     break;
    58                 }
    59             }
    60 
    61         }
    62 
    63     }
    64 }

    package com.workprojects;/** * 骰子游戏 * 押大押小决定游戏胜负 * 2019-06-27 * @author L *  */import java.util.Scanner;
    public class Work0627 {static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {// 欢迎进入游戏System.out.println("**欢迎来到暴富赌坊**");// 1.兑换筹码System.out.print("请输入想兑换的筹码:");int money = sc.nextInt();// 2.开始游戏 (1)摇三个骰子,摇出3个随机数,每个随机数在1-6之间System.out.println("*进入骰子游戏*");System.out.println("开始摇骰子....");while (true) {int a = (int) (Math.random() * 6 + 1);// 三个随机数int b = (int) (Math.random() * 6 + 1);int c = (int) (Math.random() * 6 + 1);int num = a + b + c;// 三个随机数相加String result = num < 10 ? "小" : "大";// 判断游戏结果System.out.println("选择押大,或者押小:");// 玩家选择押大或押小String guess = sc.next();// (2)玩家下注,下筹码,选择押大押小 (3-9是小, 10-18是大)System.out.println("选择下注筹码金额:");int pay = sc.nextInt();while (money < pay) {// (3)开盘,判断结果是否和玩家一致,一致则本局获胜,反之输掉下注筹码。System.out.println("下注金额输入有误,请重新输入!");pay = sc.nextInt();}System.out.println("下注成功!展示游戏结果!");System.out.println(a + " " + b + " " + c + " " + "本轮游戏结果为:" + result);System.out.println();if (guess.equals(result)) {money = money + pay;} else {money = money - pay;}// (4)结算金额,是否继续下局游戏?System.out.println("您的当前余额为:" + money);if (money < (money / 5)) {System.out.println("余额不足,游戏结束");break;} else {System.out.println("是否继续游戏?(y/n)");String again = sc.next();if ("n".equals(again)) {System.out.println("您结束了游戏,感谢光临暴富赌坊,欢迎下次再来!");break;}}
    }
    }}

  • 相关阅读:
    主数据管理(MDM)的成熟度
    Tensorflow实战Google深度学习框架—郑泽宇书籍整理
    《Flink基础教程》王绍学习资料
    《重新定义计算(ApacheFlink实践)》_蒋晓伟资料整理
    js实现页面的自定义翻译
    谈谈px,em,rem(采自菜鸟)
    js和css分别实现元素曲线运动
    echarts鼠标事件以及自定义数据获取
    js数组的多条件排序
    H5-meta标签使用大全
  • 原文地址:https://www.cnblogs.com/yanglanlan/p/11100088.html
Copyright © 2020-2023  润新知