欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java入门----猜拳小游戏

程序员文章站 2022-06-22 20:15:51
猜拳小游戏Java 入门-猜拳小游戏代码如下:import java.util.Random;import java.util.Scanner;public class RandomDemo { public static void main(String[] args) { Random qq = new Random(); Scanner oo = new Scanner(System.in); int diannao = qq.nex...

猜拳小游戏

Java 入门-猜拳小游戏

代码如下:

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

public class RandomDemo {
    public static void main(String[] args) {
        Random qq = new Random();
        Scanner oo = new Scanner(System.in);
        int diannao = qq.nextInt(10);
        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++){
            int nao = qq.nextInt(2);
            int wo = nao + 1;
            System.out.println("第"+i+"局!!!!!");
            System.out.println("输入你的猜拳:");
            int ni = oo.nextInt();  //玩家数字

            String dian = "电脑";
            String ren = "用户";

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

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

                case 3:
                    ren = "布";
                    break;

            }

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

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

                    case 3:
                        dian = "布";
                        break;


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

            if (ni == wo){
                System.out.println("你出的"+ren+",我出的"+dian+"平局啊!!!");
                System.out.println("");
                pingju++;
            }
            if (ni == 1&&wo == 2 || ni == 2&&wo == 3 || ni == 3&&wo == 1){
                System.out.println("你出的"+ren+",我出的"+dian+"\n你赢了,真厉害啊!!!");
                System.out.println("");
                wanjiashengli++;
            }
            if (ni == 1&&wo == 3 || ni == 2&&wo == 1 || ni == 3&&wo == 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电脑获得了胜利,奖励一个????");
        }


    }
}

本文地址:https://blog.csdn.net/Java_zi/article/details/109273300

相关标签: 小游戏 java