import java.util.*;
class 猜拳 {
public static void main(String[] args) {
/*
猜拳游戏
*/
// 电脑 随机 出拳;
Scanner in = new Scanner (System.in);
int r = 0;
int d = 0;
while(true){
int a = getSJS1();
// --------------------------
System.out.println("请你出拳");
String t =in.next();
// t a
if((t.equals("剪刀") && a ==3)|| (t.equals("石头") && a ==2) || (t.equals("布")&& a ==1)){
System.out.print("你赢了");
r++;
}else if ((t.equals("剪刀")&&a==2)|| (t.equals("石头")&& a ==1) || (t.equals("布")&& a ==3)){
System.out.print("平局");
r++;
d++;
}else{
System.out.print("电脑赢了");
d++;
}
if(r == 2 || d == 2 ){
break;
}
if(r > d){
System.out.print(" 最终的 赢家是 人" );
}else if(r < d){
System.out.print(" 最终的 赢家是电脑" );
}else{
System.out.print(" 最终的 结果是平局" );
}
}
public static int getSJS(){
Random r =new Random();
return r.nextInt(100)+1;
}
public static int getSJS1(){
Random r =new Random();
return r.nextInt(3)+1;
}
}
|
|