Lab 8. Hangman



Hangman (Part 1)

Write an application that allows the user to play Hangman.

In the game Hangman, the player tries to guess a word or phrase (we will just be doing words) one letter at a time. The player has a finite number (we will use 7) of wrong guesses before they lose the game. If they guess the word in less than 7 guesses, they win.

For this lab, we will begin to program the game. Your next programming assignment will be to finish the game. No graphics are needed for this lab.

You will need the following controls to complete today's lab:

Example Layout (yours can look much nicer of course)

You do not need the submit word button, the textbox above it, or the reset button to get full credit for this lab. They are covered in the bonus section and will be part of Programming Assignment 3.

You will need the following variables to complete today's lab:

For today's lab, you should put all code in the button's click event function.

Algorithm for the button's click event function:

   if the length of the guess is not 1 (use the Len function)
      Output error message in a MsgBox
   else
      Get position of guess in word (use InStr function)
      if position = 0 (incorrect guess)
         decrement guesses left
         Output incorrect guess to label (use &= so you don't lose previous wrong guesses)
      else
         update guessed word variable (use Microsoft.VisualBasic.Left and .Mid functions) (see below)
         Output new guessed word to label
      end if
   end if
   if guessed word equals word to be guessed
      Output Player Wins
   else if guesses left = 0
      Output Player Loses
   end if

Updating guessed word variable:

To add the guess to the guessed word variable on a correct guess you will need to concatenate 3 strings to together.

The 3 strings:

  1. The portion of the guessed word to the left of the guess position.
  2. The guessed letter.
  3. The portion of the guessed word to the right of the guess position.

For example:


Bonus: Up to 30% possible (10% for each item)

These bonus items will be part of the final program turned in as Programming Assignment 3, so you will also have less to do for that if you complete one or more of these.