Foros del Web » Programación para mayores de 30 ;) » Java »

Menu Para un Juego

Estas en el tema de Menu Para un Juego en el foro de Java en Foros del Web. Holaaaaaaaaassssss!!!! miren despues de tanto intentar pude hacer el juego combate naval con algunas caracteristicas especificas que me pidieron pero ahora necesito ponerle un menu ...
  #1 (permalink)  
Antiguo 21/07/2010, 21:31
 
Fecha de Ingreso: julio-2010
Mensajes: 1
Antigüedad: 13 años, 9 meses
Puntos: 0
Menu Para un Juego

Holaaaaaaaaassssss!!!!
miren despues de tanto intentar pude hacer el juego combate naval con algunas caracteristicas especificas que me pidieron
pero ahora necesito ponerle un menu por pantalla para q el jugador elija la dificultad
y ya no me puedo craniar tanto como para hacerlo T.T
(el nivel esta en facil hasta el momento en medio se disminuye los disparos = en dificil)
por favor ayudemne
ahi esta el codigo del juego D=

package combate;
import java.awt.*;
import java.awt.event.*;

import java.io.IOException;

import javax.swing.JFrame;

import javax.swing.JOptionPane;
public class combate {

public static void main(String[] args) throws IOException {


int puntero = 12;
JFrame f = new JFrame();

PanelCombate panel = new PanelCombate();
f.add(panel);



f.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent we) {
System.exit(0);
}
});

f.setTitle("Combate Naval ");
f.setCursor(puntero);

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();

for (f = 0; f < 11; f++) {
for (c = 0; c < 11; c++) {
naves[f][c] = false;
tablero[f][c] = new Casilla("");
add(tablero[f][c]);
tablero[f][c].addActionListener(new AccionBoton(this, c, f));
}
}
for (int i = 1; i <= 3; i++) {
int tipo = (int) (Math.random() * 2);
f = (int) (Math.random() * 11);
c = (int) (Math.random() * 11);
switch (i) {
case 1:
try{
if (tipo > 2) {
if (f == 11) {
naves[f - 1][c] = true;
} else {
naves[f + 1][c] = true;
}
} else {
if (c == 11) {
naves[f][c - 1] = true;
} else {
naves[f][c + 1] = true;
}
}}
catch(ArrayIndexOutOfBoundsException q){

}
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;
}

class Casilla extends Button {

boolean aciertos;

Casilla(String t) {
super.setLabel("");
setBackground(new Color(250, 210, 250));
aciertos = false;
}
}

class AccionBoton implements ActionListener {

PanelCombate pc;
int vert, hori, cant = 0;

AccionBoton(PanelCombate p, int v, int h) {
pc = p;
vert = v;
hori = h;
}

public void actionPerformed(ActionEvent ae) {
boolean salida = false;

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)) {

JOptionPane.showMessageDialog(pc.getParent(), "Se te han acabado los disparos");
JOptionPane.showMessageDialog(pc.getParent(), "Obtuviste "+aciertos+" aciertos y " +fallos+ " fallas " + " de un total de " +disparos+ " disparos ");
if(JOptionPane.showConfirmDialog(pc.getParent(), "Desea Reiniciar el juego","Aviso", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION){
if(salida != true){
System.exit(0);
}else{


}
}
}


}
}
}
}

Etiquetas: juegos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:05.