Android Open Source - numbers-game Level5 Factory

From Project

Back to project page numbers-game.


The source code is released under:

GNU General Public License

If you think the Android project numbers-game listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ngame.factories;
/*from  w w w.  jav a  2  s. co  m*/
import java.util.ArrayList;
import java.util.LinkedList;

import android.content.Context;
import android.util.Log;

import com.ngame.models.Level;
import com.ngame.utils.EndOfLevelException;

 * Class used to load levels marked with difficulty 5
 * @author Gorjan
public class Level5Factory extends LevelFactory {

  private static final String TAG = "Level5Factory";

  private ArrayList<Level> levels;
  private Context ctx;

  public Level5Factory(Context c) {
    ctx = c;
    Level newLvl;
    levels = new ArrayList<>();
    try {
      InputStream is = ctx.getResources().getAssets()
      BufferedReader reader = new BufferedReader(
          new InputStreamReader(is));

      String row = reader.readLine();

      while (row != null) {

        if (row.equalsIgnoreCase("extra"))
        String[] nums = row.split(":");
        LinkedList<String> steps = new LinkedList<>();
        for (int i = 3; i < nums.length; i++) {
        newLvl = new Level(nums[0], nums[1], steps);

        row = reader.readLine();
    } catch (Exception e) {
      Log.e(TAG, "Error in reading levels from level5.txt");

  public Level getLevel(int i) throws EndOfLevelException {
    Level returnLevel = null;
    try {
      returnLevel = levels.get(i);
    } catch (IndexOutOfBoundsException e) {
      throw new EndOfLevelException("level with index:" + i + "asked");
    return returnLevel;


Java Source Code List