自己有事没事的记录,如果有错误还望指出。不喜勿喷
package GuessNumberGame;
import java.util.Scanner;
public class Game {
public static void main(String[] args)
{
System.out.println("欢迎你参与猜数字游戏(数字在0-9之间),你将拥有三次机会,需要在三次以内猜到正确数字,否则判定游戏失败");
//int GuessTimes=0;
int successfulTimes=0;
int failTimes=0;
int GameTimes=0;
boolean IfContinue=true;
while(IfContinue)
{
//随机生成数字
int Card=(int)(Math.random()*10);
System.out.println("第"+(GameTimes+1)+"次游戏");
Scanner inputNum=new Scanner(System.in);
for(int i=3;i>=1;i--)
{
//输入数字
System.out.println("你还有"+i+"次机会,请输入你的数字:");
int CardNum=inputNum.nextInt();
if(Card>CardNum)
{
System.out.println("你输入的数字有点小了噢");
}
else if (Card < CardNum )
{
System.out.println("你输入的数字有点大了噢");
}
else
{
System.out.println("恭喜你,猜对了!");
successfulTimes++;
GameTimes++;
break;
}
if(i==1)
{
failTimes++;
GameTimes++;
//break;
}
}
System.out.println("你还想继续游戏吗?");
System.out.println("0继续/1退出");
int conNum;
Scanner numJudge=new Scanner(System.in);
int NumJudge=numJudge.nextInt();
if(NumJudge==0)
{
IfContinue=true;
}
else
{
IfContinue=false;
}
}
System.out.println("你一共进行了"+GameTimes+"次游戏,成功"+successfulTimes+"次,失败"+failTimes+"次");
}
}