/*人机猜拳游戏,人:输入所出手势,机器:随机生成所出手势*/
/*该程序仅实现了单次的猜拳游戏,你可以后续添加一个大循环决定游戏结束的条件或者对相应的人机获胜场次进行统计,
统计一定场次中的获胜者*/
//程序结果如下:
package Game_Guessing;
import java.util.Scanner;
public class Test_One {
public static void main(String[] args){
int gesture = (int) (Math.random()*3);
int you_input;
int flag = 3;
String what = "",you_what = "",flag_result = "";
switch(gesture)
{
case 0: what = "布";break;
case 1: what = "剪刀";break;
case 2: what = "石头";break;
}
System.out.println("你出什么?(石头(2)、剪刀(1)、布(0)):");
Scanner sc = new Scanner(System.in);
you_input = sc.nextInt();
while(you_input > 2 || you_input < 0)
{
System.out.print("输入错误,请重新输入:");
you_input = sc.nextInt();
}
switch(you_input)
{
case 0: you_what = "布";break;
case 1: you_what = "剪刀";break;
case 2: you_what = "石头";break;
}
//判断石头剪刀布的胜负关系
if(gesture > you_input ){
if(gesture == 2 && you_input == 0){
flag = 1;
}
else flag = 0;
}
else if(gesture < you_input) {
if(gesture == 0 && you_input ==2){
flag = 0;
}
else flag = 1;
}
else if(gesture == you_input){
flag = 2;
}
switch(flag){
case 0: flag_result = "输";break;
case 1: flag_result = "赢";break;
case 2: flag_result = "平局";break;
}
System.out.print("计算机出的是:"+what+","+"你出"+you_what+","+"你"+flag_result+"了。");
}
}