none
Arrays & GraphicWindow drawing elements RRS feed

  • General discussion

  • Hi,

    Am I able to to use an array to store a series of GraphicWindows.DrawLine elements and then use that array to display the drawings?

    I have the following:

    GraphicsWindow.DrawLine(10,300,250,300) 'bottom horizontal
    GraphicsWindow.DrawLine(100,100,200,100)'top horizontal
    GraphicsWindow.DrawLine(100,300, 100,100) ' upright
    GraphicsWindow.DrawLine(100,150, 130,100) ' vertical balance
    GraphicsWindow.DrawLine (200,100,200,120) 'hanging rope
    GraphicsWindow.DrawEllipse(185,120,30,30) 'head
    GraphicsWindow.DrawLine (200,185,200,150) 'body
    GraphicsWindow.DrawLine (200,185,170,220) 'left leg
    GraphicsWindow.DrawLine (200,185,225,220) 'right leg
    GraphicsWindow.DrawLine (200,165,180,180) 'left arm
    GraphicsWindow.DrawLine (200,165,220,180) 'right arm

    This draws a complete "hanged" man, what I would like to do according to the step in the loop of guessing the letter is to display the part for the man if the letter is guessed incorrectly.

     

    Many thanks for any ideas

     

    Wendy


    Wendy
    • Changed type paz67 Thursday, December 1, 2011 8:25 AM secret
    • Changed type paz67 Thursday, December 1, 2011 8:25 AM secret
    Wednesday, November 30, 2011 8:15 PM

