import javax.swing.*;
import java.io.*;
public class Gam3r
{
public Gam3r()
{
//stinky programme
//new design brief: make hangman!
String input,guess,sx="",pr="";
int i,cnt,x=0,y,p,q,r,left=10,m=0,f=0,l=0;
boolean gah=true,win=false,end=false;
input=JOptionPane.showInputDialog(null, "insert your word");
//insert the word
cnt=input.length();
String hm[]=new String[cnt];
String disp[]=new String[cnt];
//put the word in an array
for(i=0;i<cnt;i++)
{
hm[i]=input.substring(i,i+
1);
disp[i]="_";
System.out.println(disp[i]+" "+hm[i]);
}
//guess
do{
x++;
guess=JOptionPane.showInputDialog(null, "make yer guess");
l=0;
for(y=0;y<cnt;y++)
{
sx="";
if(hm[y].equalsIgnoreCase(
guess))
{
f++;
System.out.println("goes into loop true");
disp[y]=guess;
for(p=0;p<cnt;p++)
{
sx=sx+disp[p];
}
gah=true;
}
else
{
l++;
System.out.println("goes into loop false");
for(q=0;q<cnt;q++)
{
sx=sx+disp[q];
}
if(l==cnt)
{
gah=false;
left=left-1;
}
}
}
pr=pr+guess+",";
r=0;
for(p=0;p<cnt;p++)
{
if(disp[p]!="_")
{
System.out.println("this works");
r++;
if(r==cnt)
{
System.out.println("this works2");
win=true;
end=true;
}
}
else
{
System.out.println("win=false");
win=false;
}
}
if(gah==true)
{
JOptionPane.showMessageDialog(null,"Correct guess ya beast\n"+sx+"\n "+left+" guesses left\nold guesses: "+pr);
}
else if(gah==false)
{
JOptionPane.showMessageDialog(null,"Wrong guess ya beast\n"+sx+"\n "+left+" guesses left\n old guesses: "+pr);
}
if (end=true)
{
left=0;
}
}while(left!=0);
System.out.println("It gets here");
if(win==true)
{
JOptionPane.showMessageDialog(null,"Congratulations, you won\nThe correct word was '"+input+"'");
new Gam3r();
}
else if(win==false)
{
JOptionPane.showMessageDialog(null, "All out of guesses, try again");
new Gam3r();
}
}
public static void main(String[]args)
{
new Gam3r();
}
}