Help! way in over my head.
Hi all, im pretty new to all this and im trying to code a hangman proggie (no gui) and ive totally hit a brick wall with it, any chance someone could give me a pointer what im doing wrong with this? t'would be much appreciated.
[b]mainclass:[/b]
public class hangMain
{
public static void main(String[] args)
{
char choice;
hangman game = new hangman();
do
{
System.out.println("Welcome to HANGMAN 2000!");
System.out.println();
System.out.println("1. Play HANGMAN 2000");
System.out.println("2. Quit.");
System.out.println("Please choose a menu option (1-2): ");
choice = EasyScanner.nextChar();
System.out.println();
switch (choice)
{
case '1': option1(game);
break;
case '2': break;
default:System.out.println("not a menu option.");
}
}
while (choice !='2');
}
public static void option1(hangman gameIn)
{
boolean result = gameIn.runGame(gameIn);
if(!result)
{
System.out.println("Congratulations, winner!");
}
else
{
System.out.println("Sadly, you lost. Better luck next time!");
}
}
}
hangman class:
public class hangman
{
char lastGuess;
char[] letters = new char[4];
char[] triedLetters = new char[5];
int startTries = 5;
int triesLeft;
int counter;
boolean win, lose;
public hangman()
{
lastGuess = ' ';
triesLeft = startTries;
counter = 0;
win = false;
lose = false;
char [] letters = {'_', '_', '_', '_'};
wordBank newWord = new wordBank();
String currentWord = (newWord.getWord());
char wordArray[] = currentWord.toCharArray();
}
public boolean runGame(hangman gameIn)
{
do
{
System.out.println(letters[0] + " " + letters[1] + " " + letters[2] + " " + letters[3]);
System.out.println();
System.out.println("Number of tries remaining: " + triesLeft);
System.out.println();
System.out.println("Please guess a letter: ");
lastGuess = EasyScanner.nextChar();
for (int x = 0; x < currentWord.length(); x++)
{
String tempGuess = String.valueOf(lastGuess);
String tempTarget = String.valueOf(wordArray[x]);
if (tempGuess.equalsIgnoreCase(tempTarget))
{
letters[x] = lastGuess;
}
else counter = counter + 1;
}
if (counter == 4)
{
triesLeft = triesLeft - 1;
}
if ((letters[0] == wordArray[0]) && (letters[1] == wordArray[1]) && (letters[2] == wordArray[2]) && (letters[3] == wordArray[3]))
{
System.out.println();
System.out.println("Well done!");
win = true;
return true;
}
if (triesLeft == 0)
{
lose = true;
return false;
}
}
while ((win == false) || (lose == false) );
}
}

