Galera ,
Estou com um problema , tenho uma matriz 30x60 , cujo a mesma é preenchida com zero , nas bordas é preenchido com o numero 1 e no meio tem uns blocos de numero 2.Segue a matriz abaixo:
111111111111111111111111111111111111111111111111111111111111
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100002222222000000000000000000000000000000000000222222200001
100002222222000000000000000000000000000000000000222222200001
100002222222000000000000000000000000000000000000222222200001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000002222222222000000000000000000000000001
100000000000000000000002222222222000000000000000000000000001
100000000000000000000002222222222000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
100002222222000000000000000000000000000000000000222222200001
100002222222000000000000000000000000000000000000222222200001
100002222222000000000000000000000000000000000000222222200001
100000000000000000000000000000000000000000000000000000000001
100000000000000000000000000000000000000000000000000000000001
111111111111111111111111111111111111111111111111111111111111
Nela eu gero um numero e movo ele , até ai tudo bem , mas quando ele anda eu substituo uma posição por 3 e a anterior por 0 , só que quando ele entra no numero 2 ou 1 ele deixa o numero 0 também ao invés de deixar o que estava.
Eu estou com dificuldades para fazer as condições para arrumar isso .Segue meu código de mover o numero.
public void moverVeiculo(int matrix[][],int veiculo,int velocidade) {
for (int l = 0; l < matrix.length; l++) {
for (int c = 0; c < matrix[l].length; c++) {
int numero = matrix[l][c];
if (numero == veiculo) {
Random random = new Random();
int direcao = random.nextInt(4);
matrix[l][c]=0;
switch (direcao) {
// move para cima
case 0:
if ((l - velocidade) > 0 ) {
l -= velocidade;
}
else {
l=28;
}
break;
//move para baixo
case 1:
if ((l + velocidade) < 30) {
l += velocidade;
}
else {
l=1;
}
break;
//move para direita
case 2:
if ((c - velocidade) > 0) {
c -= velocidade;
}else{
c=58;
}
break;
//move para esquerda
case 3:
if ((c + velocidade) <60){
c = c + velocidade;
}
else {
c=1;
}
break;
}
matrix[l][c]=numero;
}
}
}
}
Se puderem me ajudar agradeço , obrigado