Codigo JAVA para crear 3 en raya
/**
* @web www.jc-mouse.net/
* @author Mouse
*/
public class juego {
private byte turno = 1;//1=>jugador 1 2=> jugador 2
private String marca_X = "X";
privateString marca_O = "O";
private boolean error=false;//por si se produce algun mensaje
private byte ganador_es=0;//1=>jugador 1 2=> jugador 2 3=>Empate
//matriz para almacenar losmovimientos del juego
private String tablero[][] ={{"","",""},
{"","",""},
{"","",""}
};public juego(){}
//reinicia los valores y limpia el tablero
public void Jugar_otra_vez()
{
for ( int i = 0 ; i < tablero.length ; i++ )
for ( int j = 0 ; j
this.error=false;
this.ganador_es=0;
this.turno=1;
}
//dado una posicion y segun el turno que corresponda//coloca la marca "X" o "O" en el tablero
//Salida: La marca que se coloco en la matriz
public String set_movimiento(int posicion)
{
String out="";
if(turno==1){
out = marcar(posicion , this.marca_X);
//si no se pudo marcar => continua con su turno
turno = 2;
if ( gano(this.tablero, this.marca_X) )this.ganador_es=1;
else if ( empate() )
this.ganador_es=3;
}
else
{
out = marcar(posicion , this.marca_O);turno = 1;
if ( gano(this.tablero, this.marca_O) )
this.ganador_es=2;
else if ( empate() )
this.ganador_es=3;
}
returnout;
}
/* MARCA LA CASILLA CON EL MOVIMIENTO DEL JUGADOR, */
private String marcar(int Posicion, String value)
{
String marca="";
switch (Posicion)
{...
Regístrate para leer el documento completo.