none
Tic - Tac - Toe Game Help! RRS feed

  • Question

  • Hi Guys! Today I was going to make a to player tic tac toe game. The problem is , whenever somone clicks the top left square, it wont work. Can anyone please help me?

    PS. I just started this program, so it is really short right now.

    ' Tic - Tac - Toe Game
    ' By Ethan Netz
    
    
    
    GraphicsWindow.Show()
    GraphicsWindow.Width = 700 
    GraphicsWindow.Height = 700
    GraphicsWindow.PenColor = "Black"
    GraphicsWindow.DrawLine(250,50,250,650)
    GraphicsWindow.DrawLine(450,50,450,650)
    GraphicsWindow.DrawLine(50,250,650,250)
    GraphicsWindow.DrawLine(50,450,650,450)
    GraphicsWindow.MouseDown = OnMouseDown
    X = "True"
    O = "False"
    Topright = 0
    Middleright = 0
    BottomRight = 0
    TopMiddle = 0
    MiddleMiddle = 0
    Bottommiddle = 0
    TopLeft = 0
    Middleleft = 0
    Bottomleft = 0
    
    Sub OnMouseDown
      If X = "True" And O = "False" Then
        GraphicsWindow.BrushColor = "Red"
      If Mouse.MouseX >= 50 And Mouse.MouseX < 250  And Mouse.MouseY > 50 And Mouse.MouseY < 250 And Topright = 0 Then
        GraphicsWindow.FillRectangle(50,50,199,199)
        Topright = 1
        X = "False"
        O = "True"
      EndIf
      
      EndIf
    
    EndSub 

    Friday, April 6, 2012 5:30 PM

Answers

  • Heyya EthanNetz!

    I've figured out what is wrong here as well!
    Both Mouse.MouseX & Mouse.MouseY returns the current real coordinates of your actual desktop OS's entire screen! They are not relative of Small Basic's Graphics.Window!!!
    If you position Graphics.Window at the most top-left, it works, 'cause both real & relative mouse coordinates become almost the same!
    Your previous "Click the Box Game" got it all right! For you used GraphicsWindow.MouseX & GraphicsWindow.MouseY instead!

    Besides the above, I've got many ideas for you:

    • Since a Tic-Tac-Toe's "board" is 3x3 sized, why not representing them inside a 2D array, like TTT [3][3], rather than using 9 different variables? You can make like O = (value < 0); X = (value > 0); and a Vacant Space = (value = 0 Or "").
    • Just after a triggered clicked event is raised, the 1st duty is capture and store which coordinate and/or object was selected; either by assigning them into Variables or piling 'em up in a Stack. For example:
    Sub MouseClick                                    Sub MouseClick
    
      MX = GraphicsWindow.MouseX    Or      Stack.PushValue("Buffer" GraphicsWindow.MouseY)
      MY = GraphicsWindow.MouseY              Stack.PushValue("Buffer" GraphicsWindow.MouseX)
    
    EndSub                                                EndSub
    • Make a separate Subroutine to process them outside a Triggered Sub itself. Like what I did creating HitScan() to check if a mouse click's coordinate matched any of the existing box's back then.

    Well, good luck on your new game!


    Friday, April 6, 2012 8:14 PM
    Answerer

All replies

  • Heyya EthanNetz!

    I've figured out what is wrong here as well!
    Both Mouse.MouseX & Mouse.MouseY returns the current real coordinates of your actual desktop OS's entire screen! They are not relative of Small Basic's Graphics.Window!!!
    If you position Graphics.Window at the most top-left, it works, 'cause both real & relative mouse coordinates become almost the same!
    Your previous "Click the Box Game" got it all right! For you used GraphicsWindow.MouseX & GraphicsWindow.MouseY instead!

    Besides the above, I've got many ideas for you:

    • Since a Tic-Tac-Toe's "board" is 3x3 sized, why not representing them inside a 2D array, like TTT [3][3], rather than using 9 different variables? You can make like O = (value < 0); X = (value > 0); and a Vacant Space = (value = 0 Or "").
    • Just after a triggered clicked event is raised, the 1st duty is capture and store which coordinate and/or object was selected; either by assigning them into Variables or piling 'em up in a Stack. For example:
    Sub MouseClick                                    Sub MouseClick
    
      MX = GraphicsWindow.MouseX    Or      Stack.PushValue("Buffer" GraphicsWindow.MouseY)
      MY = GraphicsWindow.MouseY              Stack.PushValue("Buffer" GraphicsWindow.MouseX)
    
    EndSub                                                EndSub
    • Make a separate Subroutine to process them outside a Triggered Sub itself. Like what I did creating HitScan() to check if a mouse click's coordinate matched any of the existing box's back then.

    Well, good luck on your new game!


    Friday, April 6, 2012 8:14 PM
    Answerer
  • PS: Don't forget to mark any of your threads as answered and propose as answer any reply you deem so!  ;-)
    Friday, April 6, 2012 8:21 PM
    Answerer