Gato

Páginas: 6 (1269 palabras) Publicado: 18 de septiembre de 2010
import javax.swing.*;
import java.awt.*;
import java.lang.*;
import java.awt.event.*;
import java.util.Random;

class Raya extends JFrame implements ActionListener
{
int turno=0;
boolean fin;
boolean dosJugadores;
boolean pulsado;
//botones
JButton boton[][]=new JButton[7][7];
//menus
JMenuBar Barra=new JMenuBar();
JMenu Archivo=new JMenu("Archivo");
JMenu Opciones=newJMenu("Opciones");
JMenuItem Nuevo=new JMenuItem("Nuevo");
JMenuItem Salir=new JMenuItem("Salir");
JMenuItem M1Jugador=new JMenuItem("1 Jugador");
JMenuItem M2Jugador=new JMenuItem("2 Jugadores");
JLabel Nombre=new JLabel("http://todojava.awardspace.com",JLabel.CENTER);

//imagenes
ImageIcon foto1;
ImageIcon foto2;

Raya()
{
//Cargar imagenes

foto1=newImageIcon("foto1.gif");
foto2=new ImageIcon("foto2.gif");


//menu
Nuevo.addActionListener(this);
Archivo.add(Nuevo);
Archivo.addSeparator();
Salir.addActionListener(this);
Archivo.add(Salir);
M1Jugador.addActionListener(this);
Opciones.add(M1Jugador);
M2Jugador.addActionListener(this);
Opciones.add(M2Jugador);
Barra.add(Archivo);
Barra.add(Opciones);setJMenuBar(Barra);


//Panel Principal
JPanel Principal=new JPanel();
Principal.setLayout(new GridLayout(7,7));

//Colocar Botones
for(int i=0;i<7;i++)
{
for(int j=0;j<7;j++)
{

boton[i][j]=new JButton();
boton[i][j].addActionListener(this);
boton[i][j].setBackground(Color.BLACK);
Principal.add(boton[i][j]);
}Nombre.setForeground(Color.BLUE);
add(Nombre,"North");
add(Principal,"Center");

}

//Para cerrar la Ventana

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

//tamaño frame
setLocation(170,25);
setSize (600,600);
setResizable(false);
setTitle("CONECTA 4 v 1.0http://todojava.awardspace.com/");
setVisible(true);

}
void ganar(int x,int y)
{
/*
* x fila
* y columna
*/

fin=false;
//Quien gana en?¿ horizontal
int ganar1=0;
int ganar2=0;
for(int j=0;j<7;j++)
{
if(boton[y][j].getIcon()!=null)
{
if(boton[y][j].getIcon().equals(foto1))
{ganar1++;
}
else ganar1=0;
if(ganar1==4)
{

JOptionPane.showMessageDialog(this,"Gana Jugador Rojo","Conecta 4",JOptionPane.INFORMATION_MESSAGE,foto1);
VolverEmpezar();
fin=true;
}
if(fin!=true)
{
if(boton[y][j].getIcon().equals(foto2))
{ganar2++;
}
else ganar2=0;
if(ganar2==4)
{
JOptionPane.showMessageDialog(this,"Gana Jugador Verde","Conecta 4",JOptionPane.INFORMATION_MESSAGE,foto2);
VolverEmpezar();
}
}
}
else
{
ganar1=0;
ganar2=0;
}
}
// Quien gana en?¿vertical
ganar1=0;
ganar2=0;
for(int i=0;i<7;i++)
{
if(boton[i][x].getIcon()!=null)
{
if(boton[i][x].getIcon().equals(foto1))
{
ganar1++;
}
else ganar1=0;
if(ganar1==4)
{
JOptionPane.showMessageDialog(this,"Gana Jugador Rojo","Conecta4",JOptionPane.INFORMATION_MESSAGE,foto1);
VolverEmpezar();
fin=true;
}
if(fin!=true)
{
if(boton[i][x].getIcon().equals(foto2))
{
ganar2++;
}
else ganar2=0;
if(ganar2==4)
{
JOptionPane.showMessageDialog(this,"Gana Jugador Verde","Conecta 4",JOptionPane.INFORMATION_MESSAGE,foto2);...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Gatos
  • Gatos
  • Soy gat
  • Gatos
  • Gatos
  • Gato
  • La Gata
  • gatos

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS