0
I have a matrix in a class called Logica.
And I’m manipulating her from another class called Game.
But when I pass a value of the Game class to the matrix in the Logica class and check if the value was saved in the matrix it returns me 0, as if I had not "saved" in the matrix .
I have to leave the matrix in the main class so that it never loses and accepts the past values?
class game
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 that is occurring to me in this code is that every time I add a new value to the matrix it loses the previous values. It’s like the matrix is created every time I add a value.
what am I doing wrong ??
Where are you calling the class methods
Jogo
?– Murilo Fechio