Java game save and load




















Asked 8 years, 11 months ago. Active 8 years, 11 months ago. Viewed 3k times. Bryam Ulloa Bryam Ulloa 2 2 gold badges 4 4 silver badges 16 16 bronze badges.

Does new PnlCentro set the vecBody , life to values! I think when I add a new instance its changing all of the values to the original ones, but i dont know how to save it with the new ones. Add a comment. Active Oldest Votes. BryamUlloa Did my answer help? Actually it did help somewhat, the problem was that I needed to create a new instance of the class, because I was working in a separate class for the save and load methods, but whenever I create a instance of the class all my variables reset.

So I just made the save and load methods inside the class im serializing. I read the below article, as I explored the idea of outputting to an XML file. My question is the following: A Doesn't my IDE, upon successful compilation, know how many objects I have, their data type, and what class they belong to? B Is there a way to save ALL objects without specifying them individually. Jaroslaw Pawlak 5, 7 7 gold badges 28 28 silver badges 53 53 bronze badges.

Joseph Erickson Joseph Erickson 3 3 gold badges 7 7 silver badges 23 23 bronze badges. Save and load the program? Save the objects? It's unclear what you are asking about. Do you want to save an object to a file? Perhaps take a look at Serialization — gtgaxiola. Sorry for the ambiguity.

I want to save the game. I want the user to be able to save the game, leave for a day, come back, and load their game where they started, with all objects full intact. You could also use Serializable interface and ObjectOutputStream into bytecode? If you have a collective GameModel class that contains all existing entities that are relevant to the current game state, then you could serialize that one class, and all others would be serialized recursively.

Thanks for all the comments. I guess the answer is, it's absolutely as overwhelming as I thought. Show 8 more comments.

Active Oldest Votes. The compiler doesn't know. Certainly the compiler knows a lot about the types of data. Not really. Company Name : Crunchify. Join the Discussion If you liked this article, then please share it on social media.

Other Popular Articles TemporalAdjusters and Stream. Gson ; import com. This example requires set of Java Packages and the code given below shows those imports:. Here, first, we are creating a Java Properties object called AppProps which will hold application properties Marked as 1.

Once the object is on hand, we are storing three properties by calling its "setProperty " method. The "setProperties " method accepts two strings and forms Key-Value Pair.

Later, the Value can be retrieved by providing the corresponding Key. The two parameters passed to it is "Key and Value" pair. For example, the third property we are adding is " FontSize " and the Size of the font is Here, " FontSize " is the Key Marked as 2 which is passed as First Parameter and 12 is the value for it which is passed as second parameter Marked as 3.

So, in the code snippet, we created three application settings and stored that in a Properties object called AppProps. The application properties contained in the Properties Class instance can be persisted to a text file.

This method takes an OutputStream or Writer object to store the information. Since it accepts OutputStream as well as Writer, in place of a text file, one can write the properties in a binary file as well.

We can persist the information in an XML file also. Persisting Properties to Text File using Store method. This function takes Path to our properties file Marked as 2.

Now, we have our Writer object and Path object are ready. We are making calls to the Store method of the Properties class by supplying the Writer object to it Passed as the first parameter, marked as 3. The comment passed to the store method appears as the first line in the properties file Marked as 1 and there are date and time stamp marked as 2 those tell when the properties are persisted.



0コメント

  • 1000 / 1000