1.11M Members

Help with making Hangman work...?

 
0
 

So far, it's all working great, but all I need left is to get the method WORD1() to go to WORD2() when the person types in the correct letters. The first word is "Java". How would I make it so that when they type in "Java", it will go to WORD2()?

public static void main(String[] args) {
    
    STAND();
    WORD1();
    WORD2();
    
  }

  public static void WORD1() { //Java
    char[] JAVA = {'j','a','v'};
    char key = ' ';
    String done;
    
    c.setFont(new Font("arial", Font.PLAIN, 50));
    c.setColor(Color.BLACK);
    c.drawString("_", 251, 472);
    c.drawString("_", 287, 472);
    c.drawString("_", 322, 472);
    c.drawString("_", 357, 472);
    
    while(key != 'J' || key != 'A' || key != 'V' || key != 'j' || key != 'a' || key != 'v')
    {
      key = c.getChar();
      
      if (key == 'J' || key == 'j')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("J", 250, 470);
      }
      else if (key == 'A' || key == 'a')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("A", 285, 470);
        c.drawString("A", 355, 470);
      }
      else if (key == 'V' || key == 'v')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("V", 320, 470);
      }
      else if(JAVA[0] == 'j' && JAVA[1] == 'a' && JAVA[2] == 'v')
      {
        c.clear();
        counter = 0;
        STAND();
        WORD2();
      }
      else if(key != 'J' || key != 'A' || key != 'V' || key != 'j' || key != 'a' || key != 'v')
      {
        COUNTER();
        
        if(counter == 11)
        {
          c.clear();
          c.setFont(new Font("arial", Font.PLAIN, 25));
          c.setColor(Color.BLACK);
          c.drawString("You          him! Try the next word!", 125, 250);
          c.setColor(Color.RED);
          c.drawString("killed", 174, 250);
          
          c.setFont(new Font("arial", Font.PLAIN, 15));
          c.setColor(Color.BLACK);
          c.drawString("The next word will automatically start in 5 seconds.", 150, 275);
          
          WAIT();
          c.clear();
          counter = 0;
          STAND();
          WORD2();
        }
      }
    }
  }

  public static void WORD2() {
    //code here
  }
 
0
 

Help?

 
0
 

Arg, I don't have much time to finish this project. :/ I've been trying but can't seem to get it working.

 
0
 

The code you've posted looks like a collection of may different attempts to solve the problem and has gotten to be a mess.
Perhaps you should trash it and start over with a new design. Leave out the drawing and GUI stuff and just work on the logic of how to read in the letters and test when you have the correct letters in the correct sequence.

Start with creating new logic and then code it.

 
0
 

I would if I had the time to. This took long enough to make since I am a beginner.

 
0
 

How about starting with a simple version of the program where each WORDi method only needs to read in and accept/validate one or two letters instead of 4. When you get the logic worked out, then you could move to the 4 letters you are trying to process now.

 
0
 

I only need 5 words for this program. I just seriously need help doing the returning. Could you maybe show me how you'd do it?

 
0
 

My suggestion is to start with a simple program, figure out the logic for one letter for each method and when that works, move on to two letters for each method.
When you get that to work, you should have the idea on how to write the logic for more letters.

Good luck.

 
0
 

...how many times should I repeat myself? I'd like to stick with what I have but I'd like to learn how to use the returning.

 
0
 

No one is going to do your homework for you. Also you should keep in mind many schools automatically search forums and compare them to submitted homeworks. If you plan on taking code from forums you will most likely get caught and in trouble.

I suggest learning how to program and trying to do it yourself first. When you a problem then ask for a few pointers. No one is going to do all of your work for you.

 
0
 

I'm not asking for someone to do the homework for me. I'm just asking for an example of how I could use the returning in this situation so that I can implement it into it.

 
1
 

Here's a simple example:

private void aMethod(int x) {
  if (x < 10)  // Test if the value in range
     return;   // exit the method if too small
   // do other stuff here
} // end aMethod()
 
0
 

So, in this case should I be using ints or Strings?

 
0
 

Use ints for numberic data and Strings for string data.

I'm not sure what the "case" is you are talking about.

 
0
 

I'm still lost as to how I could make this work using returning. Sorry. :/

 
0
 

Please describe in more detail what you want your program to do.
You need to have a design for the program before you write it.
What you have posted now is a mixed up mess.

My suggestion is to start with a simple program, figure out the logic for one letter for each method and when that works, move on to two letters for each method.
When you get that to work, you should have the idea on how to write the logic for more letters.

 
0
 

Alright, sorry if I wasn't clear in the OP. The current problem is: once the person fills out the required letters for the first word ("Java"), it doesn't automatically go to the second word which is method WORD2().

In other words:

- I type "J", "A", and "V" into the keyboard, completing the word.
- When I have "JAVA" filled out, it doesn't automatically go to WORD2() as it should.

 
0
 

WORD1 should return to the calling method when it has received the 4 letters.
The calling method can then call the WORD2 method.
also the WORD1 method could return an error code if there was a problem to tell the calling method about it.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article