none
Make 3x3 Puzzle RRS feed

  • Question

  • I would like to create a Shuffle Game in Visual Basic 2019

    This shuffle game contains

    One table layout panel (3x3)

    Nine buttons named from Button1 to Button9, and the button texts are named from 1 to 9

    The puzzle auto shuffle when i'm start the form (start debuging)

    When I click on a button inside the table layout panel, the button moves into the empty spot next to it in any direction (Up, Left, Right, Bottom), if there's no empty spot next to the button then nothing happens when I click on it.

    The shuffle game ends once all the numbers are in order from 1 to 9, and a message shows that the game has been completed, in whatever number of times I clicked the buttons, e.g. if I arranged all the numbers in order in 17 clicks, the message says: You completed this game in 17 clicks.

    I want to know how to do this, please tell me, and if any of you who answers the question think I need to add a button16 into the empty spot of the table layout panel and make the text of that button blank, tell me.

    P.S

    I have seen similar tutorials on how to create shuffle game in vb on youtube, but in those tutorials they worked through all the  button click event code, and they also worked through all the buttons in the checking the puzzle solved code (which I do not want to do because it would not be convenient).

    Thanks

    Thursday, March 26, 2020 4:08 PM

All replies

  • Hi

    OK, then to create such a game., follow exactly, the instructions you mention in your post. Be sure to come back here when you have any issues.


    Regards Les, Livingston, Scotland

    Thursday, March 26, 2020 4:38 PM
  • The same reply as Les. 

    However, you did not ask for code but how to do it. 

    Simply draw your buttons on a form, don't use the table layout, much to difficult, but use a panel. 

    Those buttons will all be arranged in panel controls. From each button you can recognise the Left position and the Top position. 

    There is one piece of code I will help you with otherwise you will create most probably spagetthi.

    With this code you can see which button is clicked.

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click, button2.click, button3.click ' And so On until 9'
            Dim TheClickedControl = DirectCast(sender, Button)
            If TheClickedControl.Left = ' and so on'
        End Sub
    And this you should be able to do it. This forum is no code service as Les mostly writes and not a schoolboy cheat helper (although I think some moderators think it is) and they are probably proud that they can solve this in fact easy problems. 


    Success
    Cor




    Thursday, March 26, 2020 7:23 PM
  • Hi nnd10,

    How is the question going? Please let me know if you need further assistance.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 31, 2020 2:12 AM
    Moderator
  • Did you try to type "Shuffle Game" VB.NET

    in google ?

    Dozens of results.

    Monday, April 27, 2020 12:10 PM