Professional Documents
Culture Documents
*;
import java.awt.event.*;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
f.addWindowListener(new WindowAdapter() {
f.setSize(450, 450);
f.show();
}
}
class PanelCombate extends Panel {
Casilla tablero[][];
boolean naves [][];
boolean maquina[][];
int pos, disparos, fallos,aciertos = 0;
PanelCombate() {
int f, c;
setLayout(new GridLayout(11, 11));
tablero = new Casilla[11][11];
naves = new boolean[11][11];
pos = seleccion();
}
break;
case 2:
try{
if (tipo > 2) {
if (f == 9) {
naves[f - 1][c] = true;
naves[f - 2][c] = true;
naves[f - 3][c] = true;
} else {
naves[f + 1][c] = true;
naves[f + 2][c] = true;
naves[f + 3][c] = true;
}
} else {
if (c == 9) {
naves[f][c - 1] = true;
naves[f][c - 2] = true;
naves[f][c - 3] = true;
} else {
naves[f][c + 1] = true;
naves[f][c + 2] = true;
naves[f][c + 3] = true;
}
}
break;
}
catch(ArrayIndexOutOfBoundsException w){
}
case 3:
try{
if (f == 9) {
naves[f - 1][c] = true;
naves[f - 1][c + 1] = true;
} else {
naves[f + 1][c] = true;
naves[f + 1][c - 1] = true;
}
break;
}
catch(ArrayIndexOutOfBoundsException q){
}
}
naves[f][c] = true;
}
}
private int seleccion() {
int a = 9;
return a;
}
boolean aciertos;
Casilla(String t) {
super.setLabel("");
setBackground(new Color(250, 210, 250));
aciertos = false;
}
}
PanelCombate pc;
int vert, hori, cant = 0;
if (!pc.tablero[hori][vert].aciertos) {
pc.tablero[hori][vert].aciertos = true;
pc.tablero[hori][vert].setBackground(new Color(0));
pc.disparos++;
if (pc.naves[hori][vert]) {
pc.tablero[vert][hori].setLabel("");
for (int x = 0; x < 11; x++) {
for (int y = 0; y < 11; y++) {
if (pc.naves[x][y]) {
if (x == hori && y == vert) {
pc.tablero[x][y].setBackground(new
Color(0,0,210));
pc.tablero[x][y].setLabel("");
pc.aciertos++;
}
}
}
}
}
pc.fallos = disparos - aciertos;
if (pc.aciertos >=9){
JOptionPane.showMessageDialog(pc.getParent(), "Ganaste");
System.exit(0);
}
if ((pc.disparos >= 6 && pc.aciertos == 0) || (pc.disparos >= 24))
{
}
}
}
}
}
}
}