Thread: Ghetto Hangman!

Results 1 to 4 of 4
  1. #1 Ghetto Hangman! 
    Registered Member MinimumUzinium's Avatar
    Join Date
    Nov 2011
    Posts
    108
    Thanks given
    3
    Thanks received
    7
    Rep Power
    8
    Why is it ghetto? I was too poor to afford a person.

    All I need to know is how to print '-----' and then the letter in which they guess right. Anyone know how?


    Code:
    /**
     * TODO:
     * Make it print dashes for the letters.
     * Make it print the letter where index is.
     * Make it continue after start.
     * Add letter to the continue method.
     * Compare random word and selected indexes.
     * Find index of random word, use that index to put the letter into that index
     * then replace the '_' with the letter with that index.
     * Index with Element of the word
     * ...
     */
    
    
    
    /** Import necessary packages*/
    import java.util.Random;
    import javax.swing.JOptionPane;
    import java.util.Scanner;
    import java.lang.String;
    
    public class Hangman extends BasicGame
    {
        /**Call all of the variables*/
        Random randy = new Random();
        private int guesses;
        private final int maxGuesses = 6;
        private String myGeneratedRandomWord = getWords();
        private String letter;
        private char letterSelected;
        private String[] words = {"apple", "beret", "arose", "along", "beamy", "becks", "decks", "barks",
                                  "stark", "start", "stabs", "baggy", "asked", "asset", "asses", "audit",
                                  "bowls", "boxes", "seats", "balls", "boats", "boxer", "brick", "bound",
                                  "brass", "caked", "braid", "caged", "essay", "fault", "dents", "dutch",
                                  "ethos", "dunks", "pains", "faxes", "mummy", "mixer", "mills", "might",
                                  "moral", "teeth", "wings", "works", "walls", "tolls", "crawl", "toxin",
                                  "bangs", "tough"};
        
        /**Get the random word from the array*/
        public String getWords (){
            String randomWord = words[randy.nextInt( words.length)];
            return randomWord;
        }
        
        /**Get the indexes of the letter of the random word indices don't start with 1*/
        public char getSelected(){
            return letterSelected;
        }
        
        /**Finds index of the letter of randomWord*/
        public int getIndex(){
            int index = getWords().indexOf(getSelected());
            return index;
        }
        
        /**Get the first input, set strikes to zero, get the random word*/
        public void start(){
            guesses = 0;
            getWords();
            String s = JOptionPane.showInputDialog(null, "Make your guess!");
            letterSelected = s.charAt(0);
            if(myGeneratedRandomWord.indexOf(letterSelected ) != -1) {
                // it contains the letter
                
           }
           else {
                // wrong guess
                guesses++;
           }
        }
        
        /**Continue the game on, checks if the letter is there if not then apply the letter*/
        public void continueGame(){
           String s = JOptionPane.showInputDialog(null, "Make another guess!");
           letterSelected = s.charAt(0);
           if(myGeneratedRandomWord.indexOf(letterSelected ) != -1) {
                // it contains the letter
                getIndex(getWords());
           }
           else {
                // wrong guess
                guesses++;
           }
        }
        
        /** Runner basically*/
        public void mainScreen (){
            start();
            while (guesses != maxGuesses){
                continueGame();
                checkBodyParts();
            }
            gameOver();
        }
        
        /**Gets the */
        
        
        /**After certain strikes head is called etc.*/
        public void checkBodyParts(){
            if(guesses == 1){
                JOptionPane.showMessageDialog(null, "You now have a head! Wrong guesses left: 5");
            }
            if(guesses == 2){
                JOptionPane.showMessageDialog(null, "You now have a body! Wrong guesses left: 4");
            }
            if(guesses == 3){
                JOptionPane.showMessageDialog(null, "You now have a right arm! Wrong guesses left: 3");
            }
            if(guesses == 4){
                JOptionPane.showMessageDialog(null, "You now have a left arm! Wrong guesses left: 2");
            }
            if(guesses == 5){
                JOptionPane.showMessageDialog(null, "You now have a right leg! Wrong guesses left: 1");
            }
            if(guesses == maxGuesses){
                JOptionPane.showMessageDialog(null, "You lose!");
            }
        }
        
        /**You lose.*/
        public void gameOver(){
            JOptionPane.showMessageDialog(null, "Game Over!");
            System.exit(0);
        }
    }
    Reply With Quote  
     

  2. #2  
    Registered Member
    Mister Maggot's Avatar
    Join Date
    Dec 2008
    Posts
    7,246
    Thanks given
    3,283
    Thanks received
    2,874
    Discord
    View profile
    Rep Power
    5000
    Post the stack trace.
    Reply With Quote  
     

  3. #3  
    Registered Member MinimumUzinium's Avatar
    Join Date
    Nov 2011
    Posts
    108
    Thanks given
    3
    Thanks received
    7
    Rep Power
    8
    Quote Originally Posted by Mister Maggot View Post
    Post the stack trace.
    Stack trace?

    UPDATED project.
    Reply With Quote  
     

  4. #4  
    Registered Member MinimumUzinium's Avatar
    Join Date
    Nov 2011
    Posts
    108
    Thanks given
    3
    Thanks received
    7
    Rep Power
    8
    Quote Originally Posted by Kamiel View Post
    Are you using a JFrame for a simple GUI? As I don't know where you want to print your lines on, I can't really help you.





    He's not getting an exception. It's just a question on how he's supposed to do it.

    I want to print the word on a messageDialog.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Ghetto
    By Aeon in forum Humor
    Replies: 0
    Last Post: 09-13-2010, 06:09 AM
  2. Ghetto Fights.
    By Payton in forum Videos
    Replies: 24
    Last Post: 07-14-2010, 08:12 AM
  3. [Ghetto] Turmoil on 317.
    By dang3r in forum Show-off
    Replies: 14
    Last Post: 04-26-2010, 04:04 AM
  4. Ghetto bus pls?
    By Steel in forum Videos
    Replies: 20
    Last Post: 10-07-2008, 02:40 AM
  5. Ghetto Gameframe
    By T in forum Graphics
    Replies: 8
    Last Post: 07-02-2008, 03:06 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •