用Java写一个简单的猜拳游戏
不多说直接上代码:
import java.util.*;
public class Yancey20{
public static void main(String[]args){
int score=0;//记录得分情况
int count=0;//记录出拳的次数
System.out.println("欢迎来到猜拳游戏,请输入您的昵称:");
Scanner in=new Scanner(System.in);
String name=in.next();
while(true){
Random ran=new Random();
int rang=ran.nextInt(3)+1;//产生0--2的随机数
String duishou="";
if(rang==1){duishou="石头";}
else if(rang==2){duishou="布";}
else{duishou="剪刀";}
Scanner input=new Scanner(System.in);
System.out.println();
System.out.println("请选择下列编号出拳:");
System.out.println("1:石头 2:布 3:剪刀 0:结束本轮游戏");
//System.out.println(duishou);
int chuquan=input.nextInt();
if(chuquan==0) break;
if(chuquan>3||chuquan<0){
System.out.println("出拳错误");
}
else if(chuquan==1){
System.out.pr