Write a VB program that implements the classic game of Hangman.





·         The program will require three data files:


(1)        The main file, called HMPuzz.dat, which contains the puzzles that the user must solve. This is a comma-delimited file containing two fields:

(a)        The puzzle, which is a string containing up to 20 characters. The puzzles will contain only letters and blank spaces (no special characters such as hyphens, commas, or quotes).

(b)        A "clue code",  which is an integer between 1 and 5 representing a clue that can be displayed to the user on the gameboard.


A sample set of records is shown below:









(2)        A "lookup table", called HMClues.dat, which contains two fields: (a) the "clue code" (an integer between 1 and 5) and (b) the clue description.  This file contains the following data:







(3)        A file called LastPuzz.dat, which simply contains one record with one field: a number indicating the last puzzle that was played, which will serve as a starting point for a new run of the program. This enables you to vary which puzzles are used from session to session.


At program startup, load the data from the first two files into arrays and store the "last puzzle" number into a variable. When the program first begins, and whenever the user clicks the "New Game" button, increment the "last puzzle" value and select the puzzle from the array of  puzzles loaded from the first file using the "last puzzle" value as an index into the array.


·         Visually present the "covered up" puzzle to the user, along with the hangman's gallows (which can be simply drawn with line controls), and a pool of the 26 letters of the alphabet (these can be labels or command buttons). Also display a clue description associated with the puzzle.


·         When the user clicks a letter, if any occurrences of that letter are present in the puzzle, reveal them all to the user; if that letter is not present in the puzzle, then draw another body part on the "hanged man".  In any event, disable the chosen letter.


·         The hanged man has six body parts: a head, a torso, two arms and two legs.  All parts can be created with the line control, except the head, which can be created with the circle option of the shape control.  If the hanged man is drawn before all the letters of the puzzle are revealed, the player loses; if the all the letters of the puzzle are revealed before the hanged man is drawn, the player wins.


·         Provide a "solve the puzzle" option, which enables the player to guess the answer early in the game.  If the player guesses correct, the player wins; otherwise, the player loses.


·         The program should provide options to play a new game and to quit.




Following are some screen shots of my version of this program, to give you some ideas.  Feel free to vary the design any way you want, as long as the project requirements are met.


Splash Screen




 When game first begins




While game is in progress




When player wins



 When player loses





The "Solve Puzzle" Option …



Note: If you implement the "Solve Puzzle" option with an InputBox as I did, make sure you parse the user's response so that an entry that contains lowercase letters and/or extra spaces will not count against the user when you compare the user's response to the answer.


Download the solution for this project here.