I would like to know if you could help me with this little problem that I have.
I'm doing a basic variation of the game tetris in console as part of a task, I'm quite new to Java, I just started and I was stuck in the system of punctuation / elimination of matches.
I have a matrix full of spaces (game board) that is filled with the figures of tetris, then, at a certain moment of the game I have:
As you can see, I have 4 similar elements that should have been eliminated. The only solution I can think of is to go through the whole matrix and check if there are 4 equal characters in x column, eliminate them and add points ... of this way:
for (int y=1;y<Tablero.length-1;y++){
for(int x=1;x<Tablero[y].length-4;x++){
if(Tablero[y][x].equals(Tablero[y][x+1])&&Tablero[y][x+1].equals(Tablero[y][x+2])&&Tablero[y][x].equals(Tablero[y][x+3])&&Tablero[y][x]!=" "){
puntos=puntos+1;
Tablero[y][x]=" ";
Tablero[y][x+1]=" ";
Tablero[y][x+2]=" ";
Tablero[y][x+3]=" ";
}
}
But this solution, besides being quite ugly, only applies to the specific case of 4 equals, if there are more than 4, it does not take them into account.
So in itself, the question would be: How can I go through a matrix and check if 4 or more elements are the same?
Thank you in advance for any suggestions