Penn Foster Final Graded Project 03784400 Hangman Game
Now that you’ve completed the lessons and required textbook reading, you’re ready to put it all together for the final project. This project is a final assessment on the entire course and covers all the lessons. This is a new Windows application that’s not based on the output of any previous graded projects. You may find it helpful to review the instructions of previous graded projects and the completed output from Lesson 5 graded project.
Make sure that you follow all directions completely and verify your results before submitting the project. Remember to include all required components in your solution.
You’ve been tasked to create an educational game for a fifth grade reading class. The game must test student’s spelling skills using a variation of the classic game Hangman. If you’re unfamiliar with the rules and general game play, please consult the online reference at http://en.wikipedia.org/wiki/Hangman_(game) for more information.
The application will use the HangManDB.mdf file. The HangManDB database contains the tables in Figure 58. The UnitID column in the Words table is a foreign key to the ID column in the Units table. The Word column contains the actual word to guess, while the Description column contains the description of words for that unit.
The user interface will consist of a single Windows form. The user interface will resemble Figure 59.
When the application first loads, the textbox for the letter guess should be disabled (Figure 60). If the New option is chosen in the menu, then a new word and the unit description should be loaded from the database. If the Quit option is chosen in the menu, then the application should quit.
After each guess, one of two things should happen. If it’s a correct guess, then all occurrences of that letter should appear in the labels at the bottom. If it’s an incorrect guess, then the next stage of the hangman should appear in the picture box. In either case, the textbox should highlight the letter, so that the user can make another guess. The textbox should not be cleared or the user may attempt to guess the same letter (Figure 61).
The game ends when either all letters of the word are guessed correctly or the hangman picture is completed. When the game is won (Figure 62) or lost (Figure 63), a message box should display, prompting to play again.
In either case, clicking the Yes button should have the same effect as clicking the New option in the menu, and clicking the No button should exit out of the application.
This application will consist of the following files in the solution explorer:
1. GameForm.vb. The only form in the application.
2. HangmanDB.mdf. The database that contains the questions and unit descriptions.
3. Images folder. The images needed for the different visual states of the hangman.
4. QuestionDataSet.xsd. The DataSet for the HangmanDB database. Should contain both tables Words and Units.
HangmanDB.MDF and the Images folder will be provided to you.
You’ll be provided with the following files:
– The HangmanDB.mdf database
– The Images folder that contains the image files
Hangman-0.png, Hangman-1.png, Hangman-2.png, Hangman-3.png, Hangman-4.png, Hangman-5.png, and Hangman-6.png
– The HelperMethodsCode.txt file with suggested code
1. In Visual Studio, create a new Windows Forms Application project named HangmanApp.
2. Create the Images folder in the project by using the Add > New Folder option in the Solution Explorer or the New Folder option in the Project menu
3. Add each hangman image to the Image folder. You can either click and drag them into the Solution Explorer or use the Add > Existing Item… option and select all images using the Shift key. If using the second method, make sure to change filter to All Files (*.*).
4. In the Properties panel, set the Copy To Output Directory property to Copy Always for each image file. You can use the Shift key to select all image files at once.
5. Add the HangmanDB.mdf database to the project. Use the Add > Existing Item… option. Make sure to change filter to All Files (*.*).
6. In the Data Source Configuration Wizard dialog, choose the DataSet option and then click the Next button.
7. Check the checkbox next to Tables and then click the Finish button. This will create a default dataset named HangmanDBDataSet with the Units and Words data tables.
8. Rename the Form1.vb file to GameForm.vb.
9. Click the Yes button in the dialog to rename the Form1 class as well.
10. Create the user interface for GameForm.vb. See the User Interface section above for the layout. The form will consist of the following controls:
a. One MenuStrip control that contains the Game menu with the options New and Quit.
b. One Label control for instruction with the text Guess a letter; 14-point font recommended.
c. One Label control for the unit description.
d. One TextBox control for the user to type in letter choices.
e. A PictureBox control that will display the hangman images. You’ll set the ImageLocation property to load the hangman images.
f. A Panel control that will contain the displayed letter labels.
g. Eleven Label controls, one for each letter of the word. These labels should be in the panel and will have an initial placeholder until the user guesses a letter.
You can choose to set the control properties to whatever you like, but below are some helpful suggestions. If you don’t name the controls with the recommended names, you will need to modify some provided code shown in Table 4.
6. In the body of GameForm, you should define the following variables:
a. dsQuestions. A HangmanDBDataSet object
b. numWord. The index of which word is being guessed.
c. strWord. The actual word being guessed.
d. numRightGuesses. Number of right guesses in a game.
e. numWrongGuesses. Number of wrong guesses in a game.
f. blnGameStarted. Indicates whether the game has started or not.
7. In the body of GameForm, you should define the following utility methods:
a. A method named CheckProgress that calculates the total number of tries (numRightGuesses + numWrongGuesses), displays the correct message box for winning or losing, and starts the next game or exits the application depending on the message box button
b. A method named WonGame that checks each letter in the word is matched by its label and returns True if this is the case
c. A method named LostGame that checks to see if the number of wrong guesses is greater than six and returns True if this is the case
d. A method named ResetAllLabels that sets each character label to blank text
8. Open the HelperMethodsCode.txt file and copy and paste its contents into the GameForm class.
Note: These handy methods will reduce your development time. Think of it as help from a colleague, because you’ll rarely develop a business application alone and most often will work within a team.
9. In the body of GameForm, you should have the following event procedures:
a. Form Load event handler. Disable the txtGuess textbox, initialize numWord to -1 to indicate no word has been chosen, and call the LoadData method.
b. Quit button Click event handler. Exit the application
c. In the New button Click event handler, perform the following tasks:
I. Initialize all variables, especially numRightGuesses, numWrongGuesses, blnGameStarted, and numWord. Make sure to increment numWord to the next index. Each game will increment this number by one.
II. Initialize controls. Clear the text of all controls, including the labels, textbox, and picture box. For the picture box, you can just set its ImageLocation to “”.
III. Enable and set the focus of the txtGuess textbox.
IV. Set controls using the DataSet. If you followed the same names, then you can use this code:
‘Get a word column row
strWord = CStr(dsQuestions.Words(numWord)(1))
lblUnitDescription.Text = CStr(dsQuestions.Words(numWord).UnitsRow(1))
V. Set the Text property to the underscore character (_) for each label control based on the number of characters in the word.
D. In the txt Guess text box Text Changed event, perform the following tasks:
I. Check if the game is started using the blnGameStarted variable and that the txtGuess textbox contains a value. Clearing a textbox will trigger a TextChanged event, so you’ll need to
verify a letter was actually typed by the user.
II. Check to see if the word (strWord) contains the guess (txtGuess).
III. If it does, then call the SetRightLetterLabels method and increment the numRightGuesses variable.
IV. If it doesn’t, set the image in the pboxHangman and increment the numWrongGuesses variable.
Your code should resemble the following:
pboxHangman.ImageLocation =”images\Hangman-” & numWrongGuesses & “.png”
numWrongGuesses + = 1
V. Check to see if the game has been won or lost yet. Use the CheckProgress method.
VI. Select the text in the txtGuess textbox.
10. Save and run the application. Verify that all controls and menus work correctly. You’ll submit the compiled application for this project.
You’ll submit the HangmanApp.exe file for your project.
To find this file, you should go to directory to where you saved the HangmanApp project and copy the HangmanApp.exe file from the bin\Debug folder. Make sure the HangmanApp.exe file executes before submission. The Images folder and HangmanDB.mdf must be in the same directory as the HangmanApp.exe to execute as expected.
Use the following procedure to submit your project online:
1. Log in to view your student homepage and go to the My Courses page.
2. Click the Take Exam link next to the lesson you’re working on.
3. Attach our files as follows:
a. Click the Browse button.
b. Locate the file you wish to attach.
c. Double-click on the file.
d. Click the Upload File button.
4. Enter your email address in the box provided.
(Note: Your email address is required for online submissions.)
5. If you wish to include comments about this project to your instructor, enter your comments in the Message textbox.
6. Click Submit Files.