Need help to make A Hangman

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    #16
    Originally posted by Need help54321
    Ok Will for The hang man i idea i was just going to go something like _ _ _ _ _ ok and if u miss a letter a message will pop up and say sory that is incorrect u have 6 guess left then that avoids the hole picture of the hangman and keeps it a little less complex
    That a great ideal.
    I think you can use ASCII Characters for the alphabet and for - and ' .
    ie
    Code:
    for (var i = 65; i <= 90; i++)
    //65 is the letter A an so on down the line.
    I don't yet know How you can call the ASCII Code.
    Many be someone can help you with that.

    For ramdom words make a array if you are going to do it that way.

    nomad

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #17
      Originally posted by nomad
      I think you can use ASCII Characters for the alphabet and for - and ' .
      ie
      Code:
      for (var i = 65; i <= 90; i++)
      //65 is the letter A an so on down the line.
      I don't yet know How you can call the ASCII Code.
      Here's a tip for both of you: don't ever do that. The only numeric literal constants
      in a piece of code should be plus or minus one or zero. All other constant values
      are considered 'magic' and very bad practice. Leave that loop like this:

      [code=java]
      for (char i= 'A' i <= 'Z'; i++) ...
      [/code]

      And while I'm at it: String operations don't require much looping; it's all so very
      'mechanical'. Use the String class's methods and pay special attention to the
      regular expression methods, e.g. given the secret word "apple" and a guess
      (a single character String), the following does this:

      [code=java]
      String secret= "apple"; // the secret word
      String correctChars= "p"; // previously correctly guessed chars
      String guess= "e"; // the new guess
      String newSecret= secret.replaceA ll("[^"+correctChars +guess+"]", "-");
      [/code]

      The value of newSecret will be equal to "a--l-"; if you want to make sure that
      the remaining new 'secret' doesn't contain any hidden letters do this:


      [code=java]
      boolean win(String secret, String correctChars) {
      String temp= secrect.replace All("[^"+correctChars +"]", "-");
      return temp.indexOf('-') < 0;
      }
      [/code]

      now go and read the API docs and figure it out for yourself ;-)

      kind regards,

      Jos

      Comment

      • Need help54321
        New Member
        • Jun 2007
        • 30

        #18
        Originally posted by JosAH
        Here's a tip for both of you: don't ever do that. The only numeric literal constants
        in a piece of code should be plus or minus one or zero. All other constant values
        are considered 'magic' and very bad practice. Leave that loop like this:

        [code=java]
        for (char i= 'A' i <= 'Z'; i++) ...
        [/code]

        And while I'm at it: String operations don't require much looping; it's all so very
        'mechanical'. Use the String class's methods and pay special attention to the
        regular expression methods, e.g. given the secret word "apple" and a guess
        (a single character String), the following does this:

        [code=java]
        String secret= "apple"; // the secret word
        String correctChars= "p"; // previously correctly guessed chars
        String guess= "e"; // the new guess
        String newSecret= secret.replaceA ll("[^"+correctChars +guess+"]", "-");
        [/code]

        The value of newSecret will be equal to "a--l-"; if you want to make sure that
        the remaining new 'secret' doesn't contain any hidden letters do this:


        [code=java]
        boolean win(String secret, String correctChars) {
        String temp= secrect.replace All("[^"+correctChars +"]", "-");
        return temp.indexOf('-') < 0;
        }
        [/code]

        now go and read the API docs and figure it out for yourself ;-)

        kind regards,

        Jos


        Lol Is this going to be hard i think lol i dont no if my java skills r up for it but im gonna have to try cayuse i need to make a game in 2 weeks lol so ill give it a shot

        Comment

        • DeMan
          Top Contributor
          • Nov 2006
          • 1799

          #19
          With two of you (you and nomad) attempting to work through the problem for the first time, it will be easier, and if you both run into strife, some of the experts here will help you out. Usually the biggest hurdle is starting....

          Comment

          • Need help54321
            New Member
            • Jun 2007
            • 30

            #20
            Originally posted by nomad
            That a great ideal.
            I think you can use ASCII Characters for the alphabet and for - and ' .
            ie
            Code:
            for (var i = 65; i <= 90; i++)
            //65 is the letter A an so on down the line.
            I don't yet know How you can call the ASCII Code.
            Many be someone can help you with that.

            For ramdom words make a array if you are going to do it that way.

            nomad

            Ok so Nomad how do u want to do this im thinking a simple as posable so like we wont have a hangman picture just _ _ _ _ and i think maybe just type in the letter rather then click it what u think?

            Comment

            • Need help54321
              New Member
              • Jun 2007
              • 30

              #21
              Man i think we sould try and get this game running with just one word then add on from there like just keep it very simple and basic what u think?

              Comment

              • DeMan
                Top Contributor
                • Nov 2006
                • 1799

                #22
                Good idea...,
                We can cut this into a series of programs that build on the previous.

                1) write a program that displays a string on the screen (done - "hello world")
                2) write a program that takes a character as input an displays in on the screen.
                3) write a program that stores characters entered in a list an can tell a user if a character has previously been selected
                4) Using JosAH's suggestion before, expand (3) to show all the characters in (1) that have been correctly guessed.

                That should be a good start, post again when you need more help.

                Comment

                • nomad
                  Recognized Expert Contributor
                  • Mar 2007
                  • 664

                  #23
                  Originally posted by Need help54321
                  Man i think we sould try and get this game running with just one word then add on from there like just keep it very simple and basic what u think?
                  That will be find. Since this is your class project I will try to help you as best as I can. You need to do the work, but I will give you clues and help you when you get stuck along with the real pros here at thesripts.

                  nomad

                  Comment

                  • DeMan
                    Top Contributor
                    • Nov 2006
                    • 1799

                    #24
                    Originally posted by nomad
                    That will be find. Since this is your class project I will try to help you as best as I can. You need to do the work, but I will give you clues and help you when you get stuck along with the real pros here at thesripts.

                    nomad
                    Sorry I thought you were MIA.....I'll leave you to it....

                    Comment

                    • nomad
                      Recognized Expert Contributor
                      • Mar 2007
                      • 664

                      #25
                      Originally posted by DeMan
                      Sorry I thought you were MIA.....I'll leave you to it....
                      I will need help as well. I'm just took one class and I want to modivate others like Jos did for me. I enjoy helping others. I have Ideal on how to do it but will it work that's the big question.

                      Comment

                      • DeMan
                        Top Contributor
                        • Nov 2006
                        • 1799

                        #26
                        That's good!!!
                        If you help "Need help54321" with what you know, and we'll keep an eye on this thread, and help out whenever you get stuck or run into any difficulty.

                        Comment

                        • Need help54321
                          New Member
                          • Jun 2007
                          • 30

                          #27
                          Ok will i didnt really like the hangman thing so i decided to switch to a mini putt heres what i got could anyone tell me how to get the course and the ball to pop up togher cause i can only get one or the other and could someone tell me how to get the ball to move?please


                          import javax.swing.*;
                          import java.awt.*;
                          public class FristPanel
                          {
                          public static void main(String args [])
                          {
                          JFrame jf1 = new JFrame("This Is the First Frame");
                          JLabel lbl1 = new JLabel();
                          JLabel lbl2 = new JLabel();
                          jf1.setSize(500 ,500);
                          Container c = jf1.getContentP ane();

                          ImageIcon icon = new ImageIcon("Golf .jpg");
                          lbl1.setIcon(ic on);

                          c.add(lbl1);

                          ImageIcon icon2 = new ImageIcon("golf ball.jpg");
                          lbl2.setIcon(ic on2);

                          c.add(lbl2);

                          jf1.setVisible( true);

                          }
                          }

                          Comment

                          • JosAH
                            Recognized Expert MVP
                            • Mar 2007
                            • 11453

                            #28
                            Originally posted by Need help54321
                            Ok will i didnt really like the hangman thing so i decided to switch to a mini putt heres what i got
                            So you're simply bailing out without solving anything and leaving everything and
                            everybody behind? Ok, success with your endeavours then.

                            Jos

                            Comment

                            • Need help54321
                              New Member
                              • Jun 2007
                              • 30

                              #29
                              Originally posted by JosAH
                              So you're simply bailing out without solving anything and leaving everything and
                              everybody behind? Ok, success with your endeavours then.

                              Jos
                              No my teacher didnt like the idea of hangman i dono y

                              Comment

                              • blazedaces
                                Contributor
                                • May 2007
                                • 284

                                #30
                                Originally posted by Need help54321
                                No my teacher didnt like the idea of hangman i dono y
                                Your abilities reflect poorly on your teacher. Your misunderstandin g as to why he didn't "like the idea of hangman" only worsens his image.

                                Unfortunately, I don't know the nature of this assignment, nor what goals this teacher has in teaching you java. It's only frustrating because you (and many people here) contributed much effort into procuring this project (and we barely scratched its surface. It really seemed like you could have learned a lot from the process. But now you will move on to something relatively unimportant just because the teacher might like the idea of visualizing golf balls.

                                In my educated opinion mini-put stresses syntax (java visual/GUI specifics, the not-so-important step in programming) and ignores problem-solving/logic puzzles (the HOW do you do this or that, the psuedocode that is so hard for people to think up when they first start programming).

                                This is the very problem with most programming-teaching guidelines in our education system today (keep in mind, this is an educated opinion of my own, feel free to disagree).

                                *Stops self from going into philosophical debate on today's education system*

                                Good luck with your program and sorry if I went a bit too far with this post,
                                -blazed

                                Comment

                                Working...