Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Modified Hangman Solution advanced VB Final

Options
  • 13-05-2008 1:56am
    #1
    Closed Accounts Posts: 2


    I am a student in Advanced Visal Basic(on-Line). I need help modifying HangMan solution(final Project). I am a real novice and did well until the final project. Now it all seems over my head.
    I have copied the GUI and citeria for project. I think I have the Load Event procedure but thats it.:(

    Advanced Visual Basic Final Project
    Task: Enhance a working project
    Students will be provided with the solution file for the Hangman Game of Chapter 8. Students are to modify the working solution to provide enhancements.
    1. Create a folder on your computer DESKTOP called "Advanced VB Final Solution Zip Files". Download and store the "Adv VB Final Project.zip" file provided by the instructor into this folder. Right Click and Extract (unzip) the file into the default folder. You should end up with 3 solutions and my solution executable:
    (LAST NAME – The Hangman Game) – This is the GUI for you to use to code the solution. I added some comment code to the code window to help guide you but you create the code to make it work. I included three sequential text files of words and the password.dat file to start with. You may change the GUI to your own taste as long as the final code works per the instructions.
    (Sample Code Help Files) – This is some sample code to help you understand the concepts of working between text files and the GUI as well as how to use multiple forms. This is SAMPLE code, you need to look at the code and understand what each line is doing. You can NOT SIMPLY cut/paste the sample code into your program, it will not work, but you can use the concepts. You can cut/paste and change object control names or variable names or create appropriate variables in your code to make it work. I sent out the "Pizza Practical" solution earlier in the term –it has some good code for working with controls in an array (ie clear all labels at one time). This may help you with resetting all labels in the used words group box to "invisible".
    (Working Solution Hangman Game Starting Code) – This is WORKING code for the hangman game where the student enters a new word then the game begins. Like the sample code you can cut/paste but you will have to modify things like control and variable names.
    (Dr Dunn Executable Program) – This is the executable of my solution so you can see the final project (similar to what you did at the beginning of each chapter – shows you what the working code looks like – NOTE: This is NOT the solution code, just the executable so you can see it working.
    2. RIGHT CLICK on the "LAST NAME - The Hangman Game" folder then select COPY. Go your DESKTOP and PASTE the starting program files. CHANGE THE name of the solution folder by substituting YOUR last name for "LAST NAME".
    (I recommend that you keep the zip files in the Advanced VB Final Solution Zip Files" folder in case you need to restore the solution again.)
    3. Open the Solution File from "LAST NAME - Advanced VB Final Solution" folder. Modify the solution based on the enhancements below.
    4. Zip the LAST NAME - Advanced VB Final Solution folder and return to Dr Dunn by the due date
    Overview of Enhancements
    CURRENT PROJECT: User starts a new game from the File Menu then enters a word in an input box, the GUI displays dashes for the words and the user guesses letters. If the user guesses incorrectly, the hangman image builds. Either the user guesses the word correctly or the hangman image is completed and the user loses.
    ENHANCEMENTS:
    Change the game interface to select 20 words from one of three different text files that the teacher manages instead of the student entering a word in an input box.
    Add a data management form for the teacher to manage the lists of words that populate the game.
    CODING LOGIC:
    Text Files – the text files are 21 lines. The first line is the "Category Title" and the next 20 lines are the words for the students to guess from.
    Main Form
    LOAD EVENT
    Open and read words from sequential access files (one at a time)
    Put 1st word (category title) into text property of the category radio buttons
    Trigger category 1 radio button performclick event
    This will cause category 1 button to execute which loads the words from cat1.txt
    CATEGORY RADIO BUTTON (Allows students to change categories of words)
    Clear labels, variables, counters
    Open and read words from the appropriate sequential access file
    Put 1st word (category title) into category radio button text property
    Put remaining 20 words into a one-dimension array
    Create parallel one-dimension array to store words ‘used’ to avoid repeating a word. (get the 1st word from the sequential access file and put in words(1) [remember, the "first" word in the file is the category title so the second line is first word we use in the game] and populate used(1) with FALSE to indicate it hasn’t been used.) Later, the random generator says to get word(1) you check used(1) to see if it is FALSE – if FALSE then it hasn’t been used so use it for the game and set used(1) to TRUE.

    GET NEW WORD
    Check to see if all 20 words have been used
    If Yes – ask if they want a new game (reset the game)
    If No - continue
    Call random number generator to get number from 1 to 20
    Check to see if word has been used: used(x) = T or F
    If FALSE
    Get that numbered word from the words(x) array
    Assign to the word variable and play the game
    Set used(x) to TRUE to indicate word has been used
    Increment number of words used
    If TRUE
    Call random number generator again (button1.performclick method)
    PLAY GAME
    Play game as per the working model provide
    Change method of displaying letters used from a string of letters to the Used Letters Group box
    Track/display number of words and correct words
    TEACHER LOGIN BUTTON
    Read password.dat file and assign current password to a variable
    Use Input box to get teacher to enter password (NOTE: Default pw-"hangman")
    Verify password against password from "password.dat" file
    If correct – load data management form
    If incorrect return display error message and return to main form
    DATA MANAGEMENT FORM
    LOAD EVENT
    Read sequential access file – add word to list boxes (1st word to category heading box, remaining words to words list box)
    Repeat for other 2 files

    CHANGE PASSWORD
    Use input box to get current password from teacher
    Verify current pw is correct
    If correct use input box to get new password
    Use input box to get password a second time
    Verify that newpw1 = newpw2
    If correct, write newpw1 back to password.dat file
    If incorrect (don’t match) give warning message and repeat input boxes
    DELETE WORD
    User selects words in the list boxes (use ctrl-click to select multiple words)
    Prompt for verification to delete words
    Remove words from listboxes
    Call CountWords subprocedure
    CHANGE CATEGORY NAME
    Verify that user entered a word in the textbox and picked category to add/change
    If no word or no category give error message
    Check to see if category name currently exists
    If yes then verify user wants to replace
    Change text property in listbox to the new category heading name (will write back to the sequential file on exit)
    ADD WORD
    Verify that user entered a word in the textbox and picked category to add/change
    If not, give error message
    Add word to appropriate listbox
    Call CountWords subprocedure
    COUNT WORDS ROUTINE
    Count words in each listbox
    If <>20
    Change backcolor of short/over listbox and display error label
    COMMON POINTS
    Assign default form button to New Game so user only has to hit Enter to get word
    Use error checking to make sure text files exist
    Use message boxes to verify student/teacher actions (ie "Are you sure you want to delete a word" or "Are you sure you want to exit")

    OVERVIEW
    The student will start the game and choose one of the three categories containing 20 words (category 1 radio button selected on startup). The radiobutton triggers the program to read from the appropriate text file and populate a one-dimension string array with the 20 words. Student presses "new word" button which will randomize a number from 1 to 20 and read that word from the array, place the correct number of dashes, and wait for letter guess. Game will track which words have been used so randomizer will only select an "unused" word (use a parallel one-dimension array for "words used" or a two-dimension array. Student will be able to select "new word" until all 20 words are used then have the option to "start a new game".
    You will be provided with 3 word files pre-populated with 20 words each (Line 1 in the text file is category title, the remaining 20 words are for the game). The teacher will be able to edit the file to change words. The teacher will have a login procedure to access the data files – this should be a password form with option to "change password" or "manage data". The "change password" should bring up a form which asks for the current password and allows the teacher to type in a new password (twice, to verify correct spelling) and if the current password is correct, change the password and write it back to the password.dat file. Teacher will then be taken to the data management form. Data management form will allow the teacher to open one of the category files and edit the words and category title. On exit from the data management form, verify that the teacher has entered 20 words. Save the words back to the appropriate category file.
    Hints:
    1. Make sure you understand the flow of the working program as it is written – the basic structure of the "play of the game" doesn’t change.
    2. Instead of deleting lines of code as you make changes, make them remarks (put ‘ at the beginning) until you make sure your code is working, then you can delete the extraneous lines.
    3. Test the program before you send it in.



    GUI >>>>>>>>>>> below

    ' Project name: Hangman Game Project
    ' Project purpose: The project simulates the Hangman game Revised to load from file.
    ' Created/revised:
    OptionExplicitOn
    OptionStrictOn
    PublicClass MainForm

    PrivateSub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
    'Open text files, load the heading into the appropriate radio button text property
    EndSub
    PrivateSub clearall()
    'Clear textbox, call hideletters
    EndSub
    PrivateSub showusedletter()
    ' make letter used visible
    EndSub
    PrivateSub hideletters()
    'Hide letters used when getting new word by setting visible to false
    'Hide hangman graphics when getting new word by setting visible to false
    EndSub
    PrivateSub resetgame()
    'Clear the board, reset variable, used when changing between categories or after guessing 20 words
    EndSub
    PrivateSub xNewWordButton_Click(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles xNewWordButton.Click
    'Play the game
    EndSub
    PrivateSub xTeacherLoginButton_Click(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles xTeacherLoginButton.Click
    'Check teacher's password then load data management form
    EndSub
    PrivateSub xExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xExitButton.Click
    Me.Close()
    EndSub
    PrivateSub xCat1RadioButton_CheckedChanged(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles xCat1RadioButton.CheckedChanged
    'Load words from textfile 1 to listbox 1 and 4
    EndSub
    PrivateSub xCat2RadioButton_CheckedChanged(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles xCat2RadioButton.CheckedChanged
    'Load words from textfile 2 to listbox 2 and 5
    EndSub

    PrivateSub xCat3RadioButton_CheckedChanged(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles xCat3RadioButton.CheckedChanged
    'Load words from textfile 3 to listbox 3 and 6
    EndSub

    EndClass


Comments

  • Registered Users Posts: 2,481 ✭✭✭Fremen


    I think you should talk to your lecturers about the project, or be more specific about what help you need. It's not really reasonable to expect someone to just do it for you.


  • Closed Accounts Posts: 2 Markiss


    I gave the wrong impression. I did not expect someone to do it for me. I am asking for some example code or drawing on your personal experience for ideas. I need some help with using data files now. I am taking the class online. The instructor has been quite helpful but sometimes its hard to put it all together and make associations.

    I am actuall doing a lot better on it today. Its wierd like that. Yesterday I thought it was over my head and today I made great progress.


Advertisement