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; }
public void updateGameState(NumSprite sprite) { Point p3 = sprite.getMatrixPosition(); Point p4 = m_game_state.getZeroXY(); int[][] matrix = m_game_state.getMatrix(); int i = matrix[p3.x][p3.y]; matrix[p3.x][p3.y] = 0; matrix[p4.x][p4.y] = i; m_game_state.setMatrix(matrix); }