Paulo Andres Escobar Ingenieria de Sistemas, Orientacion a la Programacion el arte de crear Programas
jueves, 5 de septiembre de 2013
BATALLA NAVALA CLASE BARCO 3 posiciones
CLASE BARCO DE 3 POSICIONES
public class Barco_3 extends Barco {
public static int contador_de_barcos =0;
@Override
public void posicionarBarcoV(int[][] matriz, int fila, int columna, JLabel a) {
contador_de_barcos++;
if (fila ==10||fila==9)
{
JOptionPane.showMessageDialog(null,"no puedes jugar fuera del juego");
contador_de_barcos --;
}
if (matriz[fila][columna]!=0 ||matriz[fila+1][columna]!=0||matriz[fila+2][columna]!=0 )
{
JOptionPane.showMessageDialog(null,"posicion tomada");
contador_de_barcos --;
}
else
{
if (contador_de_barcos <=2)
{
matriz[fila][columna]=3;
matriz[fila+1][columna]=3;
matriz[fila+2][columna]=3;
switch (fila)
{
case 1:
switch (columna)
{
case 1:
a.setLocation(50, 40); break;
case 2:
a.setLocation(90, 40);break;
case 3:
a.setLocation(130, 40);break;
case 4:
a.setLocation(170, 40);break;
case 5:
a.setLocation(210, 40);break;
case 6:
a.setLocation(250, 40);break;
case 7:
a.setLocation(290, 40);break;
case 8:
a.setLocation(330, 40);break;
case 9:
a.setLocation(370, 40);break;
case 10:
a.setLocation(410, 40);break;
}
break;
case 2:
switch (columna)
{
case 1:
a.setLocation(50, 80); break;
case 2:
a.setLocation(90, 80);break;
case 3:
a.setLocation(130, 80);break;
case 4:
a.setLocation(170, 80);break;
case 5:
a.setLocation(210, 80);break;
case 6:
a.setLocation(250, 80);break;
case 7:
a.setLocation(290, 80);break;
case 8:
a.setLocation(330, 80);break;
case 9:
a.setLocation(370, 80);break;
case 10:
a.setLocation(410, 80);break;
}
break;
case 3:
switch (columna)
{
case 1:
a.setLocation(50, 120); break;
case 2:
a.setLocation(90, 120);break;
case 3:
a.setLocation(130, 120);break;
case 4:
a.setLocation(170, 120);break;
case 5:
a.setLocation(210, 120);break;
case 6:
a.setLocation(250, 120);break;
case 7:
a.setLocation(290, 120);break;
case 8:
a.setLocation(330, 120);break;
case 9:
a.setLocation(370, 120);break;
case 10:
a.setLocation(410, 120);break;
}
break;
case 4:
switch (columna)
{
case 1:
a.setLocation(50, 160);break;
case 2:
a.setLocation(90, 160);break;
case 3:
a.setLocation(130, 160);break;
case 4:
a.setLocation(170, 160);break;
case 5:
a.setLocation(210, 160);break;
case 6:
a.setLocation(250, 160);break;
case 7:
a.setLocation(290, 160);break;
case 8:
a.setLocation(330, 160);break;
case 9:
a.setLocation(370, 160);break;
case 10:
a.setLocation(410, 160);break;
}
break;
case 5:
switch (columna)
{
case 1:
a.setLocation(50, 200);break;
case 2:
a.setLocation(90, 200);break;
case 3:
a.setLocation(130, 200);break;
case 4:
a.setLocation(170, 200);break;
case 5:
a.setLocation(210, 200);break;
case 6:
a.setLocation(250, 200);break;
case 7:
a.setLocation(290, 200);break;
case 8:
a.setLocation(330, 200); break;
case 9:
a.setLocation(370, 200); break;
case 10:
a.setLocation(410, 200); break;
}
break;
case 6:
switch (columna)
{
case 1:
a.setLocation(50, 240);break;
case 2:
a.setLocation(90, 240);break;
case 3:
a.setLocation(130, 240);break;
case 4:
a.setLocation(170, 240); break;
case 5:
a.setLocation(210, 240); break;
case 6:
a.setLocation(250, 240);break;
case 7:
a.setLocation(290, 240);break;
case 8:
a.setLocation(330, 240);break;
case 9:
a.setLocation(370, 240);break;
case 10:
a.setLocation(410, 240);break;
}
break;
case 7:
switch (columna)
{
case 1:
a.setLocation(50, 280);break;
case 2:
a.setLocation(90, 280);break;
case 3:
a.setLocation(130, 280);break;
case 4:
a.setLocation(170, 280);break;
case 5:
a.setLocation(210, 280);break;
case 6:
a.setLocation(250, 280);break;
case 7:
a.setLocation(290, 280);break;
case 8:
a.setLocation(330, 280);break;
case 9:
a.setLocation(370, 280);break;
case 10:
a.setLocation(410, 280);break;
}
break;
case 8:
switch (columna)
{
case 1:
a.setLocation(50, 320);break;
case 2:
a.setLocation(90, 320);break;
case 3:
a.setLocation(130, 320);break;
case 4:
a.setLocation(170, 320);break;
case 5:
a.setLocation(210, 320);break;
case 6:
a.setLocation(250, 320);break;
case 7:
a.setLocation(290, 320); break;
case 8:
a.setLocation(330, 320);break;
case 9:
a.setLocation(370, 320);break;
case 10:
a.setLocation(410, 320); break;
}
break;
case 9:
switch (columna)
{
case 1:
a.setLocation(50, 360);break;
case 2:
a.setLocation(90, 360);break;
case 3:
a.setLocation(130, 360);break;
case 4:
a.setLocation(170, 360);break;
case 5:
a.setLocation(210, 360);break;
case 6:
a.setLocation(250, 360);break;
case 7:
a.setLocation(290, 360);break;
case 8:
a.setLocation(330, 360);break;
case 9:
a.setLocation(370, 360);break;
case 10:
a.setLocation(410, 360);break;
}
break;
// case 10:
// JOptionPane.showMessageDialog(null,"no puedes jugar fuera del juego");
// break;
default:
break;
}
}
else
{
JOptionPane.showMessageDialog(null, "limite de barcos de 3 posiciones alcanzado");
}
}
}
@Override
public void posicionarBarcoH(int[][] matriz, int fila, int columna, JLabel a) {
contador_de_barcos++;
if (columna ==10||columna ==9)
{
JOptionPane.showMessageDialog(null,"no puedes jugar fuera del juego");
contador_de_barcos --;
}
if (matriz[fila][columna]!=0 ||matriz[fila][columna+1]!=0||matriz[fila][columna+2]!=0 )
{
JOptionPane.showMessageDialog(null,"posicion tomada");
contador_de_barcos --;
}
else{
if (contador_de_barcos <=2)
{
matriz[fila][columna]=3;
matriz[fila][columna+1]=3;
matriz[fila][columna+2]=3;
switch (fila)
{
case 1:
switch (columna)
{
case 1:
a.setLocation(40, 50); break;
case 2:
a.setLocation(80, 50);break;
case 3:
a.setLocation(120, 50);break;
case 4:
a.setLocation(160, 50);break;
case 5:
a.setLocation(200, 50);break;
case 6:
a.setLocation(240, 50);break;
case 7:
a.setLocation(280, 50);break;
case 8:
a.setLocation(320, 50);break;
case 9:
a.setLocation(360, 50);break;
// case 10:
// a.setLocation(400, 50);break;
}
break;
case 2:
switch (columna)
{
case 1:
a.setLocation(40, 90); break;
case 2:
a.setLocation(80, 90);break;
case 3:
a.setLocation(120, 90);break;
case 4:
a.setLocation(160, 90);break;
case 5:
a.setLocation(200, 90);break;
case 6:
a.setLocation(240, 90);break;
case 7:
a.setLocation(280, 90);break;
case 8:
a.setLocation(320, 90);break;
case 9:
a.setLocation(360, 90);break;
// case 10:
// a.setLocation(400, 90);break;
}
break;
case 3:
switch (columna)
{
case 1:
a.setLocation(40, 130); break;
case 2:
a.setLocation(80, 130);break;
case 3:
a.setLocation(120, 130);break;
case 4:
a.setLocation(160, 130);break;
case 5:
a.setLocation(200, 130);break;
case 6:
a.setLocation(240, 130);break;
case 7:
a.setLocation(280, 130);break;
case 8:
a.setLocation(320, 130);break;
case 9:
a.setLocation(360, 130);break;
// case 10:
// a.setLocation(400, 130);break;
}
break;
case 4:
switch (columna)
{
case 1:
a.setLocation(40, 170); break;
case 2:
a.setLocation(80, 170);break;
case 3:
a.setLocation(120, 170);break;
case 4:
a.setLocation(160, 170);break;
case 5:
a.setLocation(200, 170);break;
case 6:
a.setLocation(240, 170);break;
case 7:
a.setLocation(280, 170);break;
case 8:
a.setLocation(320, 170);break;
case 9:
a.setLocation(360, 170);break;
// case 10:
// a.setLocation(400, 170);break;
}
break;
case 5:
switch (columna)
{
case 1:
a.setLocation(40,210); break;
case 2:
a.setLocation(80, 210);break;
case 3:
a.setLocation(120, 210);break;
case 4:
a.setLocation(160, 210);break;
case 5:
a.setLocation(200, 210);break;
case 6:
a.setLocation(240, 210);break;
case 7:
a.setLocation(280, 210);break;
case 8:
a.setLocation(320, 210);break;
case 9:
a.setLocation(360, 210);break;
// case 10:
// a.setLocation(400, 210);break;
}
break;
case 6:
switch (columna)
{
case 1:
a.setLocation(40, 250); break;
case 2:
a.setLocation(80, 250);break;
case 3:
a.setLocation(120, 250);break;
case 4:
a.setLocation(160, 250);break;
case 5:
a.setLocation(200, 250);break;
case 6:
a.setLocation(240, 250);break;
case 7:
a.setLocation(280, 250);break;
case 8:
a.setLocation(320, 250);break;
case 9:
a.setLocation(360, 250);break;
// case 10:
// a.setLocation(400, 250);break;
}
break;
case 7:
switch (columna)
{
case 1:
a.setLocation(40, 290); break;
case 2:
a.setLocation(80, 290);break;
case 3:
a.setLocation(120, 290);break;
case 4:
a.setLocation(160, 290);break;
case 5:
a.setLocation(200, 290);break;
case 6:
a.setLocation(240, 290);break;
case 7:
a.setLocation(280, 290);break;
case 8:
a.setLocation(320, 290);break;
case 9:
a.setLocation(360, 290);break;
// case 10:
// a.setLocation(400, 290);break;
}
break;
case 8:
switch (columna)
{
case 1:
a.setLocation(40, 330); break;
case 2:
a.setLocation(80, 330);break;
case 3:
a.setLocation(120,330);break;
case 4:
a.setLocation(160, 330);break;
case 5:
a.setLocation(200, 330);break;
case 6:
a.setLocation(240, 330);break;
case 7:
a.setLocation(280, 330);break;
case 8:
a.setLocation(320, 330);break;
case 9:
a.setLocation(360, 330);break;
// case 10:
// a.setLocation(400, 330);break;
}
break;
case 9:
switch (columna)
{
case 1:
a.setLocation(40, 370); break;
case 2:
a.setLocation(80, 370);break;
case 3:
a.setLocation(120, 370);break;
case 4:
a.setLocation(160, 370);break;
case 5:
a.setLocation(200, 370);break;
case 6:
a.setLocation(240, 370);break;
case 7:
a.setLocation(280, 370);break;
case 8:
a.setLocation(320, 370);break;
case 9:
a.setLocation(360, 370);break;
// case 10:
// a.setLocation(400, 370);break;
}
break;
case 10:
switch (columna)
{
case 1:
a.setLocation(40, 410); break;
case 2:
a.setLocation(80, 410);break;
case 3:
a.setLocation(120, 410);break;
case 4:
a.setLocation(160, 410);break;
case 5:
a.setLocation(200, 410);break;
case 6:
a.setLocation(240, 410);break;
case 7:
a.setLocation(280, 410);break;
case 8:
a.setLocation(320, 410);break;
case 9:
a.setLocation(360, 410);break;
// case 10:
// a.setLocation(400, 410);break;
}
break;
default:
break;
}
}
else
{
JOptionPane.showMessageDialog(null, "limite de barcos de 3 posiciones alcanzado");
}
}
}
/**
*
* posiciona Barcos verticalmente
* controla que no se pase del limite del tablero
*/
public void resetContador()
{
contador_de_barcos =0;
}
}
____
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario