1,105,578 Community Members

Help with making Hangman work...?

Member Avatar
Feriscool
Light Poster
41 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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
  }
Member Avatar
Feriscool
Light Poster
41 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Help?

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
0
 

When the method WORD1 has the 4 letters required, have it do a return.
Execution will then return to the main method where WORD2 will be called.

See cross post at:
http://www.java-forums.org/new-java/43960-hangman.html#post208262

Member Avatar
Feriscool
Light Poster
41 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
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.

Member Avatar
Feriscool
Light Poster
41 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
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.

Member Avatar
Feriscool
Light Poster
41 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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?

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
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.

Member Avatar
Feriscool
Light Poster
41 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
0
 

Go to this site and search for return. It has an explanation and examples.
http://download.oracle.com/javase/tutorial/reallybigindex.html

Then write a small, simple program and test the two ways to use the return statement.

Member Avatar
\007
Junior Poster in Training
61 posts since Apr 2011
Reputation Points: 7 [?]
Q&As Helped to Solve: 8 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
Feriscool
Light Poster
41 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
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()
Member Avatar
Feriscool
Light Poster
41 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
0
 

Use ints for numberic data and Strings for string data.

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

Member Avatar
Feriscool
Light Poster
41 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
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.

Member Avatar
Feriscool
Light Poster
41 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article