Android Open Source - numbers-game Level






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.models;
import java.util.Collections;
import java.util.LinkedList;
//from w ww .  j a v a  2s.  c o m
/**
 * Class model for one level of the game
 * @author Gorjan
 *
 */
public class Level {

  private String gameNum;
  private String targetNum;
  private LinkedList<String> steps;
  private int minMoves;
  
  /**
   * @param gameNumber the starting number of the level
   * @param targetNumber the target number of the level
   */
  public Level(String gameNumber, String targetNumber, LinkedList<String> steps) {
    gameNum = gameNumber;
    targetNum = targetNumber;
    this.steps = steps;
    minMoves = steps.size();
  }

  public LinkedList<String> getSolutionSteps(){
    return steps;
  }
  
  public int getMinMoves(){
    return minMoves;
  }
  
  public String getGameNum(){
    return gameNum;
  }
  
  public String getTargetNum(){
    return targetNum;
  }
  
  public String getSolution(){
    Collections.reverse(steps);
    StringBuilder sb = new StringBuilder();
    for (String step : steps) {
      sb.append(step + " -> ");
    }
    sb.append(targetNum);
    return sb.toString();
  }

  @Override
  public boolean equals(Object obj) {
    if(obj.getClass()!= Level.class)
      return false;
    Level l2 = (Level) obj;
    if(!gameNum.equals(l2.gameNum) || !targetNum.equals(l2.targetNum))
      return false;
    return true;
  }

  @Override
  public String toString() {
    return "Starting number: " + gameNum + " Target number: " + targetNum + " solved in " + minMoves + " steps: " + getSolution(); 
  }
  
}




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