这次没有用递归了,上班没时间学 学JAVA 学的好慢。下午又空又改进了下 用递归太麻烦了。
import java.util.Scanner;
public class Guess1
{
static int x; //对比操作判断,归零for循环初始值
static int j; //for 循环
static Guess1 rm = new Guess1();
public void exit() //退出
{
System.exit(0);
}
public void reminder() //提示
{
System.out.println("---------------------");
System.out.println("**请输入有效数字1-3**");
System.out.println("**1剪刀;2石头;3布**");
System.out.println("---------------------");
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
try
{
while(true)
{
for(j = 0; j < 3; ++j)
{
System.out.println("猜拳游戏");
System.out.println("1为拳头2为剪刀3为布");
System.out.println("您还有"+(3-j)+"次游戏机会");
int personInputValue = in.nextInt();
if(personInputValue < 4 )
{
int inputValue = (int)(Math.random()*3)+1;
String Marks = "拳头";
String Marks2 = "拳头";
switch(personInputValue)
{
case 1:
Marks = "剪刀";
break;
case 2:
Marks = "石头";
break;
case 3:
Marks = "布";
break;
}
switch(inputValue)
{
case 1:
Marks2 = "剪刀";
break;
case 2:
Marks2 = "石头";
case 3:
Marks2 = "布";
}
while(x < 3)
{
if(personInputValue == inputValue)
{
System.out.println("平局"+Marks2+"and"+Marks);
break;
}
else if(personInputValue == 1 && inputValue == 2 || personInputValue == 2 && inputValue == 3 ||personInputValue == 3 && inputValue == 1 )
{
System.out.println("您输了"+Marks2+"and"+Marks);
break;
}
else
{
System.out.println("您赢了"+Marks2+"and"+Marks);
break;
}
}
}
else
{
rm.reminder(); //调用提示信息
}
}
System.out.println("继续请输入yes,退出任意输入");
String flag = in.next();
if(flag.equals("yes"))
{
j = x;
}
else
{
System.out.println("游戏结束");
rm.exit(); //调用程序退出
}
}
}
finally
{
in.close();
}
}
}