0
我使用循环在文本文件上生成1个数字。我开始在用户开始玩游戏时遇到问题。使用循环和条件来改变游戏中的分数
我要正前方去,给我的伪代码,以便你能明白我想做...
- 随机生成介于0和10号10
- 存储这些数据到一个名为mysteryNumbers.txt文件,每行一个数
- 提示用户介于0和10
- 检查文件
- 中如果用户猜测正确,subtra输入一个号码这个号码对第一号ct 10从分数开始(分数为0)
- 如果用户猜测错误,将正确数量的分数添加到用户的当前分数(在开始时,分数为0)
- 提示用户输入一个数字0这个数字之间和10
- 核对文件
- 如果用户猜测就在第二个数字,减去10从得分
- 如果用户猜测错误,添加正确的得分到当前用户分数
- 提示用户输入0到10之间的数字
- 核对文件
- 如果用户猜测正确的第三号这个号码,从比分
- 如果用户猜测错误减去10,成绩的正确数量添加到用户 目前比分
- ...等等...
- 显示用户的分数:当然,越低越好!
- 我也按照伪代码大纲来组织下面的代码。
/************************************************************************************
PrintWriter mywriter = new PrintWriter("mysteryNumber.txt");
int randomNumber;
int i = 0;
i=1;
while (i<=10) {
Random randomGen = new Random();
randomNumber= randomGen.nextInt(11);
// then store (write) it in the file
mywriter.println(randomNumber);
i = i + 1;
}
//numbers are now generated onto text file...
/************************************************************************************
* 3. Prompt the user to enter a number between 0 and 10 */
Scanner myscnr= new Scanner (System.in);
System.out.print ("Please enter a number between 0 and 10: ");
int userNumber= myscnr.nextInt();
/************************************************************************************
* 4. Check this number against the first number in the file */
// to check the user's number against the file's, you need to be able to read
// the file.
FileReader fr = new FileReader("./mysteryNumber.txt");
BufferedReader textReader = new BufferedReader(fr);
int numberInFile;
// the number in your file is as follows:
numberInFile = Integer.valueOf(textReader.readLine());
/************************************************************************************
* 5. If the user guesses right, subtract 10 from the score */
/************************************************************************************
* 6. If the user guesses wrong, add the correct amount of score to the current *
* score of the user (at the start, the score is 0 */
/************************************************************************************
* 7. Prompt the user to enter a number between 0 and 10 */
//Sytem.out.println ("Enter a number between 0");
/************************************************************************************
* 8. Check this number against the second number in the file */
etc etc...
我很困惑从评论第5部分开始。我知道我必须创建一个新的整数分数,但之后,我迷路了! 我试图在if if statemnent工作,但我不能去它..