import java.awt.*;
import java.applet.*;

public class Scorelist {
   String[] name = new String[10];
   int[] level=new int[10];
   int[] score=new int[10];
/* Highscore file commented out since this IS current only an applet */
/*   FILE *Scorelist::open_file(char *mode) {
 *    char file[255];
 *    sprintf (file, "%sscores", XBILL_HOME);
 *    return fopen (file, mode);
 * }
 * 
 * void Scorelist::read() {
 *    FILE *scorefile = open_file("r");
 *    int i;
 *     if (scorefile) {
 *	 for (i=0; i<10; i++) {
 *    fgets (name[i], 21, scorefile);
 *    fscanf (scorefile, "%d%d\n", &(level[i]), &(score[i]));
 * }
 * fclose(scorefile);
 *     }
 *     else
 * for (i=0; i<10; i++) {
 *	   strcpy(name[i], "me");
 *	   level[i] = score[i] = 0;
 *	}
 *  }
 *  
 *  void Scorelist::write() {
 *     int i, j;
 *     FILE *scorefile = open_file("w");
 *     if (!scorefile) return;
 *     for (i=0; i<10; i++) {
 *	 fputs(name[i], scorefile);
 *	 for (j=strlen(name[i]); j<25; j++)
 *	   fputc(' ', scorefile);
 *	 fprintf (scorefile, " %d %d\n", level[i], score[i]);
 *     }
 *     fclose(scorefile);
 *  }
 */  
   JBill2 game;
   public Scorelist(JBill2 a) { 
      game=a;
   }
  void read() { // Temporary until it reads a real file.
     for (int i=0; i<10; i++) {
	name[i]= "me";
	level[i] = score[i] = 0;
     }
  }
   /*  Add new high score to list   */
   void recalc (String str) {
      int i;
      if (score[9] >= game.score) return;
      for (i=9; i>0; i--) {
	 if (score[i-1] < game.score) {
	    name[i]= name[i-1];
	    level[i] = level[i-1];
	    score[i] = score[i-1];
	 }
	 else break;
      }
      name[i]= str;
      level[i] = game.level;
      score[i] = game.score;
   }
   
   void update() {
      int i, j;
      String str = "High Scores:\n\n";
      str += "Name                 Level    Score\n";
      for (i=0; i<10; i++) {
	 str += name[i];
	 for (j=name[i].length(); j<21; j++) str +=  " ";
	 str += level[i]+"  "+score[i]+"\n";
      }
//      game.ui.update_hsbox(str);
   }
   
}
