Android Open Source - numbers-game Level3 Factory






From Project

Back to project page numbers-game.

License

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;
//w  w  w .  j  a va  2s.  c  o  m
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
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 3
 * @author Gorjan
 *
 */
public class Level3Factory extends LevelFactory {

  private static final String TAG = "Level3Factory";

  private ArrayList<Level> levels;
  private Context ctx;

  public Level3Factory(Context c) {
    ctx = c;
    Level newLvl;
    levels = new ArrayList<>();
    try {
      InputStream is = ctx.getResources().getAssets()
          .open("levels/level3.txt");
      BufferedReader reader = new BufferedReader(
          new InputStreamReader(is));

      String row = reader.readLine();

      while (row != null) {

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

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

  @Override
  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

com.ngame.activities.AboutActivity.java
com.ngame.activities.ClassicModeActivity.java
com.ngame.activities.StartUpActivity.java
com.ngame.activities.TimeBattleModeActivity.java
com.ngame.factories.Level1Factory.java
com.ngame.factories.Level2Factory.java
com.ngame.factories.Level3Factory.java
com.ngame.factories.Level4Factory.java
com.ngame.factories.Level5Factory.java
com.ngame.factories.LevelFactory.java
com.ngame.factories.TimerLevelsFactory.java
com.ngame.models.Level.java
com.ngame.utils.EndOfLevelException.java
com.ngame.utils.OnSwipeTouchListener.java