Game Development Reference
In-Depth Information
// :/ It's ok, defaults save our day
}
finally
{
try
{
if
(in !=
null
)
in.close();
}
catch
(IOException e) {
}
}
}
public static void
save(FileIO files) {
BufferedWriter out =
null
;
try
{
out =
new
BufferedWriter(
new
OutputStreamWriter(
files.writeFile(
file
)));
out.write(Boolean.
toString
(
soundEnabled
));
out.write("\n");
for
(
int
i = 0; i < 5; i++) {
out.write(Integer.
toString
(
highscores[i]
[i]));
out.write("\n");
}
}
catch
(IOException e) {
}
finally
{
try
{
if
(out !=
null
)
out.close();
}
catch
(IOException e) {
}
}
}
public static void
addScore(
int
score) {
for
(
int
i=0; i < 5; i++) {
if
(
highscores[i]
[i] < score) {
for
(
int
j= 4; j > i; j--)
highscores[i]
[j] =
highscores[i]
[j-1];
highscores[i]
[i] = score;
break
;
}
}
}
}
The only difference from the Mr. Nom version of this class is the file from and to which we read
and write the settings. Instead of
.mrnom
, we now use the file
.superjumper
.
The Main Activity
We need an
Activity
as the main entry point of our game. We'll call it
SuperJumper
. Listing 9-3
shows its code.