PROTOTIPO

private class ratones implements ActionListener{
int contador,turno;
public void actionPerformed(ActionEvent e){
char marca=' ';
contador++;
turno=contador%2;
if (turno==1){
marca='x';
}
else {
marca='o';
}
if(e.getSource()==bt1){
bt1.setText(marca+" ");
bt1.setEnabled(false);
gatos[0][0]=marca;
}
int contador,turno;
public void actionPerformed(ActionEvent e){
char marca=' ';
contador++;
turno=contador%2;
if (turno==1){
marca='x';
}
else {
marca='o';
}
if(e.getSource()==bt1){
bt1.setText(marca+" ");
bt1.setEnabled(false);
gatos[0][0]=marca;
}
CON ESTE PEDAZO DE CODIGO SE REGISTRAN LAS “X” Y LAS “O” EN LAS CASILLAS CORRESPONDIENTES DANDOLE UN CLICK EN CADA UNA DE ELLAS.
ESTE CODIGO ES SOLO PARA LA CASILLA QUE ESTA MARCADA CON LA “X”.

for(int c=0;c<=2;c++){
if(gatos[0][c]=='x'&&gatos[1][c]=='x'&&gatos[2][c]=='x'){
ganador=true;
bt1.setBackground(java.awt.Color.green);
bt4.setBackground(java.awt.Color.green);
bt7.setBackground(java.awt.Color.green);
}
}
if(gatos[0][c]=='x'&&gatos[1][c]=='x'&&gatos[2][c]=='x'){
ganador=true;
bt1.setBackground(java.awt.Color.green);
bt4.setBackground(java.awt.Color.green);
bt7.setBackground(java.awt.Color.green);
}
}
ESTE CODIGO HACE QUE CADA CELDA Y LA FILA QUE GANO SE PINTE DE COLOR VERDE.
EN ESTE CASO ES EL BOTON 1,4,7 MARCADOS CON LA “X”.
bt1.setBackground(java.awt.Color.green);
bt4.setBackground(java.awt.Color.green);
bt7.setBackground(java.awt.Color.green);
bt4.setBackground(java.awt.Color.green);
bt7.setBackground(java.awt.Color.green);

if(ganador==true&&marca=='x'){
System.out.println("jugador 1fue ganador");
}
if(ganador==true&&marca=='o'){
System.out.println("jugador 2 fue ganador");
}
EN ESTE CODIGO SE VA MOSTRAR EL JUGADOR QUE GANO. LOS JUGADORES SE VAN A MANEJAR COMO JUGADOR 1 Y 2.
System.out.println("jugador 1fue ganador");
}
if(ganador==true&&marca=='o'){
System.out.println("jugador 2 fue ganador");
}
EN ESTE CODIGO SE VA MOSTRAR EL JUGADOR QUE GANO. LOS JUGADORES SE VAN A MANEJAR COMO JUGADOR 1 Y 2.

private class ManejaEventoClarar implements ActionListener{
public void actionPerformed(ActionEvent g){
for(int r=0;r<=2;r++){
for (int c=0;c<=2;c++){
gatos[r][c]='\u0000';
}
}
bt1.setText(" ");
bt1.setEnabled(true);
bt2.setText(" ");
bt2.setEnabled(true);
bt3.setText(" ");
bt3.setEnabled(true);
bt4.setText(" ");
bt4.setEnabled(true);
bt5.setText(" ");
bt5.setEnabled(true);
bt6.setText(" ");
bt6.setEnabled(true);
bt7.setText(" ");
bt7.setEnabled(true);
bt8.setText(" ");
bt8.setEnabled(true);
bt9.setText(" ");
bt9.setEnabled(true);
bt1.setBackground(java.awt.Color.white);
bt2.setBackground(java.awt.Color.white);
bt3.setBackground(java.awt.Color.white);
bt4.setBackground(java.awt.Color.white);
bt5.setBackground(java.awt.Color.white);
bt6.setBackground(java.awt.Color.white);
bt7.setBackground(java.awt.Color.white);
bt8.setBackground(java.awt.Color.white);
bt9.setBackground(java.awt.Color.white);
}
}
public void actionPerformed(ActionEvent g){
for(int r=0;r<=2;r++){
for (int c=0;c<=2;c++){
gatos[r][c]='\u0000';
}
}
bt1.setText(" ");
bt1.setEnabled(true);
bt2.setText(" ");
bt2.setEnabled(true);
bt3.setText(" ");
bt3.setEnabled(true);
bt4.setText(" ");
bt4.setEnabled(true);
bt5.setText(" ");
bt5.setEnabled(true);
bt6.setText(" ");
bt6.setEnabled(true);
bt7.setText(" ");
bt7.setEnabled(true);
bt8.setText(" ");
bt8.setEnabled(true);
bt9.setText(" ");
bt9.setEnabled(true);
bt1.setBackground(java.awt.Color.white);
bt2.setBackground(java.awt.Color.white);
bt3.setBackground(java.awt.Color.white);
bt4.setBackground(java.awt.Color.white);
bt5.setBackground(java.awt.Color.white);
bt6.setBackground(java.awt.Color.white);
bt7.setBackground(java.awt.Color.white);
bt8.setBackground(java.awt.Color.white);
bt9.setBackground(java.awt.Color.white);
}
}
ESTE CODIGO VA A LIMPIAR TODAS LAS CELDAS DEL JUEGO PARA VOLVER A JUGAR.

if(gatos[2][0]=='o'&&gatos[1][1]=='o'&&gatos[0][2]=='o'){
ganador=true;
bt3.setBackground(java.awt.Color.yellow);
bt5.setBackground(java.awt.Color.yellow);
bt7.setBackground(java.awt.Color.yellow);
}
ganador=true;
bt3.setBackground(java.awt.Color.yellow);
bt5.setBackground(java.awt.Color.yellow);
bt7.setBackground(java.awt.Color.yellow);
}
EN ESTE CASO EL JUGADOR 2 GANO (EL JUGADOR 2 ES LA “O”).


ESTE ES UN PROTOTTIPO DE UN JUEGO DEL GATO CREADO EN EL LENGUAJE DE PROGRAMACION JAVA.
LO TENEMOS COMO PROTOTIPO POR QUE QUEREMOS HACER QUE EL JUEGO SEA MAS DINAMICO, QUE JUGUEMOS CONTRA LA COMPUTADORA Y UNAS MEJORAS EN SU INTERFAZ.
No hay comentarios:
Publicar un comentario