none
Solitaire Drag and Drop Prototype RRS feed

  • Question

  • Hello,

    I am currently developing a small basic version of the card game, solitaire.

    Here is my progress so far. It is simply a set of blocks that can be dragged and dropped accordingly. It's far from completion. The overall interface of the program may feel rigid and doesn't have any rules but I'm trying to build the core foundations first.

    Here's the program#: CDC508

    Areas I wish to discuss and, if necessary, improve on:

    1. Mouse interaction with blocks. The number of blocks the user can pick up and drag based on where the user clicked. Check subroutine on line 104. The data structures were inspired from a program I found in the small basic curriculum. Details about it here.
    2. Manipulating and updating block interaction boundaries based on user action. For instance, if the user picks up a block from the 4th column and placed it in the 1st column. The interaction boundaries need to be updated. This occurs at line 76. Is this method excessive?
    3. The program sleeps (delay) for 1 ms. However, I have to change it to 0 when the user picks up a block because it can cause the mouse event to build up. How can I apply a delay throughout the program without causing the mouse event to build up or slow down?
    4. When the program creates a set of blocks (line 26), the last block created remains on top. Meaning that If I picked the block in the first column, which was the first block added, and move it over to another column it will be overlapped by other blocks since they were added after it. Hiding and then showing a selected shape or shapes didn't work. In the end, I had to remove them then reload them every time they're selected to prevent any shape from being overlapped. I'm not sure if there is another way to do this? This is done at line 152.
    5. Finally, there is a temporary patch in the program on line 44. Without the patch, the user could simply displace any block that is selected by tapping it in rapid succession. It's unpredictable but after an uncertain number of clicks the block or blocks selected will be removed and placed on the top left corner of the screen. From my observations, I know that the blocks aren't removed but simply displaced. Secondly, when this bug occurs, the 3rd check point in the main loop (line 51/ mouse release) isn't fulfilled and skips over the all code nest inside. This prevents the program from updating the block's coordinates and, as a result, it's displaced. This is apparent when you remove the comment tags of the text windows at lines 41, 52, 53 AND comment/block the entire patch on line 44. The text window will state two comments: "mouse down is true" and "mouse release is true". You should get that pair of comments when it's working, but if the selected blocks are displaced you'll notice that one of the comments is missing, the "mouse release is true". This indicates that mouse release remains false even though I released the mouse. I'm not sure If It's a small basic error or limitation. I think it's more likely that I poorly structured my code.

    More important than anything, I need help with the last two points (point # 4 and 5)!

    If anyone has questions in regard to a particular section of the code please let me know and I'll try to answer it the best I can.

    Thank you.

    P.S. If I update the code or resolve any of the problems posted above on my own. I will mention it here.




    • Edited by Ezra94 Thursday, June 11, 2015 11:40 PM Edit
    Thursday, June 11, 2015 11:31 PM

Answers

  • Import KDD528.  You can comment the extension Z order and uncomment the delete/recreate shapes to not use extension.
    • Marked as answer by Ezra94 Sunday, June 14, 2015 5:27 PM
    Saturday, June 13, 2015 9:17 PM
    Moderator
  • Here's a program I did ages ago that handles Z-orders with native SB.

    JQD875   Runs local only.

    Point 4: You're right the only way to Z order is by remove and add. Don't worry about the flicker in the top left, with careful code the eye can't see it.

    Point 3: Use a frame rate to delay your main loop 20ms = 50fps. Plenty of time to get stuff done in your Main Loop (UI thread). Register your events and assign the event handler name, e.g.

    GraphicsWindow.MouseMove = OnMouseMove 

    The event handler is:

    Sub OnMouseMove
      mouseMove = "True"
    EndSub

    Explained:

    The event handler is processed asynchronously to the Main Loop (UI thread). i.e. it's processed in another thread independent of the UI thread. 

    To avoid queuing up your OnMouseMove event handler don't do anything in it that takes time to process. All the sample does is set a flag: mouseMove = "True"

    This flag is then processed independently in your main loop for each loop (frame). Once it has been processed it is set to false ready for the next OnMouseMove to set it back to true.

    • Proposed as answer by jadamelioEditor Saturday, June 13, 2015 7:09 PM
    • Marked as answer by Ezra94 Sunday, June 14, 2015 5:27 PM
    Saturday, June 13, 2015 3:09 PM
    Moderator

All replies

  • (translated by Google translator)

    Where can I contact you for an active correspondence? Do you have an account on Facebook?

    Friday, June 12, 2015 5:36 AM
  • On point 4 recreating the shapes as you do is the only way to change the Z order (what is on top of what) without an extension.  With extension you can change the Z order of shapes.

    On point 5, I'm not sure exactly what the issue is as I can't reproduce, but maybe it is variables changing in event subroutines while they are being used in the main loop.

    Friday, June 12, 2015 7:08 PM
    Moderator
  • Hi, AbsoluteBeginner.

    The best way to contact me is through this post.

    Friday, June 12, 2015 7:14 PM
  • Hi, Litdiv

    Thank you for the response.

    Point 5 is unpredictable but under the conditions I specified can the yield the results I described. Did you remember to remove the code block labeled patch on line 44? If you do so, then tap any of the blocks in rapid succession should cause it to be displaced.

    Let me know if this works.


    • Edited by Ezra94 Friday, June 12, 2015 7:24 PM
    Friday, June 12, 2015 7:22 PM
  • OK I can reproduce it.  I can see no reason how your patch can fix it and in fact I can reproduce withut commenting the lines, especially if I do a very quick mouse clicks by using left and right buttons clicked almost simultaneusly.

    Drag with left mouse and also click the right button while over another shape, perhaps this can help work it out.

    Friday, June 12, 2015 7:51 PM
    Moderator
  • Hmmm . . . .

    When you reproduced the bug did the block you selected remain displaced or did it return to it original place when you released the mouse?

    Friday, June 12, 2015 8:03 PM
  • Does this fix it, CDC508-0

    Check the isMoving flag I added that ensures we only collect or drop in order.

    This also seems to have some issues, with debugging added CDC508-1.  In this case it seens to get in a state when mouse up event fires on mousedown????

    Starting to feel like a bug or something I don't understand - so start to simplify the code and try to getthesimplest code that show this.

    EDIT, maybe the last issue is your patch code.
    Friday, June 12, 2015 8:26 PM
    Moderator
  • Here is the program without the patch JZC747

    The Bug:

    If you click, with the left mouse (let's ignore the right mouse), the first block in the first column in rapid succession (or a couple clicks or even a single click), the block should be displaced at the top left corner. It will return to its original place if you click the empty space where it originally was.

    Let me know if you reproduce these results.

    I apologize. This program is too large in scale to understand in a short period of time. I will try to scale down the code that displays this problem.



    • Edited by Ezra94 Friday, June 12, 2015 8:51 PM
    Friday, June 12, 2015 8:40 PM
  • Yes, but only with rapid left right clicks.And for you with the mod I suggested, JZC747-0
    Friday, June 12, 2015 9:09 PM
    Moderator
  • Do you get the results with left and right clicks? Have you gotten the same results with just the left mouse?

    The mod you provided still produce the bug.

    I think I may have pinpointed the problem . . . .

    As I was reading the code, I commented the code block on line 138, which managed to remove the bug. However, by doing so, the program can't modify the z order. Also, this doesn't include the patch.

    Here is the program#: SRP108

    Perhaps the code block on line 138, which modifies the z order, is connected with the bug?

    I'll keep investigating.

    Thank you for your help.




    • Edited by Ezra94 Friday, June 12, 2015 10:21 PM
    Friday, June 12, 2015 9:22 PM
  • Only with right click to easily see the error - it could be some latency in creating shapes - maybe a larger delay in main loop - 20 ms is still 50 fps - more than needed for cards moving
    Friday, June 12, 2015 9:55 PM
    Moderator
  • Hi Litdiv,

    After reading all the replies in this post again, I noticed that there may be a misunderstanding.

    The original program (CDC508), which includes the patch, works as expected. The patch itself isn't a bug. When I mentioned that I had problem, I meant that I was looking for an alternative to the patch because I wasn't satisfied with my current solution, the patch, to the bug. The bug we're discussing only occurs without the patch. Without the patch, the user can click, with the left mouse, on a block and potentially can cause it to be displaced at the top of the left corner of the screen. Unlike the left mouse click, blocks are displaced with the right mouse click but return to its original place when the user release the mouse so we want to focus on the mouse left click.

    To summarize, the program with the patch works and prevent blocks from being displaced but I'm trying to find an alternative solution to the path.

    I hope this helps.

    Thank you.


    • Edited by Ezra94 Friday, June 12, 2015 10:10 PM
    Friday, June 12, 2015 10:09 PM
  • When you use right mouse click the bug occurs? Does the block stay at the top left corner?

    20ms delay in loop? I'll give that a try. I suspect that a delay might be the issue.


    • Edited by Ezra94 Friday, June 12, 2015 10:18 PM
    Friday, June 12, 2015 10:16 PM
  • Seems like situation is swapped. I get the bug with the left mouse and yourself with right mouse. Does the program operate fine when you use left mouse? I guess it's not too important. The bug still occurs.

    • Edited by Ezra94 Friday, June 12, 2015 10:26 PM
    Friday, June 12, 2015 10:25 PM
  • When you use right mouse click the bug occurs? Does the block stay at the top left corner?


    Sometimes or sometimes the block just gets stuck like it is dropped early.

    I coulnd't see why the patch worked so wanted  to understand the problem without it - the patch didn't explain it for me so looked for anoher underlying problem.

    Friday, June 12, 2015 10:26 PM
    Moderator
  • To make sure, the program works with the patch? For me, left mouse click works and right mouse click cause block to be displaced but returned to original spot when mouse released. Overall, it works for me. Without patch, block is displaced at left corner if clicked with left (not sure about right mouse click but doesn't matter at that point).

    Thank you for being patient and taking the time to help me. I realize how difficult it can be to read and debug another programmer's code. I don't expect you to immediately understand my problem or derive a solution. All we can do, is work together: you provide guidance and myself explaining my problem as clearly as possible and offering any help I can. I should be doing most of the work since it's my problem.

    I'll work on rewriting the delay in the main loop. If that doesn't work, I'll let you know.

    If that doesn't work I may have to cut down the code. Like you mentioned earlier, I may have to write a smaller version that displays this bug.

    I'll keep you posted.






    • Edited by Ezra94 Friday, June 12, 2015 11:38 PM
    Friday, June 12, 2015 11:27 PM
  • I had a go at this since its a nice project - if you want I could show my solution, or you can work on yours.
    Saturday, June 13, 2015 1:47 PM
    Moderator
  • Here's a program I did ages ago that handles Z-orders with native SB.

    JQD875   Runs local only.

    Point 4: You're right the only way to Z order is by remove and add. Don't worry about the flicker in the top left, with careful code the eye can't see it.

    Point 3: Use a frame rate to delay your main loop 20ms = 50fps. Plenty of time to get stuff done in your Main Loop (UI thread). Register your events and assign the event handler name, e.g.

    GraphicsWindow.MouseMove = OnMouseMove 

    The event handler is:

    Sub OnMouseMove
      mouseMove = "True"
    EndSub

    Explained:

    The event handler is processed asynchronously to the Main Loop (UI thread). i.e. it's processed in another thread independent of the UI thread. 

    To avoid queuing up your OnMouseMove event handler don't do anything in it that takes time to process. All the sample does is set a flag: mouseMove = "True"

    This flag is then processed independently in your main loop for each loop (frame). Once it has been processed it is set to false ready for the next OnMouseMove to set it back to true.

    • Proposed as answer by jadamelioEditor Saturday, June 13, 2015 7:09 PM
    • Marked as answer by Ezra94 Sunday, June 14, 2015 5:27 PM
    Saturday, June 13, 2015 3:09 PM
    Moderator
  • Solitaire. Good idea for an SB game. Might try this one too.
    Saturday, June 13, 2015 3:31 PM
    Moderator
  • By all means litdiv please post your code. Even if it doesn't solve my bug, I'm curious to see an alternative approach to solitaire. I may not look or comment on your code immediately until I've tried to figure it on my own. It looks like Jibba Jabba has joined the discussion so I'm sure he's curious too!




    • Edited by Ezra94 Saturday, June 13, 2015 5:31 PM
    Saturday, June 13, 2015 5:27 PM
  • Hi Jibba Jabba,

    Thank you for the z order sample.

    I'm currently reimplementing the delay in my program.

    I suspect that the bug in my program is due to a poorly written delay structure.

    Saturday, June 13, 2015 5:46 PM
  • Import KDD528.  You can comment the extension Z order and uncomment the delete/recreate shapes to not use extension.
    • Marked as answer by Ezra94 Sunday, June 14, 2015 5:27 PM
    Saturday, June 13, 2015 9:17 PM
    Moderator
  • Thank you Litdiv. This will help me see where I went wrong with my program.

    Also, I have suggestion. Could this be a game challenge for the next challenge of the month?

    I hope to have this completed by July. If I have anymore questions, I'll be sure to ask.

    Sunday, June 14, 2015 5:30 PM
  • Just made a quick puzzle and put it here, as about Z-Order of shapes. ID: WZJ402

    If you look at LitDev's beta download, you'll find new LDImage.SplitImage method, which is optimal to split multiple images, button strips and, yes, puzzle parts in ImageList.

    Keys: Left/Right, Up/Down to move all parts;  S .. Shuffle, T .. template preview on/off (a turn counts twice)

    For another puzzle, simply dragNdrop an image from explorer into the GW.

    (PS: Could be refined/simplified a bit, bt it's late...)

    Following is the starting SB image (SmallBasicLogo.png):

    Edit: In line 49 (before removing the first/upper '...harmful..blabla..' comment) please correct under 'Sub LoadParts' the typo from ...

    GraphicsWindow.DrawRectangle((gw-h)/2, (gh-h)/2, w,h)   ' to ...

    GraphicsWindow.DrawRectangle((gw-w)/2, (gh-h)/2, w,h)   ' !!

    And: The 2 Subs 'Sub Template' and 'Sub SplittedImages'  are unused and can be removed.

    Tuesday, June 16, 2015 10:09 PM
    Answerer
  • I added this to split this image for solitair cards.

    Wednesday, June 17, 2015 5:51 PM
    Moderator
  • Thanks for KDD528 litdev.

    Yeah Ezra make a community suggestion for this to be in July challenge. MAD game!

    For me there's a lot going on in this game.

    Wednesday, June 17, 2015 8:03 PM
    Moderator