Hi, i've been working on a hangman java game. I have a lot of it coded, but when I go to run it, Im getting stuck somewhere I believe on line 64. I put a print statement before line 64 and it is printing it, then the program doesnt do anything but it is still running. Can anyone tell me what I have wrong in my program? Thanks.
/* * Mat2670 Homework 4 EX 1 * * Connor Moore * 03/07/2013 * * File: Hangman.java * This program gets a random word from a file that is * at least 5 characters long and lets a user play a * game of hangman. */ package mat2670; import java.util.*; import java.io.*; public class Hangman { private static final int LENGTH = 5; private static final int MAXGUESS = 6; private static final int NUMCHARS = 26; public static void main(String[] args) { Random rand = new Random(); ArrayList<String> words = new ArrayList<String>(); Scanner input = null; try { input = new Scanner(new File("/usr/share/dict/words")); } catch (FileNotFoundException ex) { System.err.print("File Not Found!"); } while (input.hasNextLine()) { String curWord = input.nextLine(); if (curWord.length() >= LENGTH) { for (int i = 0; i < curWord.length(); i++) { words.add(i, curWord); } break; } } String gameWord = words.get(rand.nextInt(words.size())); char[] displayWord = gameWord.toCharArray(); for (int k = 0; k < gameWord.length(); k++) { displayWord[k] = '_'; } Scanner console = new Scanner(System.in); char[] correct = new char[NUMCHARS]; char[] incorrect = new char[MAXGUESS]; int y = 0; System.out.print("here"); //print for debugging purpose while (!Arrays.equals(gameWord.toCharArray(), displayWord) && y <= MAXGUESS) { String guess = console.nextLine(); if (gameWord.contains(guess)) { int index = gameWord.indexOf(guess); for (int t = 0; t < gameWord.length(); t++) { displayWord[index] = guess.charAt(0); } } else { incorrect[y] = guess.charAt(0); y++; } System.out.println(displayWord); System.out.println(correct); System.out.println(incorrect); } } public static void drawBase() { echoString(" ", 4); echoString("-", 4); System.out.println(); System.out.println(" | |"); echoString(" |\n", 1); System.out.println(" ------"); } public static void drawHead() { echoString(" ", 4); echoString("-", 4); System.out.println(); System.out.println(" | |"); System.out.println(" O |"); echoString(" |\n", 1); System.out.println(" ------"); } public static void drawTorso() { echoString(" ", 4); echoString("-", 4); System.out.println(); System.out.println(" | |"); System.out.println(" O |"); System.out.println(" ! |"); echoString(" |\n", 1); System.out.println(" ------"); } public static void drawLeftA() { echoString(" ", 4); echoString("-", 4); System.out.println(); System.out.println(" | |"); System.out.println(" O |"); System.out.println(" /| |"); echoString(" |\n", 1); System.out.println(" ------"); } public static void drawRightA() { echoString(" ", 4); echoString("-", 4); System.out.println(); System.out.println(" | |"); System.out.println(" O |"); System.out.println(" /|\\ |"); System.out.println(" |\n"); System.out.println(" ------"); } public static void drawLeftL() { echoString(" ", 4); echoString("-", 4); System.out.println(); System.out.println(" | |"); System.out.println(" O |"); System.out.println(" /|\\ |"); System.out.println(" / |"); echoString(" |\n", 1); System.out.println(" ------"); } public static void drawRightL() { echoString(" ", 4); echoString("-", 4); System.out.println(); System.out.println(" | |"); System.out.println(" O |"); System.out.println(" /|\\ |"); System.out.println(" / \\ |"); echoString(" |\n", 1); System.out.println(" ------"); } private static void echoString(String s, int times) { for (int i = 1; i <= times; i++) { System.out.print(s); } } }
Ignore the ugly drawPieces methods I have, just typed them out in a hurry, but before changing and implementing them, i need my code working.