猜拳系统

···
package game.test;

import java.util.Scanner;

public class Scissors_Stone_Cloth {
public static void main(String[] args) {
while (true) {
System.out.println("*******************************");
System.out.println("--------欢迎进入猜拳游戏--------");
System.out.println("请出拳:(1是剪刀,2是石头,3是布)");
Scanner sc=new Scanner(System.in);
int person=sc.nextInt();
int computer=(int)(Math.random()*3)+1; //电脑随机出拳
String per="用户";
String com = "电脑";

        switch(person){
            case 1:
                per="剪刀";
                break;
            case 2:
                per="石头";
                break;
            case 3:
                per="布";
                break;
        }
        
        switch(computer){
            case 1:
                com="剪刀";
                break;
            case 2:
                com="石头";
                break;
            case 3:
                com="布";
                break;
        }

     
        if(person==1&&computer==3||person==2&&computer==1||person==3&&computer==2){
            System.out.println("你出的是("+per+") 电脑出的是("+com+")");
            System.out.println("       【你输了!再来一次吧】");
            //System.out.println();
        }else if (person==computer){
            System.out.println("你出的是("+per+") 电脑出的是("+com+")");
            System.out.println("       【平局!再来一次吧】");
           // System.out.println();
        }else{
            System.out.println("你出的是("+per+") 电脑出的是("+com+")");
            System.out.println("       【恭喜你赢了!!!】");
            System.out.println("【你终于战胜了电脑,游戏结束!】");;
            break;
        }
    }
}

}

···

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容