Epco Elstak

Greenhorn
+ Follow
since Oct 24, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Epco Elstak

Hey folks,
I have a serious question here. I made a hangman game see below:

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Hangman
{

public static void main(String args[])
{
Hangman epco = new Hangman();
epco.startSpel(args[0]);
}

private int aantalBeurten = 7;
private int aantalFouten = 0;
private StringBuffer teRadenWoord;
private StringBuffer raadWoord;
private boolean nogNietGewonnen = true;
private int aantalGoed = 0;

private char readChar(){

char c = ' '; BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try
{
String s = reader.readLine();
c = s.charAt(0);
}
catch (Exception e) {}
return c;

}

public boolean checkWoord(StringBuffer attempt, StringBuffer endResult)
{
boolean notFound = false;
for (int i = 0; i < endResult.length(); i++)
{
if (attempt.charAt(i) != endResult.charAt(i))
{
notFound = true;
}
}
return notFound;
}

public void maakHetRaadWoord(){

raadWoord = new StringBuffer("");
for (int i = 0; i < teRadenWoord.length(); i++)
{
raadWoord.append(".");
}
}
public void startSpel(String woord)
{
teRadenWoord = new StringBuffer(woord);
System.out.println("Help mij! je hebt 8 kansen om te zorgen dat ik niet word opgehangen!");
maakHetRaadWoord();

while (nogNietGewonnen == true && aantalBeurten >= aantalFouten)
{
aantalGoed = 0;
System.out.println("Vul een letter in, zorg dat het een goede is! ");
System.out.println("het woord tot nu toe --> " + raadWoord.toString());
char letter = Character.toLowerCase(readChar());
if (Character.isLetter(letter))
{

System.out.println("Ingevulde letter: " + letter);
for (int i = 0; i < teRadenWoord.length(); i++)
{
if(teRadenWoord.charAt(i) == letter)
{
raadWoord.setCharAt(i, letter);
aantalGoed++;
}

}
nogNietGewonnen = checkWoord(raadWoord, teRadenWoord);

if (aantalGoed == 0)
{
aantalFouten++;
System.out.println("Dit is onjuist, ik hang bijna!");
System.out.println("beurt" +aantalFouten);
}
}
else
{
System.out.println("Dit is geen Letter. Vul een letters in om het woord te raden!");
}
}

if (nogNietGewonnen == false)
{
System.out.println("Je hebt me gered, ik sta bij je in het krijt!");
System.out.println("Het woord is " + teRadenWoord + ".");
}
if (aantalFouten == 8)
{
System.out.println("Je hebt me laten ophangen, ik rekende op je");
System.out.println("Het juiste woord was " + teRadenWoord + ".");
}
}

It's almost done, though I have to do 2 more things, and I can't figure out how to do it.
First I have to add a code that checks if the user used a letter twice, even it's upper case or not (example T/t). And if so the programme needs to say that the user already used that letter.

Second thing is, I have to delete the "char letter = Character.toLowerCase(readChar());" part, and make a stringbuffer of it and use equalsIgnoreCase instead.

I would appreciate any help, I need to post it in 2 days.
thanks in advance!
13 years ago