<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -15,7 +15,7 @@ try {
     exit;
 }
 
-$q = 'SELECT clear, name, score FROM `scores` ORDER BY `score` DESC';
+$q = 'SELECT name, score, clear FROM `scores` ORDER BY `score` DESC';
 
 if (isset($num_scores)) {
 	$num_scores = intval($num_scores);</diff>
      <filename>script/board.php</filename>
    </modified>
    <modified>
      <diff>@@ -1,15 +1,12 @@
 package com.shade.score;
 
 import java.io.BufferedReader;
-import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
-import java.util.Scanner;
-
-import org.newdawn.slick.util.ResourceLoader;
+import java.util.prefs.Preferences;
 
 /**
  * Post all of the scores in a csv file to a server.
@@ -18,14 +15,10 @@ import org.newdawn.slick.util.ResourceLoader;
  */
 public class BatchWriter {
     
-    private static final String NEWLINE = &quot;\n&quot;;
+    private static final String EMPTY_STRING = &quot;&quot;;
+    private static final String SCORE_KEY = &quot;scores&quot;;
     private static final String SERVER = &quot;http://anotherearlymorning.com/games/shade/batch.php&quot;;
-    
-    private String path;
-
-    public BatchWriter(String path) {
-        this.path = path;
-    }
+   
     
     public boolean write() {
         try {
@@ -45,24 +38,13 @@ public class BatchWriter {
                     .getInputStream()));
             String response = i.readLine();
             return response.equals(&quot;success&quot;);
-
         } catch (Exception e) {
             return false;
         }
     }
 
     private String collectScores() {
-        StringBuilder builder = new StringBuilder();
-        Scanner reader = getScanner();
-        while (reader.hasNextLine()) {
-            builder.append(reader.nextLine());
-            builder.append(NEWLINE);
-        }
-        return builder.toString();
-    }
-
-    private Scanner getScanner() {
-        InputStream stream = ResourceLoader.getResourceAsStream(path);
-        return new Scanner(stream);
+        Preferences prefs = Preferences.systemNodeForPackage(this.getClass());
+        return prefs.get(SCORE_KEY, EMPTY_STRING);
     }
 }</diff>
      <filename>src/com/shade/score/BatchWriter.java</filename>
    </modified>
    <modified>
      <diff>@@ -8,14 +8,13 @@ package com.shade.score;
  */
 public class FailSafeHighScoreReader implements HighScoreReader {
 
-    private static final String FILE = &quot;states/highscore/scores.csv&quot;;
     private static final String SERVER = &quot;http://anotherearlymorning.com/games/shade/board.php&quot;;
     
     private LocalHighScoreReader localReader;
     private RemoteHighScoreReader remoteReader;
 
     public FailSafeHighScoreReader() {
-        localReader = new LocalHighScoreReader(FILE);
+        localReader = new LocalHighScoreReader();
         remoteReader = new RemoteHighScoreReader(SERVER);
     }
 </diff>
      <filename>src/com/shade/score/FailSafeHighScoreReader.java</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,6 @@
 package com.shade.score;
 
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.URL;
-
-import org.newdawn.slick.util.ResourceLoader;
+import java.util.prefs.Preferences;
 
 /**
  * Write high scores to a remote server or locally if you cannot connect to the
@@ -20,7 +16,8 @@ import org.newdawn.slick.util.ResourceLoader;
  */
 public class FailSafeHighScoreWriter implements HighScoreWriter {
 
-    private static final String FILE = &quot;states/highscore/scores.csv&quot;;
+    private static final String EMPTY_STRING = &quot;&quot;;
+    private static final String SCORE_KEY = &quot;scores&quot;;
     private static final String SERVER = &quot;http://anotherearlymorning.com/games/shade/post.php&quot;;
 
     private LocalHighScoreWriter localWriter;
@@ -28,9 +25,9 @@ public class FailSafeHighScoreWriter implements HighScoreWriter {
     private BatchWriter batchWriter;
 
     public FailSafeHighScoreWriter() {
-        localWriter = new LocalHighScoreWriter(FILE);
+        localWriter = new LocalHighScoreWriter();
         remoteWriter = new RemoteHighScoreWriter(SERVER);
-        batchWriter = new BatchWriter(FILE);
+        batchWriter = new BatchWriter();
     }
 
     public boolean write(String name, int score, boolean clear) {
@@ -39,7 +36,7 @@ public class FailSafeHighScoreWriter implements HighScoreWriter {
             // try to write past local scores to server
             if (batchWriter.write()) {
                 // clear the file
-                clearFile(FILE);
+                Preferences.systemNodeForPackage(this.getClass()).put(SCORE_KEY, EMPTY_STRING);
             }
             // else do nothing, they will get written later
         } else {
@@ -50,14 +47,4 @@ public class FailSafeHighScoreWriter implements HighScoreWriter {
         return true;
     }
 
-    private void clearFile(String f) {
-        try {
-            URL u = ResourceLoader.getResource(f);
-            FileWriter w = new FileWriter(u.getPath());
-            w.flush();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-
 }</diff>
      <filename>src/com/shade/score/FailSafeHighScoreWriter.java</filename>
    </modified>
    <modified>
      <diff>@@ -1,13 +1,11 @@
 package com.shade.score;
 
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.StringReader;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.LinkedList;
-
-import org.newdawn.slick.util.ResourceLoader;
+import java.util.prefs.Preferences;
 
 import com.shade.util.CsvReader;
 
@@ -20,22 +18,20 @@ import com.shade.util.CsvReader;
  */
 public class LocalHighScoreReader implements HighScoreReader {
 
+    private static final String EMPTY_STRING = &quot;&quot;;
+    private static final String SCORE_KEY = &quot;scores&quot;;
+    
     private static final int NAME = 0;
     private static final int SCORE = 1;
     private static final int CLEAR = 2;
-    
-    private CsvReader reader;
-
-    public LocalHighScoreReader(String path) {
-        InputStream stream = ResourceLoader.getResourceAsStream(path);
-        InputStreamReader input = new InputStreamReader(stream);
-        reader = new CsvReader(input);
-    }
 
     /**
      * Returns all the scores if zero is passed.
      */
     public String[][] getScores(int limit) {
+        Preferences prefs = Preferences.systemNodeForPackage(this.getClass());
+        StringReader s = new StringReader(prefs.get(SCORE_KEY, EMPTY_STRING));
+        CsvReader reader = new CsvReader(s);
         LinkedList&lt;String[]&gt; rows = new LinkedList&lt;String[]&gt;();
         try {
             while (reader.readRecord()) {
@@ -52,7 +48,7 @@ public class LocalHighScoreReader implements HighScoreReader {
         Collections.sort(rows, new Comparator&lt;String[]&gt;() {
 
             public int compare(String[] s1, String[] s2) {
-                return s1[SCORE].compareTo(s2[SCORE]);
+                return s2[SCORE].compareTo(s1[SCORE]);
             }
             
         });</diff>
      <filename>src/com/shade/score/LocalHighScoreReader.java</filename>
    </modified>
    <modified>
      <diff>@@ -1,45 +1,41 @@
 package com.shade.score;
 
-import java.io.FileWriter;
 import java.io.IOException;
-import java.net.URL;
-
-import org.newdawn.slick.util.ResourceLoader;
+import java.io.StringWriter;
+import java.util.prefs.Preferences;
 
 import com.shade.util.CsvWriter;
 
 public class LocalHighScoreWriter implements HighScoreWriter {
 
+    private static final String EMPTY_STRING = &quot;&quot;;
+    private static final String SCORE_KEY = &quot;scores&quot;;
+    
     private static final int NAME = 0;
     private static final int SCORE = 1;
     private static final int CLEAR = 2;
     
     private static final char COMMA = ',';
-    private CsvWriter writer;
-
-    public LocalHighScoreWriter(String path) {
-        try {
-            URL url = ResourceLoader.getResource(path);
-            FileWriter stream = new FileWriter(url.getPath(), true);
-            writer = new CsvWriter(stream, COMMA);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
 
     public boolean write(String name, int score, boolean clear) {
         String[] row = new String[3];
         row[NAME] = name;
-        row[SCORE] = score + &quot;&quot;;
+        row[SCORE] = score + EMPTY_STRING;
         row[CLEAR] = (clear) ? &quot;1&quot; : &quot;0&quot;;
         return write(row[NAME], row[SCORE], row[CLEAR]);
     }
     
     protected boolean write(String name, String score, String clear) {
+        Preferences prefs = Preferences.systemNodeForPackage(this.getClass());
+        StringWriter stream = new StringWriter();
+        CsvWriter writer = new CsvWriter(stream, COMMA);
         String[] row = new String[] { name, score, clear };
         try {
             writer.writeRecord(row);
-            writer.flush();
+//            writer.flush();
+            
+            stream.append(prefs.get(SCORE_KEY, EMPTY_STRING));
+            prefs.put(SCORE_KEY, stream.toString());
         } catch (IOException e) {
             return false;
         }</diff>
      <filename>src/com/shade/score/LocalHighScoreWriter.java</filename>
    </modified>
    <modified>
      <diff>@@ -154,11 +154,11 @@ public class HighscoreState extends BasicGameState {
         int y = 100;
         int n = 0;
         for (String[] s : scoress) {
-            if (s[0].equals(&quot;1&quot;)) {
+            if (s[2].equals(&quot;1&quot;)) {
                 crowns.add(new FadeInImage(resource.get(&quot;crown&quot;), x, y + 3 + (40 * n), 1000 + 400 *n));
             }
-            scores.add(new FadeInText(s[1], master.jekyllLarge, x + 50, y + (40 * n), 1000 + 400 * n));
-            scores.add(new FadeInText(s[2], master.jekyllLarge, x + 300, y + (40 * n), 1000 + 400 * n));
+            scores.add(new FadeInText(s[0], master.jekyllLarge, x + 50, y + (40 * n), 1000 + 400 * n));
+            scores.add(new FadeInText(s[1], master.jekyllLarge, x + 300, y + (40 * n), 1000 + 400 * n));
             n++;
         }
     }</diff>
      <filename>src/com/shade/states/HighscoreState.java</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>res/states/highscore/scores.csv</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>379dc57f55e910b68de9ab9dd495d90ebed018df</id>
    </parent>
  </parents>
  <author>
    <name>Alex Schearer</name>
    <email>aschearer@gmail.com</email>
  </author>
  <url>http://github.com/aschearer/shade/commit/d43e3a8c5285ce739f37dac23153366660823774</url>
  <id>d43e3a8c5285ce739f37dac23153366660823774</id>
  <committed-date>2008-12-30T22:49:47-08:00</committed-date>
  <authored-date>2008-12-30T22:49:47-08:00</authored-date>
  <message>fixing issues with failsafe score, it now works correctly.</message>
  <tree>a1ec294c3d1f4921f9eeccb498ed7313b32b2709</tree>
  <committer>
    <name>Alex Schearer</name>
    <email>aschearer@gmail.com</email>
  </committer>
</commit>
