hangman code for comp 1!!!

hi, i am doing the hangman code gor the comp 1 exam, i have managed create the menu options which allow you to enter a whole phrase and get a random word, these are fully working, also, i have managed to get the program to convert all of the letters that are guessed into upper case, i have created the 3 extra functions: 'getrandomword' which is called by menu option 3 (this gets a random word from the myphrases.txt document that was supplied), 'guesswholephrase' which is called by menu option 4, and 'checknewphrase' which is called within the 'getnewphrase' function so that if an incorrect character is entered eg.%, then an error message will appear. if anybody needs help with these just let me know, does anybody know if i have missed anything out? i saw something about not being able to enter the same letter twice by storing the ones previously entered into an array? i would really appreciate it if anyone could help...thanks!


  • Hey, i totally need your help, i am stuck on pretty much everything you have managed to do.....please..please could you helpme...Can you post your code so far.. thanks

    Your help is very much appreciated!!!!!!!!!
  • OK GUYS u are like jesuses at this what am i supposed to do i h ave no idea my fucked up teacher gave this to me like 4 days ago when she had to given it to me like moth ago PLZ HELP ME ASAP, i have no idea what i am supposed to do, she didnt tell my anything. plz heeelp only got 7h left. here is the code

    ' Skeleton Program for the AQA COMP1 Summer 2009 examination
    ' this code should be used in conjunction with the Preliminary Materials
    ' written by the AQA COMP1 Programmer Team
    ' developed in the Visual Basic 6 programming environment
    ' the listbox control has deliberately numbered the choices 1, 2 and 5

    Dim NewPhrase As String
    Dim PhraseHasBeenSet As Boolean
    Dim PhraseGuessed As Boolean
    Dim Choice As Integer
    Dim IndividualLettersArray(1 To 20) As String
    Dim GuessStatusArray(1 To 20) As String
    Dim LettersGuessedArray(1 To 26) As String
    Dim NextGuessedLetter As String
    Dim Position As Integer
    Dim Index As Integer

    Private Sub Form_Load()
    PhraseHasBeenSet = False

    lstMenu.AddItem "1. SETTER - Maks a new word/phrase"
    lstMenu.AddItem "2. USER - Next letter guess"
    lstMenu.AddItem "5. End"
    End Sub

    Function GetNewPhrase() As String
    Dim PhraseOK As Boolean
    Dim ThisNewPhrase As String

    ThisNewPhrase = InputBox("Key in new phrase ...(letters and any Spaces)")
    If Len(ThisNewPhrase) < 10 Then
    PhraseOK = False
    MsgBox ("Not enough letters ... ")
    ' possible futher validation check(s)
    PhraseOK = True
    GetNewPhrase = ThisNewPhrase
    End If
    Loop Until PhraseOK = True
    End Function

    Private Sub SetUpGuessStatusArray(ByRef NewPhrase As String, ByRef IndividualLettersArray() As String, _
    ByRef GuessStatusArray() As String)
    Dim Position As Integer

    For Position = 1 To Len(NewPhrase)
    IndividualLettersArray(Position) = Mid(NewPhrase, Position, 1)
    If IndividualLettersArray(Position) = " " Then
    GuessStatusArray(Position) = " "
    GuessStatusArray(Position) = "*"
    End If
    End Sub

    Private Sub DisplayCurrentStatus(ByRef PhraseLength As Byte, ByRef GuessStatusArray() As String)
    Dim Position As Integer
    Dim TempString As String

    TempString = ""
    For Position = 1 To PhraseLength
    TempString = TempString + GuessStatusArray(Position)
    txtOutput.Text = TempString
    End Sub

    Function GetNextLetterGuess() As String
    Dim GuessedLetter As String

    GuessedLetter = InputBox("Next guess ?")
    GetNextLetterGuess = GuessedLetter
    End Function

    Function AllLettersGuessedCorrectly(ByRef GuessStatusArray() As String, _
    ByRef NewPhrase As String, ByRef IndividualLettersArray() As String) As Boolean
    Dim Position As Integer
    Dim MissingLetter As Boolean

    MissingLetter = False
    Position = 1
    If GuessStatusArray(Position) <> IndividualLettersArray(Position) Then
    MissingLetter = True
    Position = Position + 1
    End If
    Loop Until MissingLetter = True Or Position = Len(NewPhrase) + 1

    If MissingLetter = False Then
    AllLettersGuessedCorrectly = True
    AllLettersGuessedCorrectly = False
    End If
    End Function

    Private Sub lstMenu_Click()

    ' lstOutput control has a ListIndex property which starts ar 0
    Choice = lstMenu.ListIndex + 1

    If Choice = 1 Then
    NewPhrase = GetNewPhrase()
    Call SetUpGuessStatusArray(NewPhrase, IndividualLettersArray, GuessStatusArray)
    PhraseHasBeenSet = True
    End If

    If Choice = 2 Then
    If PhraseHasBeenSet = True Then
    Call DisplayCurrentStatus(Len(NewPhrase), GuessStatusArray)
    NextGuessedLetter = GetNextLetterGuess()
    ' is this letter present ?
    For Index = 1 To Len(NewPhrase)
    If NextGuessedLetter = IndividualLettersArray(Index) Then
    GuessStatusArray(Index) = NextGuessedLetter
    End If

    Call DisplayCurrentStatus(Len(NewPhrase), GuessStatusArray)
    PhraseGuessed = AllLettersGuessedCorrectly(GuessStatusArray, NewPhrase, _
    If PhraseGuessed = True Then
    MsgBox ("You have guessed correctly")
    End If

    MsgBox ("The setter has not specified the word/phrase ..")
    End If
    End If

    If Choice = 3 Then
    If PhraseGuessed = False Then
    MsgBox ("You have not completed this word/phrase")
    End If
    End If

    End Sub

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!