none
c sharp hangman project (IN DESPERATE HELP) RRS feed

  • Question

  • Hi I have a vs.net project and I need some help. Below is the project she gave us. Please use basic/low level codes

    Hangman

    Your challenge is to program Hangman! User should see the correct number of blanks for each letter in the word. The user is then supposed to guess one letter at a time. If it's correct, it should fill in the blank and show the correct hangman. If it is incorrect, it should add a body part (advance the hangman). It should also display the letters that have been used and print those on the screen to avoid repeats.

    Task 1: Request a word to be used for the game. Store user's input to a variable. (What data type is this?) Clear screen after storing. Use:  Console.Clear();

    Task 2: This word will be stored to a string array. You will need to use Substring. An example of how this may be used is:

    nameOfYourString.Substring (startIndex, length)

    where nameOfYourString is the name of the string to be converted to a string array, startIndex is the starting index (which letter of your string) that you'd like to store - remember this starts at 0! - and length is the length of the string you'd like to use - in our case, this will be one.

    Tip: If you are using a for loop, you can use .Length as the maximum for your counter, and your loop counter as your index variable for your array.

    Task 3: Create a function that will request user's guess for a letter and return it as a string to Main. If the user enters in more than one letter, it should let the user know and request input again.

    Tip: What kind of function is this? How can you run the error check?

    Task 4: Create another string array to store the user's guessed letters, that can be used to print to the screen after each guess. The values returned from Task 3 should be stored in this array.

    Tip: What kind of loop should you use for this?

    Task 5: Copy the function below that includes hangmen. Notice each picture has a new body part. What does the function do and how can you implement it in your own program? Alternatively, create your own hangman function that includes the output for each hangman display.

    Tip: Consider how many wrong answers will result in a loss?  

    Task 6: Compare the guessed answer choice with the string array for the word and replace the blanks as needed. In order to do this, you will need another(!) array, this time a bool array that will be used to indicate whether to print or not.

    Task 7: Make sure your program will tell the user if they win or lose. Make sure you have accounted for user errors like:

    • typing in more than one letter for the guess,

    • capital vs. lowercase letters (you can use nameOfString.ToLower)

    • user types in something other than letters

    • user types in same letter more than once

    Once complete, make sure you have commented your code (probably helpful to do as you go along) and run it multiple times to check for errors (this means more than once!).

           static string[] HangDudes()

           {

               string[] dudes = { @"

     +---+

     |  |

         |

         |

         |

         |

    =========", @"

     +---+

     |  |

     O  |

         |

         |

         |

    =========", @"

     +---+

     |  |

     O  |

     |  |

         |

         |

    =========", @"

     +---+

     |  |

     O  |

    /|   |

         |

         |

    =========", @"

     +---+

     |  |

     O  |

    /|\  |

         |

         |

    =========", @"

     +---+

     |  |

     O  |

    /|\  |

    /    |

         |

    =========", @"

     +---+

     |  |

     O  |

    /|\  |

    / \  |

         |

    =========" };

               return dudes;

           }


    Thursday, March 28, 2019 3:23 AM

All replies

  • We are not supposed to do homework assignments on this forum. If you have a go and get stuck, we can help you over the bumps, but we can't do the whole thing for you.

    What I will tell you is that this sort of project is very common, so entering "hangman c# code" (or something like that) into Google would probably help.

    Thursday, March 28, 2019 3:40 AM
  • Hangman can be more fun if randomly picking the word to guess from a string array, f.eks:

    public static string MakeWord() { //Makes an array of words and returns one random word
          string[] Words = new string[] {
    "Alfa Romeo",
    "Aston Martin",
    "Audi",
    "Bentley",
    "Benz",
    "BMW",
    "Bugatti",
    "Cadillac",
    "Chevrolet",
    "Chrysler",
    "Citroen",
    "Corvette",
    "DAF",
    "Dacia",
    "Daewoo",
    "Daihatsu",
    "Datsun",
    "De Lorean",
    "Dino",
    "Dodge",
    "Farboud",
    "Ferrari",
    "Fiat",
    "Ford",
    "Honda",
    "Hummer",
    "Hyundai",
    "Jaguar",
    "Jeep",
    "KIA",
    "Koenigsegg",
    "Lada",
    "Lamborghini",
    "Lancia",
    "Land Rover",
    "Lexus",
    "Ligier",
    "Lincoln",
    "Lotus",
    "Martini",
    "Maserati",
    "Maybach",
    "Mazda",
    "McLaren",
    "Mercedes",
    "Mercedes Benz",
    "Mini",
    "Mitsubishi",
    "Nissan",
    "Noble",
    "Opel",
    "Peugeot",
    "Pontiac",
    "Porsche",
    "Renault",
    "Rolls-Royce",
    "Rover",
    "Saab",
    "Seat",
    "Skoda",
    "Smart",
    "Spyker",
    "Subaru",
    "Suzuki",
    "Tesla",
    "Think",
    "Toyota",
    "Vauxhall",
    "Volkswagen",
    "Volvo"
                };

                Random random = new Random();
                int i = random.Next(Words.Length);
                string Word = Words[i];
                return Word;
            }

    • Edited by ThisNewbie Monday, April 1, 2019 3:45 PM
    Sunday, March 31, 2019 2:28 PM