|
-
Newbie- Help with code
Hi,
I've been working on this code for a hangman game but have got a problem with it. The problem is that it only checks for the last letter of the secrect word.
Thanks in advance,
John.
public class HangmanGuts extends Frame
{
{
String CurWord = "";
String dashes = "";
int guesses;
guesses = 0;
int j;
int a;
int counter;
counter = 0;
String curChar = "";
String curCharDash = "";
String UserGuess;
String words[]={"Mountain", "Mole", "Locker", "Routier", "Grim", "Insult", "Indepedent", "Sandbag", "Proposal", "Cricket"};
a = (int)(Math.random() * 10);
CurWord = words[a];
dashes = "";
for (int i = 1; i<=CurWord.length(); i++)
dashes +="-";
System.out.println(CurWord);
System.out.println("Welcome to Hangman, type a letter and press enter");
for (int c=0; c<=10; c++)
{
UserGuess = "";
UserGuess = EasyIn.getString();
for (j=0; j <CurWord.length()-1; j++);
{
curChar = String.valueOf(CurWord.charAt(j));
curCharDash = String.valueOf(dashes.charAt( j ));
if(curChar.equalsIgnoreCase(UserGuess)&& curCharDash.equals("-"))
dashes = dashes.substring(0,j)+UserGuess+dashes.substring(j+1);
}
System.out.println(dashes);
if(counter == 10)
{
System.out.println("You lose!");
System.out.println("The word was "+CurWord);
counter = 0;
break;
}
else if(dashes.equalsIgnoreCase(CurWord))
{
System.out.println("You win!");
counter = 0;
break;
}
}
}
}
public class runHangman
{
public static void main(String args[])
{
HangmanGuts a = new HangmanGuts();
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks