Results 1 to 1 of 1
Thread: Making hangman game
- 11-29-2010, 09:42 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
Making hangman game
So. I am making a hangman game. I am using the following code to pick a word.
Although, I'm really not quite sure the best implementation for this particular code.Java Code:package Hangman; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.File; import java.util.ArrayList; import java.util.Random; public class WordBank { public WordBank { /*declare an array list which doesn't have a set size and eliminates the need to know the size ahead of time. Meaning you can use any sized txt file*/ try { File words = new File("words.txt"); FileReader reader = new FileReader(words); BufferedReader in = new BufferedReader(reader); String string; while ((string = in.readLine()) != null) { wordlist.add(string); } in.close(); } catch (IOException e) { e.printStackTrace(); } } //return a random element of the array. Although,java's random generator //is not really as random as it could be. Def work on this later if time //allows private String WordPick(ArrayList<Object> x) { String word; Random generator = new Random(); int randomIndex = generator.nextInt(x.size()); word = (String) x.get(randomIndex); return word; } public String getAnswer() { String x = WordPick(wordlist); return x; } }
Any suggestions on how I could maybe make this a bit better because, at the moment I'm unable to really do much with it..
I was thinking that I could have a single class which outputs a word
From there have the word split up into individual letters and placed on JPanels with a - on them. As the user guessed the right word the program would go in and change the - to the letter or display the hangman panel and increase a counter.
Similar Threads
-
Hangman Game // HELP //
By K-Scale in forum New To JavaReplies: 4Last Post: 05-27-2010, 12:01 AM -
Hangman Game Help Please
By 9tjh in forum New To JavaReplies: 4Last Post: 12-04-2009, 03:19 AM -
Hangman Game..
By iPetey in forum New To JavaReplies: 4Last Post: 05-07-2009, 02:24 PM -
Need help with hangman game
By kurt in forum New To JavaReplies: 4Last Post: 04-25-2009, 06:47 PM -
Hangman Game
By L23 in forum New To JavaReplies: 8Last Post: 07-03-2008, 01:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks