Need help with reseting system. eg New Game Item.

publicclass Game

{

private JTextArea scoreTextArea;

private JFrame scoreFrame;

private Simon simon;

private Player player;

private HighScores highScores;

private GUI gui;

/**

* Constructor for the Game class

*/

private Game()

{

gui =new GUI();

simon =new Simon();

player =new Player();

highScores =new HighScores(true);

}

/**

* The Main method, used to start the program in the JVM

*/

publicstaticvoid main(String[] args)

{

Game game =new Game();

game.play();

}

/**

* Creates the highscore gui.

*/

privatevoid makeHighScoreGui()

{

//Displays a seperate frame for the highscore.

scoreFrame =new JFrame("High Scores");

Container contentPane = scoreFrame.getContentPane();

scoreTextArea =new JTextArea("\n \n \n");

contentPane.add(scoreTextArea);

scoreFrame.pack();

scoreFrame.setVisible(true);

}

/**

* The method called from main

*/

publicvoid play()

{

{

System.out.println("**********************");

System.out.println("NEW GAME OF SIMON SAYS");

System.out.println("**********************");

//main game loop, executes as long as the program runs for

while(true)

{

//simon's turn to say some colors

System.out.println("Simon Says:");

gui.display(simon.say());

//now its the user's turn to repeat Simon

//goes through a loop as it needs to capture multiple characters

for(int i=0; i < simon.getTurn(); i++)

{

gui.changeLabel("color "+ (i+1) +" of " + simon.getTurn() +":");

char charInput = gui.getInput();

//player has got the guess wrong if this branch is entered

if(simon.checkGuess(charInput) ==false)

{

System.out.println("Wrong!");

//the score should be stored if it beats all the other top scores

if(player.getScore() > highScores.getLowestScore())

{

System.out.println("High Score! Enter your name:");

player.setName(gui.getName());

highScores.add(player);

}

//finish the game, save, and exit

System.out.println("GAME OVER!");

makeHighScoreGui();

scoreTextArea.setText("\nHall Of Fame:\n"+ highScores.toString() +"\n");

highScores.saveHighScores();

System.exit(0);

}

// player has got the guess correct if this branch is taken

else

{

//the player got the color correct

System.out.println("Correct!");

}

}

//the player got the whole sequence correct, increase the score

player.incScore();

//send the player's score to the GUI class as a string

gui.setScore(player.getScore() +"");

}

}

}

}

I need to create a method starting a new game.

eg. When you use the method the game starts back at score 0 and simon says different colors.

I tried taking away the game.play from public static void main(String[] args) and putting it in its own method but then the class doesnt work. The new method doesnt start the game.

[5842 byte] By [Gwata] at [2007-10-3 7:44:06]
# 1
Should I give more info?Is it unsolvable?I know Im bumping kind of early but my topic has been pushed to page 2.
Gwata at 2007-7-15 2:45:17 > top of Java-index,Java Essentials,New To Java...
# 2

Write another method that resets everything back to their starting values. Then in the play method have an if statement to decide wether to end the game or not. At the start of the loop call the reset method.

play() {

while true {

reset();

// other code

if user wants to end {

System.exit();

}

}

}

floundera at 2007-7-15 2:45:18 > top of Java-index,Java Essentials,New To Java...