private boolean isArchive() { archiveRow = m_game_state.checkRow(); archiveCol = m_game_state.checkCol(); cross_down = m_game_state.checkCrossDown(); cross_up = m_game_state.checkCrossUp(); return ((!archiveRow.isEmpty()) || (!archiveCol.isEmpty()) || cross_down || cross_up); }
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); }
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()); } }
public void levelChange() { initSize(); m_progress_bar.setTotalTime(Constant.TOTAL_TIME); _score.setLevel(_level); _score.reset(); removeList.clear(); m_game_state.setSize(grid_size); createGame(); NumSprite.istouchable = true; m_progress_bar.resume(); }
public void removeMap() { for (int i = 0; i < grid_size; i++) for (int j = 0; j < grid_size; j++) { Point p = m_game_state.getPxPy(i, j); if (_map.containsKey(p)) { NumSprite sprite = _map.get(p); sprite.destroy(); _map.remove(p); } } }
public void onTouchMovable(NumSprite sprite) { NumSprite.istouchable = false; Point p0 = m_game_state.getZeroPxPy(); Point p1 = new Point(); p1.set(sprite.getPx(), sprite.getPy()); // toogle 2 sprite toogle(p0, p1); // update game_state updateGameState(sprite); // m_game_state.showMatrix2D(); // Check if archive target if (isArchive()) { if (sound_on) m_resource_manager.sound.playArchive(); m_progress_bar.pause(); processArchivement(); } else { NumSprite.istouchable = true; } return; }
private void processArchivement() { // TODO Auto-generated method stub if (!archiveRow.isEmpty()) { for (int i = 0; i < archiveRow.size(); i++) { // remove row from hash for (int j = 0; j < grid_size; j++) { Point p = m_game_state.getPxPy(archiveRow.get(i), j); NumSprite sprite = _map.get(p); sprite.rotateSprite(); _map.remove(p); removeList.add(m_game_state.getMatrix()[archiveRow.get(i)][j]); } m_game_state.removeRow(archiveRow.get(i)); _score.addScore(1); } } if (!archiveCol.isEmpty()) { for (int i = 0; i < archiveCol.size(); i++) { // remove col from hash for (int j = 0; j < grid_size; j++) { Point p = m_game_state.getPxPy(j, archiveCol.get(i)); NumSprite sprite = _map.get(p); sprite.rotateSprite(); _map.remove(p); removeList.add(m_game_state.getMatrix()[j][archiveCol.get(i)]); } m_game_state.removeCol(archiveCol.get(i)); _score.addScore(1); } } if (cross_down) { // remove item for (int j = 0; j < grid_size; j++) for (int i = 0; i < grid_size; i++) { if (i + j == grid_size - 1) { Point p = m_game_state.getPxPy(i, j); NumSprite sprite = _map.get(p); sprite.rotateSprite(); _map.remove(p); removeList.add(m_game_state.getMatrix()[i][j]); } } m_game_state.removeCrossDown(); _score.addScore(2); } if (cross_up) { // remove item for (int j = 0; j < grid_size; j++) for (int i = 0; i < grid_size; i++) { if (i == j) { Point p = m_game_state.getPxPy(i, j); NumSprite sprite = _map.get(p); sprite.rotateSprite(); _map.remove(p); removeList.add(m_game_state.getMatrix()[i][j]); } } m_game_state.removeCrossUp(); _score.addScore(2); } boolean wait = false; new Thread( new Runnable() { public void run() { /* Do things */ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } /* Wait 1000 milliseconds */ fillGameState(); m_progress_bar.resume(); } }) .start(); }