locked
Some questions about my chess game RRS feed

  • Question

  • Hello,

    I'm making a new chess game. You need to select a piece and move it. How can I select my chess? Following codes are mine, but there are too many bugs in it:

    If Mouse.IsLeftButtonDown="true" Then
        If Math.Floor(Mouse.MouseX/100)-1>0 And Math.Floor(Mouse.MouseY/100)<5 Then
          If round="BRD" Then
            LDShapes.BrushColour(BRDarmy[Math.Floor(Mouse.MouseX/100)+1][Math.Floor(Mouse.MouseY/100)],"PaleTurquoise")
          ElseIf round="DDR" Then
            LDShapes.BrushColour(DDRarmy[Math.Floor(Mouse.MouseX/100)+1][Math.Floor(Mouse.MouseY/100)],"Aqua")
          EndIf
        EndIf
      EndIf

    The main error is:

    And sometimes I can't select a chess.

    Can someone help me?

    Best Regards & Thanks a lot!




    Wednesday, April 8, 2020 12:37 PM

Answers

  • try not to use Mouse.MouseX & Y bcs they are in screen-related coords!

    instead use Graphicswindow.MouseX & Y props! They are window-related.

    Wednesday, April 8, 2020 5:04 PM
  • Yes, it is important to know that there are these two types of mouse coordinates.
    Accidental use of the mouse object (Mouse .__) can lead to strange errors that are not so easy to find.
    Here is a brief example:

    GraphicsWindow.BackgroundColor = "Yellow"
    GraphicsWindow.Width  = 400
    GraphicsWindow.Height = 300
    GW_Left = Shapes.AddText(GraphicsWindow.left)
    GW_Top  = Shapes.AddText(GraphicsWindow.top)
    M_X = Shapes.AddText(Mouse.MouseX)
    M_Y = Shapes.AddText(Mouse.MouseY)
    MXGW_Left = Shapes.AddText(Mouse.MouseX - GraphicsWindow.left)
    MYGW_Top  = Shapes.AddText(Mouse.MouseY - GraphicsWindow.top)
    Shapes.Move(GW_Left, 300 , 100)
    Shapes.Move(GW_Top , 300 , 125)
    Shapes.Move(M_X, 300 , 150)
    Shapes.Move(M_Y, 300 , 175)
    Shapes.Move(MXGW_Left, 300 , 200)
    Shapes.Move(MYGW_Top, 300 , 225)
    
    Ball = Shapes.AddEllipse(16, 16)
    Shapes.Move(Ball, 50, 50)
    
    GraphicsWindow.MouseMove = OnMouseMove
    
    Sub OnMouseMove
     'ch_mX = Mouse.MouseX - GraphicsWindow.Left  'windowed X
     'ch_mY = Mouse.MouseY - GraphicsWindow.Top   'windowed Y 
     'Shapes.SetText(TextThing,"X="+(Mouse.MouseX - GraphicsWindow.Left - 8) + " Y=" + (Mouse.MouseY - GraphicsWindow.Top - 31))
     'Shapes.SetText(M_X,Mouse.MouseX)
     'Shapes.SetText(M_Y,Mouse.MouseY)
     Shapes.SetText(M_X,GraphicsWindow.MouseX)
     Shapes.SetText(M_Y,GraphicsWindow.MouseY)
     Shapes.SetText(GW_Left,GraphicsWindow.left)
     Shapes.SetText(GW_Top,GraphicsWindow.top)
     Shapes.SetText(MXGW_Left,Mouse.MouseX - GraphicsWindow.left)
     Shapes.SetText(MYGW_Top, Mouse.MouseY - GraphicsWindow.top)
     'Shapes.SetText(TextThing,"X="+ Mouse.MouseX  + " Y=" + Mouse.MouseY )
     'Shapes.Move(Ball, GraphicsWindow.MouseX , GraphicsWindow.MouseY)
    EndSub

    Wednesday, April 8, 2020 7:35 PM
  • The line     "GraphicsWindow.KeyDown = OnKeyDown" is never executed because  move[armyx][armyy] has no value. You assign  move("BRDarmy"][1] = 1  and then check for  move[armyx][armyy]. armyx has the value 1 and not "BRDarmy" so is never > 0 and the keydown assignment is not executed.

    Is there a reason you want to call the keydown events only after a certain position in the game?


    Jan [ WhTurner ] The Netherlands


    Thursday, April 16, 2020 11:24 AM
    Answerer
  • Program to see how determine the box the where the mousclick occurs:

    GraphicsWindow.Width=500
    GraphicsWindow.Height=500
    For x=100 To 400 Step 100  ''grid
      GraphicsWindow.DrawLine(x,0,x,500)
      GraphicsWindow.DrawLine(0,x,5000,x)
    EndFor
    GraphicsWindow.MouseUp=mu
    
    Sub mu
      x=GraphicsWindow.MouseX
      xx=math.Ceiling(x/100)
      y=GraphicsWindow.MouseY
      yy=Math.Ceiling(y/100)
      GraphicsWindow.DrawText(x,y,xx+":"+yy)
    EndSub


    Jan [ WhTurner ] The Netherlands


    Saturday, April 11, 2020 2:53 PM
    Answerer