All replies

  • Nice drawing.

    One way would be to put your drawing in a subroutine and draw each segment depending on the value of a variable, then call the subroutine with the segment to be drawn which increases from 1 to 11 and 12 is all over as a wrong guess is made.

    Partial test code of the idea below:

    For i = 1 To 12
      seg = i
      drawSegment()
      Program.Delay(500)
    EndFor
    
    Sub drawSegment
      If (seg = 1) Then
        GraphicsWindow.DrawLine(10,300,250,300) 'bottom horizontal
      ElseIf (seg = 2) Then
        GraphicsWindow.DrawLine(100,100,200,100)'top horizontal
      ElseIf (seg = 3) Then
        GraphicsWindow.DrawLine(100,300, 100,100) ' upright
      ElseIf (seg = 4) Then
        GraphicsWindow.DrawLine(100,150, 130,100) ' vertical balance
      ElseIf (seg = 5) Then
        GraphicsWindow.DrawLine (200,100,200,120) 'hanging rope
      ElseIf (seg = 6) Then
        GraphicsWindow.DrawEllipse(185,120,30,30) 'head
      ElseIf (seg = 7) Then
        GraphicsWindow.DrawLine (200,185,200,150) 'body
      ElseIf (seg = 8) Then
        GraphicsWindow.DrawLine (200,185,170,220) 'left leg
      ElseIf (seg = 9) Then
        GraphicsWindow.DrawLine (200,185,225,220) 'right leg
      ElseIf (seg = 10) Then
        GraphicsWindow.DrawLine (200,165,180,180) 'left arm
      ElseIf (seg = 11) Then
        GraphicsWindow.DrawLine (200,165,220,180) 'right arm
      ElseIf (seg = 12) Then
        Sound.PlayBellRingAndWait()
      EndIf
    EndSub


    Wednesday, November 30, 2011 8:25 PM
    Moderator
  • MissedLetter needs to be initialised somewhere at the start to 0.

    You have 2 loops inside each other, both using the index i (inside OnKeyDown), this will casues problems because i is updated on the inner loop and therefore the outer loop wont complete properly because i has been updated.

    Also the logic isn't really right.

    1] we want to check if the letter is in the word, if it is then print it.  Also flag we found a match

      Converted = Text.ConvertToUpperCase (GuessWord)
      Found = 0
      For i = 1 To Text.GetLength(converted)
        If GraphicsWindow.LastKey = Text.GetSubText(Converted,i, 1) Then
          GraphicsWindow.DrawText(50+ i * 40, 450, Text.GetSubText(converted,i, 1))
          Found = 1
        EndIf
      EndFor
    

    2] If it isn't in the word, then draw the next segment, update MissedLetter

    3] if MissedLetterleter > 11 (=12) then game over

      If (Found = 0) Then
        MissedLetter = MissedLetter + 1
        If (MissedLetter = 12) Then
          GraphicsWindow.ShowMessage("The word was "+GuessWord,"You Loose")
        Else
          seg = MissedLetter
          drawSegment()
        EndIf
      EndIf
    


    The whole subroutine:

    Sub OnKeyDown
      Converted = Text.ConvertToUpperCase (GuessWord)
      Found = 0
      For i = 1 To Text.GetLength(converted)
        If GraphicsWindow.LastKey = Text.GetSubText(Converted,i, 1) Then
          GraphicsWindow.DrawText(50+ i * 40, 450, Text.GetSubText(converted,i, 1))
          Found = 1
        EndIf
      EndFor
      If (Found = 0) Then
        MissedLetter = MissedLetter + 1
        If (MissedLetter = 12) Then
          GraphicsWindow.ShowMessage("The word was "+GuessWord,"You Loose")
        Else
          seg = MissedLetter
          drawSegment()
        EndIf
      EndIf
    EndSub


    Wednesday, November 30, 2011 10:50 PM
    Moderator
  • I was thinking you could use the shapes object to assign each one to an array, then you can hide and show after testing for a correct answer.  Using this gives you a flash of a head in the wrong spot and I can't get it assigned and then hidden without it flashing in place first... Is there a way to assign the 'drawMe's without showing them until you want them?  I've been trying to draw and animate some complex shapes this way.

    drawMe[1] = Shapes.AddLine(10,300,250,300) 'bottom horizontal
    drawMe[2] = Shapes.AddLine(100,100,200,100)'top horizontal
    drawMe[3] = Shapes.AddLine(100,300, 100,100) ' upright
    drawMe[4] = Shapes.AddLine(100,150, 130,100) ' vertical balance
    drawMe[5] = Shapes.AddLine(200,100,200,120) 'hanging rope
    drawMe[6] = Shapes.AddEllipse(30,30) 'head
    Shapes.Move( drawMe[6], 185, 120) ' puts head in place
    drawMe[7] = Shapes.AddLine(200,185,200,150) 'body
    drawMe[8] = Shapes.AddLine(200,185,170,220) 'left leg
    drawMe[9] = Shapes.AddLine(200,185,225,220) 'right leg
    drawMe[10] = Shapes.AddLine(200,165,180,180) 'left arm
    drawMe[11] = Shapes.AddLine(200,165,220,180) 'right arm


    Allen
    Tuesday, December 6, 2011 5:14 PM
  • Yes Shapes.ShowShape and Shapes.HideShape:

    drawMe[1] = Shapes.AddLine(10,300,250,300) 'bottom horizontal
    Program.Delay(1000)
    Shapes.HideShape(drawMe[1])
    Program.Delay(1000)
    Shapes.ShowShape(drawMe[1])


    Tuesday, December 6, 2011 7:04 PM
    Moderator
  • You can use for loop to hide and show multiple shaped in a row:

    drawMe[1] = Shapes.AddLine(10,300,250,300) 'bottom horizontal
    drawMe[2] = Shapes.AddLine(100,100,200,100)'top horizontal
    drawMe[3] = Shapes.AddLine(100,300, 100,100) ' upright
    drawMe[4] = Shapes.AddLine(100,150, 130,100) ' vertical balance
    drawMe[5] = Shapes.AddLine(200,100,200,120) 'hanging rope
    drawMe[6] = Shapes.AddEllipse(30,30) 'head
    Shapes.Move( drawMe[6], 185, 120) ' puts head in place
    drawMe[7] = Shapes.AddLine(200,185,200,150) 'body
    drawMe[8] = Shapes.AddLine(200,185,170,220) 'left leg
    drawMe[9] = Shapes.AddLine(200,185,225,220) 'right leg
    drawMe[10] = Shapes.AddLine(200,165,180,180) 'left arm
    drawMe[11] = Shapes.AddLine(200,165,220,180) 'right arm

    'Hide all shapes
    For i = 1 to Array.GetItemCount(drawMe)
      Shapes.HideShape(drawMe[i])'Hide shape
    EndFor

    TextWindow.Read()

    'Show all shapes
    For i = 1 to Array.GetItemCount(drawMe)
      Shapes.ShowShape(drawMe[i])'Show shape
      TextWindow.Read()
    EndFor

    • Edited by Oskariok Tuesday, December 6, 2011 7:28 PM
    Tuesday, December 6, 2011 7:24 PM