Podrias poner como usarlo en el main ...
Es que intento checarlo pero aun no consigo del todo crear el main jejeje
Yo hice tambien uno aunque es un poco mas corto:
package Ahorcado;
import java.util.Random;
public class AHORCADO
{
private String palabra
= "", Solucion
= ""; private int pos = -1, intentos = 0, maxintentos = 6;
private String [] PALABRAS
= {"GATO",
"PERRO",
"ELEFANTE",
"CASA",
"AUTOMOVIL",
"ESCUELA", "MALCOM IN THE MIDDLE"};
public int Gano = -1;
public void Iniciar()
{
int x = -1;
do{
x = R.nextInt(PALABRAS.length);
}while(pos == x);
pos = x;
palabra = PALABRAS[pos];
for(x = 0; x < palabra.length(); x++)
{
if(palabra.charAt(x) != ' ')
Solucion += "_";
else
Solucion += " ";
}
Dibujar();
}
public void BuscarLetra(char pal)
{
Solucion = "";
for(int x = 0; x < palabra.length(); x++)
{
if(palabra.charAt(x) != ' ')
{
if(pal == palabra.charAt(x))
Solucion += pal;
else
Solucion += Sol1.charAt(x);
}else
Solucion += ' ';
}
if(Sol1.compareTo(Solucion) == 0 && Solucion.indexOf(pal) == -1)
intentos++;
Dibujar();
if(Solucion.compareTo(palabra) == 0)
{
Gano = 0;
SOP("Usted ha GANADO!!!! ;D");
}else if(intentos == maxintentos){
Gano = 1;
SOP("Usted ha perdido!!! ");
}
}
private void Dibujar()
{
for(char c: Solucion.toCharArray())
SOP("");
SOP("\nIntentos restantes: " + (maxintentos - intentos));
}
{
}
}
Y en el main para jugar seria algo asi:
Scanner Leer
= new Scanner
(System.
in); AHORCADO A = new AHORCADO();
char Letra;
int op = -1;
do{
if(op == -1)
op = 1;
else{
A.SOP("\n[1] - Jugar de Nuevo\n[0] - Salir");
op = Leer.nextInt();
}
switch(op)
{
case 1:
A.Iniciar();
while(A.Gano == -1)
{
letra = Leer.next().toUpperCase();
Letra = letra.charAt(0);
A.BuscarLetra(Letra);
}
break;
case 0:
break;
default:
A.SOP("Opcion Indefinida!");
}
}while(op != 0);