Still it does not show the high score. Can you please tell me where the error is ??
See my code below:
[public class NumberGuessingGame/]
{
[public static void main (String[] args)/]
{
[Console c = new Console ("Number Guessing Game");/]
// Open a text file "input.txt" for input.
// Refer to this file using the object named inFile.
// The first line of the fle is: 88 word 6.725
TextInputFile inFile = new TextInputFile ("input.txt");
String highScoreName = inFile.readLine (); // read from file
int highScore = inFile.readInt (); // read from file
// We should close any open files when we're done with them.
inFile.close ();
// for testing
//c.println ("The file input.txt contains:");
//c.println (first + " " + name + " " + second);
// Write the items read from "input.txt" in REVERSE ORDER into the output file
//c.println("\nNow writing contents of file input.txt into file output.txt (in reverse order)");
char option = 'Y';
while (option != 'N' && option != 'n')
{
int secretNumber = (int) (Math.random () * 100);
//we also declare each new variable as needed
//int secretNumber =
int guessNumber = 0;
int guessTaken = 0;
int highestScore = 0;
int score = 0;
//Input the information from the keyboard
c.setTextBackgroundColor (Color.PINK);
c.setTextColor (Color.BLUE);
c.println ("\t NUMBER GUESSING GAME");
c.println ("");
c.println ("Please enter your name: ");
String name = c.readLine ();
//c.println ("Secret number is: " + secretNumber);
c.println ("Hello " + name);
while (guessNumber != secretNumber)
{
c.println ("Please enter the guessing number: ");
guessNumber = c.readInt ();
guessTaken++;
if (guessNumber < secretNumber)
{
c.println ("Your guessing number is too law! Try again");
}
else if (guessNumber > secretNumber)
{
c.println ("Your guessing number is too high! Try again");
}
else
{
c.setTextBackgroundColor (Color.MAGENTA);
c.println ("");
c.println ("Congratulations " + name + " !!!");
c.println ("Number of guesses taken: " + guessTaken);
}
[ }
do
{
c.println ("Do you like to play again ? Y/N)");
option = c.readChar ();
if (option != 'y' && option != 'Y' && option != 'N' && option != 'n')
{
c.println ("Invalid option.");
//break;
}
}
while (option != 'y' && option != 'Y' && option != 'N' && option != 'n');
{
if (guessTaken >= highScore )
{
c.println ("Your High Score is: " + highScore + name);
highScore = c.readInt ();
}
}
}
c.println ("Thank you for playing the game !!! ");
c.println ("Have a nice day");/]
This assignment needs to show high score and the name of the high score player.
This is a number guessing game. Thanks !
Question2
Page 1 of 11 Replies - 86 Views - Last Post: 29 November 2012 - 04:24 PM
Replies To: Question2
#2
Re: Question2
Posted 29 November 2012 - 04:24 PM
You already have a thread with the same subject:
http://www.dreaminco...1&#entry1756853
Please avoid double posting
And
http://www.dreaminco...1&#entry1756853
Please avoid double posting
And
Page 1 of 1
|
|

New Topic/Question
This topic is locked



MultiQuote



|