• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Java Reseting alll values in the program

Hi, I am working on this program where at the end of the game I ask the user if they want to play again.  If they say yes, I need to start a new game.  I made a restart()

public void restart(){
            Game g = new Game();
            g.playGame();
      }

However when I call this method some of the values in my program still at what they were during the previous game.

Is there a game to just clear everything and create an new instance of the game with all the default values?
0
ubuntuguy
Asked:
ubuntuguy
3 Solutions
 
brunoguimaraesCommented:
Where are you storing these values? You should put them as attributes for the Game class (but not static).
0
 
MMierzwaCommented:
It is hard to say but that variables that stay at their previous values are not just static to class?
0
 
HalfAsleepCommented:
The reason we ask this, is because the static variables "follow" the class, and not the instantiated objects.

A static class variable will not change as you create instances of the class.
0
 
ubuntuguyAuthor Commented:
Hi sorry I was making a mistake.... I was calling the reset method not the restart one... lol.. sorry.... although I learned something about static variables  in this thread that i didnt know
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now