Subversion Repositories sokoban

Rev

Blame | Last modification | View Log | RSS feed

  1. package gdi1sokoban.highscores;
  2.  
  3. /**
  4.  * HighscoreEntry class
  5.  *
  6.  * represents one highscore entry
  7.  */
  8. public class HighscoreEntry {
  9.         private String playerName = ""; // player name
  10.         private int steps = 0; // steps count
  11.         private int time = 0; // time needed
  12.  
  13.         /**
  14.          * gets the value of playerName
  15.          * @return playerName
  16.          */
  17.         protected String getPlayerName() {
  18.                 return playerName;
  19.         }
  20.  
  21.         /**
  22.          * gets the value of steps
  23.          * @return steps
  24.          */
  25.         protected int getSteps() {
  26.                 return steps;
  27.         }
  28.  
  29.         /**
  30.          * gets the value of time
  31.          * @return time
  32.          */
  33.         protected int getTime() {
  34.                 return time;
  35.         }
  36.  
  37.         /**
  38.          * HighscoreEntry constructor
  39.          *
  40.          * @param myLevel game level no.
  41.          * @param myPlayerName player name
  42.          * @param mySteps steps count
  43.          * @param myTime time needed
  44.          * @throws NumberFormatException
  45.          */
  46.         protected HighscoreEntry(final String myPlayerName, final String mySteps, final String myTime) throws NumberFormatException {
  47.                 playerName = myPlayerName;
  48.                 steps = Integer.valueOf(mySteps).intValue();
  49.                 time = Integer.valueOf(myTime).intValue();
  50.         }
  51.        
  52.         /**
  53.          * transforms the highscore entry into string format
  54.          * @return formatted string
  55.          */
  56.         @Override
  57.         public String toString() {
  58.                 // calculate the length of the new string
  59.                 final String hSteps = String.valueOf(steps);
  60.                 final String hTime = String.valueOf(time);
  61.                 final int strLen = playerName.length() + hSteps.length() + hTime.length() + 2;
  62.                 final StringBuffer myBuf = new StringBuffer(strLen);
  63.                 // construct the highscore row string
  64.                 myBuf.append(playerName).append("\t").append(hSteps).append("\t").append(hTime);
  65.                 // return
  66.                 return myBuf.toString();       
  67.         }
  68. }
  69.