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.

