This site requires JavaScript, please enable it in your browser!
Greenfoot back
Weeb.exe
Weeb.exe wrote ...

2020/4/27

how to create save games with greenfoot

1
2
Weeb.exe Weeb.exe

2020/4/27

#
Ok so if i wanted create a save file for a game so that way if you reset it you can still continue (like with popular games) is there a possible way to do this with greenfoot or is this impossible?
danpost danpost

2020/4/27

#
Weeb.exe wrote...
Ok so if i wanted create a save file for a game so that way if you reset it you can still continue (like with popular games) is there a possible way to do this with greenfoot or is this impossible?
Do you intend to make an executable jar file from this project or is it only to be run in greenfoot (application and website)?
Weeb.exe Weeb.exe

2020/4/28

#
greenfoot
danpost danpost

2020/4/28

#
Weeb.exe wrote...
greenfoot
You can use the ScoreBoard class provided by greenfoot; but, only for one-player games.
Weeb.exe Weeb.exe

2020/4/28

#
oh ok
danpost danpost

2020/4/28

#
Weeb.exe wrote...
oh ok
You will need to find the best way to squeeze what information you want saved into the limited amount of storage per user.
Weeb.exe Weeb.exe

2020/4/28

#
ok is there anyway to do this like saving it to a different file like a txt?
danpost danpost

2020/4/28

#
Weeb.exe wrote...
ok is there anyway to do this like saving it to a different file like a txt?
There is a way; however, it will only work locally as a stand-alone or in the greenfoot application. It will not work on the site.
Weeb.exe Weeb.exe

2020/4/28

#
that's ok im not planning on posting it here this is for an assignment
danpost danpost

2020/4/28

#
In general, you would create a FileReader or FileWriter object:
1
FileReader file = new FileReader("gameState.txt"); // or FileWriter
Then you would create a BufferedReader (or BufferedWriter) object to wrap it in:
1
BufferedReader br = new BufferedReader(file);
Please refer to the class APIs of each (in thejava.io package). Here is a link to the The Java API documentation It is critical that the wrapper (br or bw) is closed as soon as possible. When reading, open and read everything directly into an array and close it. Then deal with what was read. When writing, prepare everything to be written first, then open, write everything and close it. try-catch blocks will be required for the file operations.
Weeb.exe Weeb.exe

2020/4/28

#
where is the general do i just create a general class?
danpost danpost

2020/4/28

#
Weeb.exe wrote...
where is the general do i just create a general class?
Definition: "in general" -- usually; in most cases.
Weeb.exe Weeb.exe

2020/4/28

#
ok but where do i place this code?
danpost danpost

2020/4/28

#
Weeb.exe wrote...
ok but where do i place this code?
Presumably, for writing, at the place where you leave the game unfinished, but want to recall it later; and, for reading, at the place where it is determined that you want to recall it.
Weeb.exe Weeb.exe

2020/4/28

#
do i need to place this in every class?
There are more replies on the next page.
1
2