import java.util.Scanner;
public class Guess
{
static int x;
static int y = 3;
static Guess guess = new Guess();
public void reminder()
{
System.out.println("**请输入有效数字1-3**");
System.out.println("**1剪刀;2石头;3布**");
}
public static void main(String[] args)
{
startGame();
}
public static void startGame()
{
Scanner in = new Scanner(System.in);
try{
System.out.println("猜拳游戏,您还有"+y+"次游戏机会");
System.out.println("请出拳:1为剪刀;2为石头;3为布");
int person = in.nextInt();
if(person < 4)
{
int inputValue = (int)(Math.random()*3)+1;
String Marks = "拳头";
String Marks2 = "拳头";
switch(person)
{
case 1:
Marks = "剪刀";
break;
case 2:
Marks = "石头";
break;
case 3 :
Marks = "布";
break;
}
switch(inputValue)
{
case 1:
Marks2 = "剪刀";
break;
case 2:
Marks2 = "石头";
break;
case 3 :
Marks2 = "布";
break;
}
if(person == inputValue)
{
System.out.println("平局,您与电脑出的都是"+Marks2);
x++;
--y;
System.out.println("您还可以玩"+y+"次");
if(y == 0)
{
System.exit(0);
}
System.out.println("你可以输入1继续猜拳!");
int inputValueTwo = in.nextInt();
if(inputValueTwo == 1 )
{
if(x<3)
{
startGame();
}else
{
System.out.println("游戏结束");
}
}
else if(inputValueTwo != 1 )
{
guess.reminder();
--y;
startGame();
}
else
{
System.exit(0);
}
}
else if(person == 1 && inputValue == 2||person == 2 && inputValue == 3 || person == 3 && inputValue == 1)
{
System.out.println("您输了-_-,您出的是"+Marks+"电脑出的是:"+Marks2);
++x;
--y;
System.out.println("您还可以玩"+y+"次");
if(y == 0)
{
System.exit(0);
}
System.out.println("你可以输入1继续猜拳!");
int inputValueFour = in.nextInt();
if(inputValueFour == 1 )
{
if(x<3)
{
startGame();
}else
{
System.out.println("游戏结束");
}
}
else if(inputValueFour != 1 )
{
guess.reminder();
--y;
startGame();
}
else
{
System.exit(0);
}
}
else
{
System.out.println("您赢了^_^,您出的是"+Marks+"电脑出的是"+Marks2);
++x;
--y;
System.out.println("您还可以玩"+y+"次");
if(y == 0)
{
System.exit(0);
}
System.out.println("你可以输入1继续猜拳!");
int inputValueThree = in.nextInt();
if(inputValueThree == 1 )
{
if(x<3)
{
startGame();
}else{
System.out.println("游戏结束");
}
}
else if(inputValueThree != 1 )
{
guess.reminder();
--y;
startGame();
}
else
{
System.exit(0);
}
}
}
else
{
++x;
--y;
System.out.println("您已经失去一次猜拳的机会!");
if(x<=3)
{
guess.reminder();
startGame();
}else
{
System.out.println("您已经玩了3次");
}
}
}
finally
{
in.close();
}
}
}
Guess(写的很糟糕,虽然目前就这水平)
最新推荐文章于 2024-05-06 13:44:25 发布