private void checkVertical(int row, int col){ // The current id of the tile that we are checking for matches final Tileint tilecurrentId = tiles[row][col];tiles[row][col].getId(); // The matches of the current tile final List<Tile> matchedTiles = new ArrayList<Tile>(); matchedTiles.add(tiles[row][col]); if(row < 7 && tiles[row + 1][col].getId() == tiles[row][col].getId()currentId){ // 1 up matchedTiles.add(tiles[row + 1][col]); if(row < 6 && tiles[row + 2][col].getId() == tiles[row][col].getId()currentId) // 2 up matchedTiles.add(tiles[row + 2][col]); } if(row > 0 && tiles[row - 1][col].getId() == tiles[row][col].getId()currentId) { // 1 down matchedTiles.add(tiles[row - 1][col]); if(row > 1 && tiles[row - 2][col].getId() == tiles[row][col].getId()currentId) // 2 down matchedTiles.add(tiles[row - 2][col]); } // If we find a match if(matchedTiles.size >= 23) { for(Tile tile : matchedTiles) { final int row = tile.getRow(); final int col = tile.getCol(); tiles[row][col].setId(8); } } } private void checkVertical(int row, int col){ // The current tile we are checking for matches final Tile tile = tiles[row][col]; // The matches of the current tile final List<Tile> matchedTiles = new ArrayList<Tile>(); if(row < 7 && tiles[row + 1][col].getId() == tiles[row][col].getId()){ // 1 up matchedTiles.add(tiles[row + 1][col]); if(row < 6 && tiles[row + 2][col].getId() == tiles[row][col].getId()) // 2 up matchedTiles.add(tiles[row + 2][col]); } if(row > 0 && tiles[row - 1][col].getId() == tiles[row][col].getId()) { // 1 down matchedTiles.add(tiles[row - 1][col]); if(row > 1 && tiles[row - 2][col].getId() == tiles[row][col].getId()) // 2 down matchedTiles.add(tiles[row - 2][col]); } // If we find a match if(matchedTiles.size >= 2) { for(Tile tile : matchedTiles) { final int row = tile.getRow(); final int col = tile.getCol(); tiles[row][col].setId(8); } } } private void checkVertical(int row, int col){ // The current id of the tile that we are checking for matches final int currentId = tiles[row][col].getId(); // The matches of the current tile final List<Tile> matchedTiles = new ArrayList<Tile>(); matchedTiles.add(tiles[row][col]); if(row < 7 && tiles[row + 1][col].getId() == currentId){ // 1 up matchedTiles.add(tiles[row + 1][col]); if(row < 6 && tiles[row + 2][col].getId() == currentId) // 2 up matchedTiles.add(tiles[row + 2][col]); } if(row > 0 && tiles[row - 1][col].getId() == currentId) { // 1 down matchedTiles.add(tiles[row - 1][col]); if(row > 1 && tiles[row - 2][col].getId() == currentId) // 2 down matchedTiles.add(tiles[row - 2][col]); } // If we find a match if(matchedTiles.size >= 3) { for(Tile tile : matchedTiles) { final int row = tile.getRow(); final int col = tile.getCol(); tiles[row][col].setId(8); } } } private Array<Tile> matchedTiles = new Array<Tile>(); //... private void checkVertical(int row, int col){ // The current tile we are checking for matches final Tile toChecktile = array[row][col];tiles[row][col]; // The matches of the current tile final List<Tile> matchedTiles.add = new ArrayList<Tile>(toCheck); if(toCheck.getRow()row < 7 && array[rowtiles[row + 1][col].getId() == array[row][col]tiles[row][col].getId()){ //check 1 up matchedTiles.add(array[rowtiles[row + 1][col]); } if(toCheck.getRow()row < 6 && array[rowtiles[row + 2][col].getId() == array[row][col]tiles[row][col].getId(){) //check 2 up matchedTiles.add(array[rowtiles[row + 2][col]); } if(toCheck.getRow()row > 0 && array[rowtiles[row - 1][col].getId() == array[row][col]tiles[row][col].getId()) { //check 1 down matchedTiles.add(array[rowtiles[row - 1][col]); } if(toCheck.getRow()row > 1 && array[rowtiles[row - 2][col].getId() == array[row][col]tiles[row][col].getId(){) //check 2 down matchedTiles.add(array[rowtiles[row - 2][col]); } } // If we find a match if(matchedTiles.size >= 32){ //if we find a match{ for(Tile ttile : matchedTiles) { final int row = array[ttile.getRow()][t.getCol()].setId(8); //actual array of tiles on board } final int matchedTilescol = new Array<Tile>tile.getCol(); }else{ matchedTiles = new Array<Tile>tiles[row][col].setId(8); } } } private Array<Tile> matchedTiles = new Array<Tile>(); //... private void checkVertical(int row, int col){ Tile toCheck = array[row][col]; matchedTiles.add(toCheck); if(toCheck.getRow() < 7 && array[row + 1][col] == array[row][col]){ //check 1 up matchedTiles.add(array[row + 1][col]); } if(toCheck.getRow() < 6 && array[row + 2][col] == array[row][col]){//check 2 up matchedTiles.add(array[row + 2][col]); } if(toCheck.getRow() > 0 && array[row - 1][col] == array[row][col]){//check 1 down matchedTiles.add(array[row - 1][col]); } if(toCheck.getRow() > 1 && array[row - 2][col] == array[row][col]){//check 2 down matchedTiles.add(array[row - 2][col]); } if(matchedTiles.size >= 3){ //if we find a match for(Tile t : matchedTiles){ array[t.getRow()][t.getCol()].setId(8); //actual array of tiles on board } matchedTiles = new Array<Tile>(); }else{ matchedTiles = new Array<Tile>(); } } private void checkVertical(int row, int col){ // The current tile we are checking for matches final Tile tile = tiles[row][col]; // The matches of the current tile final List<Tile> matchedTiles = new ArrayList<Tile>(); if(row < 7 && tiles[row + 1][col].getId() == tiles[row][col].getId()){ // 1 up matchedTiles.add(tiles[row + 1][col]); if(row < 6 && tiles[row + 2][col].getId() == tiles[row][col].getId()) // 2 up matchedTiles.add(tiles[row + 2][col]); } if(row > 0 && tiles[row - 1][col].getId() == tiles[row][col].getId()) { // 1 down matchedTiles.add(tiles[row - 1][col]); if(row > 1 && tiles[row - 2][col].getId() == tiles[row][col].getId()) // 2 down matchedTiles.add(tiles[row - 2][col]); } // If we find a match if(matchedTiles.size >= 2) { for(Tile tile : matchedTiles) { final int row = tile.getRow(); final int col = tile.getCol(); tiles[row][col].setId(8); } } } EDIT:
Trying to implement Shiro's solution:
private Array<Tile> matchedTiles = new Array<Tile>(); //... private void checkVertical(int row, int col){ Tile toCheck = array[row][col]; matchedTiles.add(toCheck); if(toCheck.getRow() < 7 && array[row + 1][col] == array[row][col]){ //check 1 up matchedTiles.add(array[row + 1][col]); } if(toCheck.getRow() < 6 && array[row + 2][col] == array[row][col]){//check 2 up matchedTiles.add(array[row + 2][col]); } if(toCheck.getRow() > 0 && array[row - 1][col] == array[row][col]){//check 1 down matchedTiles.add(array[row - 1][col]); } if(toCheck.getRow() > 1 && array[row - 2][col] == array[row][col]){//check 2 down matchedTiles.add(array[row - 2][col]); } if(matchedTiles.size >= 3){ //if we find a match for(Tile t : matchedTiles){ array[t.getRow()][t.getCol()].setId(8); //actual array of tiles on board } matchedTiles = new Array<Tile>(); }else{ matchedTiles = new Array<Tile>(); } } EDIT:
Trying to implement Shiro's solution:
private Array<Tile> matchedTiles = new Array<Tile>(); //... private void checkVertical(int row, int col){ Tile toCheck = array[row][col]; matchedTiles.add(toCheck); if(toCheck.getRow() < 7 && array[row + 1][col] == array[row][col]){ //check 1 up matchedTiles.add(array[row + 1][col]); } if(toCheck.getRow() < 6 && array[row + 2][col] == array[row][col]){//check 2 up matchedTiles.add(array[row + 2][col]); } if(toCheck.getRow() > 0 && array[row - 1][col] == array[row][col]){//check 1 down matchedTiles.add(array[row - 1][col]); } if(toCheck.getRow() > 1 && array[row - 2][col] == array[row][col]){//check 2 down matchedTiles.add(array[row - 2][col]); } if(matchedTiles.size >= 3){ //if we find a match for(Tile t : matchedTiles){ array[t.getRow()][t.getCol()].setId(8); //actual array of tiles on board } matchedTiles = new Array<Tile>(); }else{ matchedTiles = new Array<Tile>(); } } Loading
lang-java