Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

hangman code for comp 1!!!

xjessxxjessx Posts: 1Member
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!

Comments

  • Inculcate48Inculcate48 Posts: 5Member
    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!!!!!!!!!
  • gnickolaygnickolay Posts: 1Member
    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

    Do
    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)
    Else
    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) = " "
    Else
    GuessStatusArray(Position) = "*"
    End If
    Next
    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)
    Next
    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
    Do
    If GuessStatusArray(Position) <> IndividualLettersArray(Position) Then
    MissingLetter = True
    Else
    Position = Position + 1
    End If
    Loop Until MissingLetter = True Or Position = Len(NewPhrase) + 1

    If MissingLetter = False Then
    AllLettersGuessedCorrectly = True
    Else
    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
    Next

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

    Else
    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")
    Else
    End
    End If
    End If

    End Sub

Sign In or Register to comment.