Java-人机猜拳比赛 入门小白可以看看 ~ 大佬请无视

Java做的小游戏,有兴趣可以看看

刚学Java第一天,做的小游戏~

修改版~

import java.util.Scanner;

public class Kaaaa {
    public static void main(String[] args) {
        Scanner oo = new Scanner(System.in);
        int wanjiashengli = 0;
        int diannaoshengli = 0;
        int pingju = 0;

        System.out.println("\t\t\t\t\t\t剪刀石头步游戏");
        System.out.println("输入您想要游戏的局数:");
        int wanjia = oo.nextInt();  //玩家输入的游戏  局数
        System.out.println("\t\t\t\t\t\t  游戏开始:\n\t\t\t\t 请注意1代表石头,2代表剪刀,3代表布");
        for (int i = 1;i <= wanjia;i++){

            System.out.println("第"+i+"局!!!!!");
            System.out.println("输入你的猜拳:");
            int ni = oo.nextInt();  //玩家数字
            int nao = (int)(Math.random()*3)+1;  //电脑随机数字
            String dian = "电脑";
            String ren = "用户";

            //玩家
            switch (ni){
                case 1:
                    ren = "石头";
                    break;

                case 2:
                    ren = "剪刀";
                    break;

                case 3:
                    ren = "布";
                    break;

            }

            //电脑
            switch (nao){
                case 1:
                    dian = "石头";
                    break;

                case 2:
                    dian = "剪刀";
                    break;

                case 3:
                    dian = "布";
                    break;


            }
            //1石头,2剪刀,3布

            if (ni == nao){
                System.out.println("你出的"+ren+",我出的"+dian+"平局啊!!!");
                System.out.println("");
                pingju++;
            }
            if (ni == 1&&nao == 2 || ni == 2&&nao == 3 || ni == 3&&nao == 1){
                System.out.println("你出的"+ren+",我出的"+dian+"\n你赢了,真厉害啊!!!");
                System.out.println("");
                wanjiashengli++;
            }
            if (ni == 1&&nao == 3 || ni == 2&&nao == 1 || ni == 3&&nao == 2){
                System.out.println("你出的"+ren+",我出的"+dian+"\n你输了,真笨啊!!!");
                System.out.println("");
                diannaoshengli++;
            }

        }
        if (wanjiashengli == diannaoshengli){
            System.out.println("最终比分为:\n您的总胜场:"+wanjiashengli+"\n电脑的总胜场:"+diannaoshengli+"\n平局场:"+pingju+"\n平局,再来一盘吧");
        }
        if (wanjiashengli > diannaoshengli){
            System.out.println("最终比分为:\n您的总胜场:"+wanjiashengli+"\n电脑的总胜场:"+diannaoshengli+"\n平局场:"+pingju+"\n你获得了胜利,奖励一个香蕉");
        }
        if (wanjiashengli < diannaoshengli){
            System.out.println("最终比分为:\n您的总胜场:"+wanjiashengli+"\n电脑的总胜场:"+diannaoshengli+"\n平局场:"+pingju+"\n电脑获得了胜利,奖励一个巴掌");
        }


    }
}
©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页