Advertisement
Evyatar12

kal

Jun 16th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. package project.game.levels.io.levelsets;
  2.  
  3. import java.io.IOException;
  4. import java.io.LineNumberReader;
  5. import java.util.List;
  6.  
  7. import project.game.levels.LevelInformation;
  8. import project.game.levels.io.levels.LevelSpecificationReader;
  9. import project.misc.Utils;
  10.  
  11. /**
  12.  * {@link LevelSet} is a set of levels.
  13.  */
  14. public class LevelSet {
  15.  
  16.     private LevelSpecificationReader lsr = new LevelSpecificationReader();
  17.  
  18.     private String desc;
  19.     private String key;
  20.     private List<LevelInformation> lvls;
  21.  
  22.     /**
  23.      * Set the levels file for this set.
  24.      * @param levels : the levels
  25.      */
  26.     public void setLevelsFile(String levels) {
  27.         this.lvls = this.lsr.fromReader(Utils.getResourceReader(levels));
  28.     }
  29.  
  30.     /**
  31.      * Get the levels.
  32.      * @return the levels
  33.      */
  34.     public List<LevelInformation> getLevels() {
  35.         return this.lvls;
  36.     }
  37.  
  38.     /**
  39.      * Get the description of the set.
  40.      * @return the description
  41.      */
  42.     public String getDescription() {
  43.         return this.desc;
  44.     }
  45.  
  46.     /**
  47.      * Set the description for this set.
  48.      * @param s : the description
  49.      */
  50.     public void setDescription(String s) {
  51.         this.desc = s;
  52.     }
  53.  
  54.     /**
  55.      * Get the key used to run this set.
  56.      * @return the key
  57.      */
  58.     public String getKey() {
  59.         return this.key;
  60.     }
  61.  
  62.     /**
  63.      * Set the key used to run this set.
  64.      * @param k : the key
  65.      */
  66.     public void setKey(String k) {
  67.         this.key = k;
  68.     }
  69.  
  70.     /**
  71.      * Construct a new level set from a given {@link LineNumberReader}.
  72.      * @param lnr : the reader
  73.      * @return a new {@link LevelSet} instance
  74.      */
  75.     public static LevelSet fromReader(LineNumberReader lnr) {
  76.         try {
  77.             LevelSet ls = new LevelSet();
  78.  
  79.             // if this is not the first line
  80.             if (lnr.getLineNumber() % 2 == 1) {
  81.                 lnr.readLine();
  82.             }
  83.  
  84.             String[] splitLine = lnr.readLine().split(":");
  85.  
  86.             ls.setKey(splitLine[0]);
  87.             ls.setDescription(splitLine[1]);
  88.  
  89.             ls.setLevelsFile(lnr.readLine());
  90.  
  91.             return ls;
  92.         } catch (IOException e) {
  93.             e.printStackTrace();
  94.             return null;
  95.         }
  96.  
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement