//this is the game engine program for Hangman

import WordList;//imports the dictionary

import java.util.*;

import java.util.Random.*;

class HmGame

{

private WordList word;//reference to dictionary

private char[] rightletters,wrongletters;//arrays to hold correct and wrong characters

private String select,clues;

private int random,total,trials,righttry,tries;

public HmGame()//constructs new game with word chosen,the clue,and the two character arrays

{

word=new WordList();

rightletters= new char[100];//correct character array

wrongletters=new char[100];//wrong character array

random=(int)(java.lang.Math.random()*word.getLength());//to select a random word

select=word.getWord(random);

clues=word.getClue(random);

empty(); //creater empty character arrays

total=0;//pointer for wrong character array

trials=0;// number of wrong tries

tries=0; //number of correct tries

}

public void empty()//constructs empty character arrays

{

for (int m=0;m<100;m++)

{

rightletters[m]=' ';

wrongletters[m]=' ';

}

}

public String getSelect() // returns word selected

{

return select;

}

public String getClues()// returns the clue for the word selected

{

return clues;

}

public char[] getrightChar() // returns the correct letters array

{

return rightletters;

}

public char[] getwrongChar()// returns the wrong letters array

{

return wrongletters;

}

public void compChar(char c)//compares letter entered to letters in word selected

{

righttry=0;

for(int m=0,i=0;(m<100)&& (i<6);m+=14,i++)//looks through every letter in word for the correct letter

{

if(select.charAt(i)==c){rightletters[m]=c;righttry++;}

}

if (righttry==0)//if no correct letters

{

trials++;//number of wrong tries incremented

wrongletters[total*10]=c;//puts wrong letter in wrong letters array

total++;//increases the pointer for the array

}

if (righttry==1){tries++;}//if one match is found increments number of correct try by one

if (righttry==2){tries+=2;}//if two matches ditto

if (righttry==3){tries+=3;}//if three matches

if (righttry==4){tries+=4;}//if four matches,no more likely

}

public int getTrials()//returns number of wrong tries

{

return trials;

}

public int getTries() // returns number of correct tries

{

return tries;

}

}