Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Scoreboard / Leaderboard: How do you manage them?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 tom_mai78101   Members   -  Reputation: 577

Like
0Likes
Like

Posted 23 September 2012 - 04:26 AM

Currently, I have something like this planned out:

Posted Image

A Scoreboard object consists of many Formats. Each Format object means a record of a player's session. There are many players playing, and once they are done playing, each of their sessions is recorded into a Format object, stored into a binary file somewhere, and can be compared with other Formats. The Scoreboard object, when invoked, will gather up all currently recorded Format sessions from one binary file, and gives a simple list of the Formats in an orderly fashion.

I wanted to store many of these Formats into 1 binary file. So, here's what I have in mind:

[source lang="java"]package test;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.util.ArrayList;import java.util.List;import java.util.Random;public class Scoreboard { public static List<Format> formats = new ArrayList<Format>(); public static void main(String arg[]) { make(); retrieve(); } public static void make() { Random r = new Random(); for (int i = 0; i < r.nextInt(4) + 1; i++) { Format f = new Format(); f.position = r.nextInt(10); f.name = r.toString(); f.score = r.nextLong(); formats.add(f); } try { FileOutputStream out = new FileOutputStream(new File("format.txt")); ObjectOutputStream output = new ObjectOutputStream(new BufferedOutputStream(out)); output.writeObject(formats); output.flush(); output.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } formats.clear(); } public static void retrieve() { FileInputStream in; try { in = new FileInputStream(new File("format.txt")); ObjectInputStream input = new ObjectInputStream(new BufferedInputStream(in)); formats = (ArrayList<Format>) input.readObject(); input.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } System.out.println("Clear!"); }}[/source]

And the Format object:

[source lang="java"]package test;import java.io.Serializable;public class Format implements Serializable { private static final long serialVersionUID = 1L; public int position; public String name; public long score;}[/source]

But there is a problem. And it's a big flaw. How does one simply manage the Formats, by recording and saving them at arbitary times, and from the Scoreboard, you can invoke it to list out the Formats at arbitary times? This is something I haven't come up with yet. Probably going to need some hints on this.

It's something that I wanted to do on an Android smartphone, but I guess Java is fine anyway.

Sponsor:

#2 tom_mai78101   Members   -  Reputation: 577

Like
0Likes
Like

Posted 23 September 2012 - 05:55 AM

Update:

I was just thinking a little bit more when I thought, why not just put the ArrayList<Format> inside the Format class object?

[source lang="java"]public class Format implements Serializable { private static final long serialVersionUID = 1L; List<Format> formats = new ArrayList<Format>(); public int position; public String name; public long score;}[/source]
It would seems it might be the key to solving this solution: A temporary place to store a session in, and a permanent place to store lots of older sessions in an array. So, that way, when I save it, the file will consist mainly of a temporary cache session, and a large chunk of permanent data. When I read it back, it will read all of them together, and I could omit the temporary cached session and continue to do some processing.

Seems about right...




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS