作业要求:利用“ Math.random ( )  ”生成随机数的方法拟来模拟同时摇三个色子获得的点数;点数的多少不同,也会导致不同的输出结果;可适当对程序增添一些更有趣的功能;作业优化:.......

作业要求:

利用“ Math.random ( )  ”生成随机数的方法来模拟同时摇三个色子获得的点数;点数的多少不同,也会导致不同的输出结果;可适当对程序增添一些更有趣的功能;

作业优化:

import java.util.*;
public class 摇色子{
    static int shu2;
    static int a, b, c, mo, moo;
    public static void main(String [] args){
        int shu;
        p("欢迎来到竞技场,这位其貌不扬的同学!\n");
        p("请问是否进入游戏?\n");
        p("请输入:1(进入)/0(退出)    ");
        shu=s();
        if(shu==1){
            p("正在载入《色子王2.0》....\n");
            shaiZi();
        }
        else {
            p("臭屌丝,没钱你来干嘛!\n");
        }

    }

    public static void shaiZi(){
        do {
            a = (int) (Math.random() * 6 + 1);
            b = (int) (Math.random() * 6 + 1);
            c = (int) (Math.random() * 6 + 1);
            int num = a + b + c;
            p("您的点数为:" + num+"\n");
            if (1 <= num && num < 7) {
                p("孩子,消停回家种地去吧\n");
                mo = -(int) (Math.random() * 100 + 1);
            }
            if (7 <= num && num < 13) {
                p("有点实力嘛!\n");
                mo = (int) (Math.random() * 100 + 1);
            }
            if (13 <= num && num <= 18) {
                p("赌神大人,刚才是小人瞎了狗眼,请您不要在意\n");
                mo = (int) (Math.random() * 200 + 1);
            }
            moo += mo;
            p("这位同学,您现在筹码余额为:" + moo+"w\n");
            p("请问是否继续赌局?\n");
            p("请输入:1(继续)/0(退出)");
            shu2=s();
        }
        while(shu2==1);
        p("这位同学,您目前账户余额为:"+moo+"w\n");
        p("欢迎下次光临!\n");
    }

    public static void p(String a){
        System.out.print(a);
    }

    public static int s() {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        return a;
    }

}

部分效果展示:

点击查看 (●'◡'●)

欢迎来到竞技场,这位其貌不扬的同学!
请问是否进入游戏?
请输入:1(进入)/0(退出)    1
正在载入《色子王2.0》....
您的点数为:10
有点实力嘛!
这位同学,您现在筹码余额为:12w
请问是否继续赌局?
请输入:1(继续)/0(退出)1
您的点数为:9
有点实力嘛!
这位同学,您现在筹码余额为:73w
请问是否继续赌局?
请输入:1(继续)/0(退出)1
您的点数为:12
有点实力嘛!
这位同学,您现在筹码余额为:77w
请问是否继续赌局?
请输入:1(继续)/0(退出)0
这位同学,您目前账户余额为:77w
欢迎下次光临!

Process finished with exit code 0

点击查看 ~( ̄▽ ̄)~*

点击查看 ☜(゚ヮ゚☜)
欢迎来到竞技场,这位其貌不扬的同学!
请问是否进入游戏?
请输入:1(进入)/0(退出)    0
臭屌丝,没钱你来干嘛!

Process finished with exit code 0

博主能力有限,若程序有bug或有其他不当之处,请狠狠打脸博主           (~ ̄(OO) ̄)ブ