none
Help needed with Hangman RRS feed

  • Question

  • Im trying to build a basic hangman game to show off for a project i am doing. If anyopne sees this, could you tell me whats wrong and how i can fix it. When you go and enter a word it takes it in and turns the length of the word into dashes. When another person goes to enter a word, they have to enter it the amount of times it is away from the start of the word. Fo example

    Word trying to guess: Hello

    If you want to guess o, you would have to enter o 5 times before it being accepted. A+I would like to get this done by Friday.

    Thanks,

    Eamon.

    _______________________________________________________________________________________________________

    TextWindow.WriteLine("Welcome To Hangman :)")

    TextWindow.WriteLine(" __      __       .__                                  __             ___ ___                                       ")    
    TextWindow.WriteLine("/  \    /  \ ____ |  |   ____  ____   _____   ____   _/  |_  ____    /   |   \_____    ____    ____   _____ _____    ____  ")
    TextWindow.WriteLine("\   \/\/   // __ \|  | _/ ___\/  _ \ /     \_/ __ \  \   __\/  _ \  /    ~    \__  \  /    \  / ___\ /     \\__  \  /    \ ")
    TextWindow.WriteLine(" \        /\  ___/|  |_\  \__(  <_> )  Y Y  \  ___/   |  | (  <_> ) \    Y    // __ \|   |  \/ /_/  >  Y Y  \/ __ \|   |  \")
    TextWindow.WriteLine("  \__/\  /  \___  >____/\___  >____/|__|_|  /\___  >  |__|  \____/   \___|_  /(____  /___|  /\___  /|__|_|  (____  /___|  /")
    TextWindow.WriteLine("       \/       \/          \/            \/     \/                        \/      \/     \//_____/       \/     \/     \/ ")

    TextWindow.WriteLine(" ")
    TextWindow.WriteLine("Enter The Word To Be Guessed By The Second Player")
    userword = TextWindow.Read()
    length = Text.GetLength(userword)


    attempt = 0
    y = 0

    For i = 1 To length 
      word[i] = Text.GetSubText(userword,i,1)
    EndFor
    For i=1 To length
      TextWindow.WriteLine(word[i])
    endfor
    TextWindow.Clear()
    For i = 1 To length
      dash[i] = "_"
      TextWindow.Write(" " + dash[i] + " ")
    endfor

     TextWindow.WriteLine("")
     
    while attempt < 10
       
      For i=1 To length
        guess[y] = TextWindow.Read()
        
        If guess[y] = word[i] Then
           TextWindow.WriteLine("Correct")
           dash[i] = guess[y]
           For i=1 to length 
             TextWindow.Write(" " + dash[i] + " ")
         endfor
         TextWindow.WriteLine("")
         Else
           if guess[y] <> word[i] then
             attempt = attempt + 1
           TextWindow.WriteLine("Incorrect! You have used " + attempt + " guess out of 10")
           endif
       endif
       If attempt = 10 Then
         TextWindow.Clear()
         TextWindow.WriteLine("You ran out of guesses!")
        EndIf
      EndFor
      
    endwhile

    Wednesday, July 31, 2019 9:36 AM

Answers

  • Hi Eamon, I think you should add code to show winning.  If there are no "_" in dash array, this program should show winning and end program.

    Nonki Takahashi

    Wednesday, July 31, 2019 1:41 PM
    Moderator
  • I've written the "heart"of the program which works, You have to add all the things which are missing at the moment:

    inword="hello"  ''  testvalue
    length=Text.GetLength(inword)
    for i=1 to length
      word[i]=Text.GetSubText(inword,i,1)
      dash[i]="_"
    EndFor
    
    While attempt<10
      guess=TextWindow.Read()
      found="False"
      For i=1 To length
        If word[i]=guess Then
          found="True"
          If dash[i]="_" Then
            dash[i]=guess
            nFound=nFound+1
          EndIf
        EndIf
      EndFor
      If found="True"Then
        For i=1 To length
          TextWindow.Write(" " + dash[i] + " ")
        EndFor
        TextWindow.WriteLine("")
      Else
        attempt=attempt+1
      EndIf
      If nFound=length Then
        TextWindow.WriteLine("YOU WIN")
        TextWindow.Pause()
        Program.End()
      EndIf
    EndWhile
    TextWindow.WriteLine("YOU LOSE")
    
    


    Jan [ WhTurner ] The Netherlands

    Thursday, August 1, 2019 12:04 PM
    Answerer

All replies

  • Hi Eamon, I think you should add code to show winning.  If there are no "_" in dash array, this program should show winning and end program.

    Nonki Takahashi

    Wednesday, July 31, 2019 1:41 PM
    Moderator
  • The flow of your program is not correct:

    You have to test the first guess with all the letters in word. if there is no match then "NOT CORRECT", and count one attempt

    else put ALL the correct letters in the dashes array and ask for the second guess. and so on

    You also have to think if you want to make a difference between H and h. It is best to change all input to UPPERCASE with Text.ConvertToUpperCase


    Jan [ WhTurner ] The Netherlands


    Wednesday, July 31, 2019 3:01 PM
    Answerer
  • I've written the "heart"of the program which works, You have to add all the things which are missing at the moment:

    inword="hello"  ''  testvalue
    length=Text.GetLength(inword)
    for i=1 to length
      word[i]=Text.GetSubText(inword,i,1)
      dash[i]="_"
    EndFor
    
    While attempt<10
      guess=TextWindow.Read()
      found="False"
      For i=1 To length
        If word[i]=guess Then
          found="True"
          If dash[i]="_" Then
            dash[i]=guess
            nFound=nFound+1
          EndIf
        EndIf
      EndFor
      If found="True"Then
        For i=1 To length
          TextWindow.Write(" " + dash[i] + " ")
        EndFor
        TextWindow.WriteLine("")
      Else
        attempt=attempt+1
      EndIf
      If nFound=length Then
        TextWindow.WriteLine("YOU WIN")
        TextWindow.Pause()
        Program.End()
      EndIf
    EndWhile
    TextWindow.WriteLine("YOU LOSE")
    
    


    Jan [ WhTurner ] The Netherlands

    Thursday, August 1, 2019 12:04 PM
    Answerer