Example #1
0
  public void toogle(Point p1, Point p2) {
    // Save position
    int x1 = p1.x;
    int y1 = p1.y;
    int x2 = p2.x;
    int y2 = p2.y;

    NumSprite sp1 = _map.get(p1);
    NumSprite sp2 = _map.get(p2);
    int id1 = sp1.getResourceID();
    int id2 = sp2.getResourceID();
    Point p3 = sp1.getMatrixPosition();
    Point p4 = sp2.getMatrixPosition();
    // remove 2 sprite
    if (_map.containsKey(p1)) _map.remove(p1);
    if (_map.containsKey(p2)) _map.remove(p2);
    sp1.destroy();
    sp2.destroy();
    // Create 2 new sprite
    NumSprite sp1_new = new NumSprite(x1, y1, id2);
    NumSprite sp2_new = new NumSprite(x2, y2, id1);
    sp1_new.setMatrixPosition(p3.x, p3.y);
    sp2_new.setMatrixPosition(p4.x, p4.y);
    _map.put(p1, sp1_new);
    _map.put(p2, sp2_new);
    if (sound_on) m_resource_manager.sound.playSlide();
  }
Example #2
0
  public void fillGameState() {
    int value;
    ArrayList<Integer> list = new ArrayList<Integer>(removeList.size());

    while (!removeList.isEmpty()) {
      list.add(removeList.remove((int) (Math.random() * removeList.size())));
      //			Log.i(Constant.TAG, String.valueOf(list));

      if (removeList.isEmpty() && Util.checkContinuous(list)) {
        removeList.addAll(list);
        list.clear();
      }
    }
    //		Log.i(Constant.TAG, String.valueOf(list));
    int[][] matrix = m_game_state.getMatrix();
    for (int i = 0; i < grid_size; i++)
      for (int j = 0; j < grid_size; j++) {
        if (matrix[i][j] == -1) {
          value = list.remove(0);
          //					Log.i(Constant.TAG, String.valueOf(value));
          matrix[i][j] = value;
          Point p = m_game_state.getPxPy(i, j);
          NumSprite sprite = new NumSprite(p.x, p.y, value);
          sprite.setMatrixPosition(i, j);
          _map.put(p, sprite);
        }
      }
    m_game_state.setMatrix(matrix);
    NumSprite.istouchable = true;
  }
Example #3
0
  private void createGame() {
    Point p;

    // Create random matrix
    m_game_state.createRandomMatrix();
    //	m_game_state.showMatrix2D();

    // Create NumItem & add to Hash table
    try {
      for (int i = 0; i < grid_size; i++)
        for (int j = 0; j < grid_size; j++) {
          p = m_game_state.getPxPy(i, j);
          NumSprite item = new NumSprite(p.x, p.y, m_game_state.getMatrix()[i][j]);
          item.setMatrixPosition(i, j);
          _map.put(p, item);
        }
      NumSprite.m_game_state = m_game_state;
    } catch (Exception e) {
      Log.i(Constant.TAG, e.toString());
    }
  }