none
Need help with my small basic hangman code RRS feed

  • Question

  • Hey guys, my small basic hangman code would not draw the hangman after you enter the wrong letter. Please fix tyty

    Here's my code

    GraphicsWindow.BackgroundColor = "Darkgray"
    GraphicsWindow.Title = "Hangman"
    GraphicsWindow.FontSize = 12
    GraphicsWindow.BrushColor = "black"
    GraphicsWindow.DrawText (120, 1, "Hangman")

    GraphicsWindow.Height = 300
    GraphicsWindow.Width = 300

     NewGame = Controls.AddButton("New Game", 110, 120)
    Controls.SetSize(NewGame, 80, 40)


    Controls.ButtonClicked = LastButtonClicked



    Sub LastButtonClicked
      ButtonClicked = Controls.LastClickedButton
      If (NewGame = ButtonClicked) Then
        GraphicsWindow.Clear()
        TextWindow.WriteLine("Player 1 please enter your word ")
        word = TextWindow.Read()
        word1 = Text.ConvertToUpperCase(word)
        wordlength = Text.GetLength(word1)
        TextWindow.WriteLine("Your word was")
        TextWindow.Writeline(word1)
        TextWindow.WriteLine("Press space bar to continue")
        Program.Delay(1000)
          TextWindow.Hide()
          GraphicsWindow.Clear()
          GraphicsWindow.Width = 500
          GraphicsWindow.Height = 600
          GraphicsWindow.BackgroundColor = "White"
          GraphicsWindow.FontSize = 14
          
        For i = 1 To Text.GetLength(word1)
        GraphicsWindow.FontSize = 16
        GraphicsWindow.PenColor = "Black"
        GraphicsWindow.PenWidth = 4    
        Shapes.AddLine(50 + i*40, 550, 50 + i*40 + 30, 550) 
      EndFor 
      EndIf

    Endsub 
      
    hang = 0
    man = 0
     
      
    hangman = "1="+Shapes.AddRectangle(10,200)+";2=50;3=50;"+"4="+Shapes.AddRectangle(100,10)+";5=50;6=50;"+"7="+Shapes.AddRectangle(5,80)+";8=150;9=50;"+"10="+Shapes.AddEllipse(30,30)+";11=137;12=130;"+"13="+Shapes.AddRectangle(5,40)+";14=150;15=160;"+"16="+Shapes.AddLine(150,170,130,190)+";17=0;18=0;"+"19="+Shapes.AddLine(150,170,170,190)+";20=0;21=0;"+"22="+Shapes.AddLine(150,200,170,220)+";23=0;24=0;"+"25="+Shapes.AddLine(150,200,130,220)+";26=0;27=0;100=1"


    For i = 1 To Array.GetItemCount(hangman) Step 3
      Shapes.Move(hangman[i],hangman[i+1],hangman[i+2])
      Shapes.HideShape(hangman[i])
    EndFor



    GraphicsWindow.KeyDown = OnKeyDown


    Sub OnKeyDown
      For q = 0 To hang Step 1
        If GraphicsWindow.LastKey = Text.GetSubText(word,q,hang) Then
         hang = hang - 1
         man = man - 1
        EndIf
      EndFor
      

      
      For i=1 To Text.GetLength(word1)
        If GraphicsWindow.LastKey=Text.GetSubText(word1, i, 1) Then
          hang = hang + 1
          GraphicsWindow.DrawText(50+i*45,520,Text.GetSubText(word1, i, 1))
          GraphicsWindow.FontSize = 16
          If hang = Text.GetLength(word1) Then
            GraphicsWindow.Clear()
            GraphicsWindow.Width = 500
            GraphicsWindow.Height = 400
            GraphicsWindow.Title = "Player 2 Wins!!!"
            GraphicsWindow.PenColor = "Red'
            GraphicsWindow.DrawText (250, 200, "Player 2 Wins!!!")
            
            Program.Delay(3000)
            Program.End()
           Endif    
        Else
          wrong = wrong + 1
          
        EndIf
      EndFor 




    If man = 8 Then 
      GraphicsWindow.Clear()
      GraphicsWindow.Width = 500
      GraphicsWindow.Height = 400
      GraphicsWindow.Title = "Player 1 Wins!!!"
      GraphicsWindow.PenColor = "Red'
      GraphicsWindow.DrawText (250, 200, "Player 1 Wins!!!")
      
      Program.Delay(3000)
      Program.End()
    Endif

    If wrong = Text.GetLength(word1) Then
        Shapes.ShowShape(hangman[hangman[100]])
        hangman[100]=hangman[100]+3
        man = man + 1
      EndIf
      
      wrong = 0
      EndSub

    Very urgent as it is due today


    Friday, June 30, 2017 3:11 AM

Answers