All replies

  • Hi Thalemann-Pioniere,

    Did you prepare shapes before calling LDShapes.BrushColour?

    shp[1] = Shapes.AddRectangle(100, 100)
    Shapes.Move(shp[1], 100, 100)
    shp[2] = Shapes.AddRectangle(100, 100)
    Shapes.Move(shp[2], 250, 100)
    LDShapes.BrushColour(shp[1],"PaleTurquoise") 
    LDShapes.BrushColour(shp[2],"Aqua") 


    Nonki Takahashi

    Wednesday, April 8, 2020 1:35 PM
  • Hi Nonki,

    Sure! If you want to see the complete program, QFF913 is.

    Best Regards & Thanks!

    Wednesday, April 8, 2020 2:33 PM
  • try not to use Mouse.MouseX & Y bcs they are in screen-related coords!

    instead use Graphicswindow.MouseX & Y props! They are window-related.

    Wednesday, April 8, 2020 5:04 PM
  • Yes, it is important to know that there are these two types of mouse coordinates.
    Accidental use of the mouse object (Mouse .__) can lead to strange errors that are not so easy to find.
    Here is a brief example:

    GraphicsWindow.BackgroundColor = "Yellow"
    GraphicsWindow.Width  = 400
    GraphicsWindow.Height = 300
    GW_Left = Shapes.AddText(GraphicsWindow.left)
    GW_Top  = Shapes.AddText(GraphicsWindow.top)
    M_X = Shapes.AddText(Mouse.MouseX)
    M_Y = Shapes.AddText(Mouse.MouseY)
    MXGW_Left = Shapes.AddText(Mouse.MouseX - GraphicsWindow.left)
    MYGW_Top  = Shapes.AddText(Mouse.MouseY - GraphicsWindow.top)
    Shapes.Move(GW_Left, 300 , 100)
    Shapes.Move(GW_Top , 300 , 125)
    Shapes.Move(M_X, 300 , 150)
    Shapes.Move(M_Y, 300 , 175)
    Shapes.Move(MXGW_Left, 300 , 200)
    Shapes.Move(MYGW_Top, 300 , 225)
    
    Ball = Shapes.AddEllipse(16, 16)
    Shapes.Move(Ball, 50, 50)
    
    GraphicsWindow.MouseMove = OnMouseMove
    
    Sub OnMouseMove
     'ch_mX = Mouse.MouseX - GraphicsWindow.Left  'windowed X
     'ch_mY = Mouse.MouseY - GraphicsWindow.Top   'windowed Y 
     'Shapes.SetText(TextThing,"X="+(Mouse.MouseX - GraphicsWindow.Left - 8) + " Y=" + (Mouse.MouseY - GraphicsWindow.Top - 31))
     'Shapes.SetText(M_X,Mouse.MouseX)
     'Shapes.SetText(M_Y,Mouse.MouseY)
     Shapes.SetText(M_X,GraphicsWindow.MouseX)
     Shapes.SetText(M_Y,GraphicsWindow.MouseY)
     Shapes.SetText(GW_Left,GraphicsWindow.left)
     Shapes.SetText(GW_Top,GraphicsWindow.top)
     Shapes.SetText(MXGW_Left,Mouse.MouseX - GraphicsWindow.left)
     Shapes.SetText(MYGW_Top, Mouse.MouseY - GraphicsWindow.top)
     'Shapes.SetText(TextThing,"X="+ Mouse.MouseX  + " Y=" + Mouse.MouseY )
     'Shapes.Move(Ball, GraphicsWindow.MouseX , GraphicsWindow.MouseY)
    EndSub

    Wednesday, April 8, 2020 7:35 PM
  • Hello there,

    Thank you for your helping, they're very helpful! This program is very complicated for me so maybe there will be problems. If I can't solve them, I will post them in this thread.

    Best Regards & Thanks a lot!

    Friday, April 10, 2020 10:26 AM
  • Hello,

    In your program you define the armies in a [1..4][1..4] array, but in ""drawchesses" you fill the BRDarmy from 0 to 3. I think that should be also  1 to 4.


    Jan [ WhTurner ] The Netherlands

    Saturday, April 11, 2020 12:18 PM
    Answerer
  • Hi Jan,

    You checked it so carefully! Yes, but I don't know why it can work. And I am making a new program to make a mini game(easy to understand), but the topic is same to the bigger one. Then, I will "handle" the code of the mini version into the bigger version.

    Thanks a lot & Best Regards!

    Saturday, April 11, 2020 12:35 PM
  • Program to see how determine the box the where the mousclick occurs:

    GraphicsWindow.Width=500
    GraphicsWindow.Height=500
    For x=100 To 400 Step 100  ''grid
      GraphicsWindow.DrawLine(x,0,x,500)
      GraphicsWindow.DrawLine(0,x,5000,x)
    EndFor
    GraphicsWindow.MouseUp=mu
    
    Sub mu
      x=GraphicsWindow.MouseX
      xx=math.Ceiling(x/100)
      y=GraphicsWindow.MouseY
      yy=Math.Ceiling(y/100)
      GraphicsWindow.DrawText(x,y,xx+":"+yy)
    EndSub


    Jan [ WhTurner ] The Netherlands


    Saturday, April 11, 2020 2:53 PM
    Answerer
  • The second question: I have to move the chess. But GraphicWindow.KeyDown or GraphicWindow.LastKey don't work. I want to use "Up", "Down", "Left" and "Right" to change chesses, and use "A", "D", "W", "X" to move them.

    The ID is QFF913-0.

    Best Regards & Thanks a lot!


    Thursday, April 16, 2020 2:28 AM
  • The line     "GraphicsWindow.KeyDown = OnKeyDown" is never executed because  move[armyx][armyy] has no value. You assign  move("BRDarmy"][1] = 1  and then check for  move[armyx][armyy]. armyx has the value 1 and not "BRDarmy" so is never > 0 and the keydown assignment is not executed.

    Is there a reason you want to call the keydown events only after a certain position in the game?


    Jan [ WhTurner ] The Netherlands


    Thursday, April 16, 2020 11:24 AM
    Answerer
  • Hi Jan,

    Oops... I'm a stupid. I need to review my code again. It's too messy...

    And It can only be run one time and While loop doesn't work? How to solve it?

    Best Regards & Thank you very much!

    p.s. It seems that there is no part about GraphicsWindow.LastKey in introducing?

    Thursday, April 16, 2020 12:05 PM
  • Perhaps is https://social.technet.microsoft.com/wiki/contents/articles/16381.small-basic-curriculum-lesson-4-2-responding-to-events.aspx  of some help

    Or https://social.technet.microsoft.com/wiki/contents/articles/16377.small-basic-curriculum-lesson-3-4-events-and-interactivity.aspx


    Jan [ WhTurner ] The Netherlands


    • Edited by WhTurner33Editor Thursday, April 16, 2020 12:42 PM added second link
    Thursday, April 16, 2020 12:33 PM
    Answerer