Foro de elhacker.net

Programación => Java => Mensaje iniciado por: bengy en 26 Octubre 2011, 18:13 pm



Título: juego tres en raya
Publicado por: bengy en 26 Octubre 2011, 18:13 pm
Código:
import java.util.*;
public class TresRaya{
char asterisco;
char cero;
char [][] matriz;
String juego=" ";
boolean bandera=false;

public TresRaya(){
asterisco='*';
cero='o';
matriz= new char [3][3];
}

public char [][] llenar(){
for(int i=0;    i<=2;  i++){
for(int j=0;    j<=2;  j++){
   
        matriz[i][j]='t';
        //llenamos con t por tres en raya
}
}
return matriz;
}
public String poner1(int fila, int columna, char caracter){
if(bandera==false){
for(int i=0;    i<=2;  i++){
for(int j=0;    j<=2;  j++){
    if (i==fila && j==columna){
        if(caracter=='*' && matriz[i][j]=='t'){
        matriz[i][j]=caracter; }
}
}
}
if(matriz[0][0]=='*' && matriz[0][1]=='*' && matriz[0][2]=='*'){ juego="gano jugador 1"; }
if(matriz[1][0]=='*' && matriz[1][1]=='*' && matriz[1][2]=='*'){ juego="gano jugador 1"; }
if(matriz[2][0]=='*' && matriz[2][1]=='*' && matriz[2][2]=='*'){ juego="gano jugador 1"; }
if(matriz[0][0]=='*' && matriz[1][1]=='*' && matriz[2][2]=='*'){ juego="gano jugador 1"; }
if(matriz[0][0]=='*' && matriz[1][0]=='*' && matriz[2][0]=='*'){ juego="gano jugador 1"; }
if(matriz[0][1]=='*' && matriz[1][1]=='*' && matriz[2][1]=='*'){ juego="gano jugador 1"; }
if(matriz[0][2]=='*' && matriz[1][2]=='*' && matriz[2][2]=='*'){ juego="gano jugador 1"; }
if(matriz[0][2]=='*' && matriz[1][1]=='*' && matriz[0][0]=='*'){ juego="gano jugador 1"; }
bandera=true;
}
else{ juego="no es su turno";}
return juego;
}

public String poner2(int fila, int columna, char caracter){
if(bandera==true){
for(int i=0;    i<=2;  i++){
for(int j=0;    j<=2;  j++){
    if (i==fila && j==columna){
        if(caracter=='o'  && matriz[i][j]=='t' ){
        matriz[i][j]=caracter; }
    }
}
}
if(matriz[0][0]=='o' && matriz[0][1]=='o' && matriz[0][2]=='o'){ juego="gano jugador 2"; }
if(matriz[1][0]=='o' && matriz[1][1]=='o' && matriz[1][2]=='o'){ juego="gano jugador 2"; }
if(matriz[2][0]=='o' && matriz[2][1]=='o' && matriz[2][2]=='o'){ juego="gano jugador 2"; }
if(matriz[0][0]=='o' && matriz[1][1]=='o' && matriz[2][2]=='o'){ juego="gano jugador 2"; }
if(matriz[0][0]=='o' && matriz[1][0]=='o' && matriz[2][0]=='o'){ juego="gano jugador 2"; }
if(matriz[0][1]=='o' && matriz[1][1]=='o' && matriz[2][1]=='o'){ juego="gano jugador 2"; }
if(matriz[0][2]=='o' && matriz[1][2]=='o' && matriz[2][2]=='o'){ juego="gano jugador 2"; }
if(matriz[0][2]=='o' && matriz[1][1]=='o' && matriz[0][0]=='o'){ juego="gano jugador 2"; }
bandera=false;
}
else{ juego="no es su turno";}
return juego;
}


public void mostrar(){
for(int i=0;    i<=2;  i++){
for(int j=0;    j<=2;  j++){
    System.out.println(matriz[i][j]);
}
}

}
}


Título: Re: juego tres en raya
Publicado por: bengy en 30 Octubre 2011, 22:23 pm
alguien me da ideas para hacer la intefaz bueno acorde con el code


Título: juego tres en raya
Publicado por: Debci en 31 Octubre 2011, 08:17 am
El mensaje 'juego tres en raya (http://foro.elhacker.net/index.php?topic=342973)' fue bloqueado
Incumplimiento de las normas, leetelas por favor.
Leer reglas:
http://foro.elhacker.net/reglas

-Doble post
-Título incompleto (no especificas tu problema)
-Mensajes vacíos respecto a lo que quieres que te hagan.
-No preguntas ninguna duda concreta, solo pides que te lo hagan.
-Aquí no se hacen tareas.