I have an array in a class called Logica.
And I'm manipulating it from another class called Game.
But when I pass a value from the Game class to the array in the Logic class and Czech if the value was stored in the array it returns me 0, as if I did not have "saved" in the array.
I have to leave the array in the main class so that it never misses and accepts past values?
Game class
public class Jogo {
Logica logi = new Logica();
public static void main(String[] args) throws Exception{
//exibe Tabuleiro :)
new Tabuleiro();
}
public boolean validaJogada(int lin, int col){
if(logi.devolveValor(lin, col) != 0){
return false;
}else{
System.out.println("Valida Jogo Classe:JOGO " +logi.devolveValor(lin, col));
return true;
}
}
public void realizaJogada(int lin, int col, int jogador){
logi.recebeJogada(lin, col, jogador);
System.out.println(montaMatriz());
}
public String montaMatriz(){
String matriz;
int tabu[][] = new int [3][3];
tabu = logi.devolveTabuleiro();
matriz = tabu[0][0]+"|"+tabu[0][1]+"|"+tabu[0][2] + "\n";
for(int i=1; i < 3; i++){
for(int j=2; j < 3; j++){
matriz += tabu[i][j]+"|"+tabu[i][j]+"|"+tabu[i][j] + "\n";
}
}
return matriz;
}
Logica class
public class Logica {
public int tab[][] = new int[3][3];
private int jogador;
public int[][] devolveTabuleiro(){
int i,j;
for(i=0; i <=2 ; i++){
for(j=0; j<=2; j++){
System.out.println(this.tab[i][j]);
}
}
return tab;
}
public boolean recebeJogada(int lin, int col, int jogador){
tab[lin][col] = jogador;
System.out.println("Recebi: col: " + col + " Linha: " + lin+ " do Jogador: "+ jogador);
return true;
}
public int devolveValor(int lin, int col){
return tab[lin][col];
}
The problem I'm having with this code is that every time I add a new value to the array it loses its previous values. It is as if the array were created every time I add a value.
What am I doing wrong?