今天有人找我划拳,于是有了这个案例
public class Hq {
//三局两胜制猜拳
public static void main(String[] args){
System.out.println("开始出拳,提示 1剪刀 2石头 3布");
int v=0;//第一位玩家计分板
int s=0;//第二位玩家计分板
while(true){
//判断游戏是否结束
if(v==2){
System.out.println("玩家一胜利");
break;
}else if(s==2){
System.out.println("玩家一胜利");
break;
}
//第一位玩家出拳
Scanner yi=new Scanner(System.in);
int a=yi.nextInt();
//第二位玩家出拳
Scanner er=new Scanner(System.in);
int b=er.nextInt();
//判断当前局结果
if((a==1 && b==3) || (a==2 && b==1 ) || (a==3 && b==2)){
v=++v;
System.out.println("玩家一胜利"+v+"局");
}else if(a<1 || a>3|| b<1 || b>3){
System.out.println("玩家一或者玩家二输入不合法,请重新输入");
}else if( a==b){
System.out.println("平");
}else{
s=++s;
System.out.println("玩家一胜利"+s+"局");
}
}
}
}