Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,075 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,799 people online right now. Registration is fast and FREE... Join Now!




Checkers Game

 
Reply to this topicStart new topic

Checkers Game, different way to do it

Rating  1
yowutup11
12 May, 2008 - 06:00 AM
Post #1

New D.I.C Head
*

Joined: 7 Mar, 2008
Posts: 42

ok so I have been working on a checker game. So far i have code that allows all the white checkers to move properly. The only problem is that this code is about 5000 lines long. I am sure there is a quicker and easier way to do it.

Here is the code for one checker to move in all squares possible for it to go into:

CODE

elect Case str1
            Case 1
                If picCheckers1.Location.X < 271 And picCheckers1.Location.Y > 114 And Open5 = True Then
                    picCheckers1.Location = square5
                    str1 = 5
                    Open1 = True
                    Open5 = False
                    lblTurn.Text = "Yellow"
                Else
                    If picCheckers1.Location.X > 309 And picCheckers1.Location.Y > 114 And Open6 = True Then
                        picCheckers1.Location = square6
                        str1 = 6
                        Open1 = True
                        Open6 = False
                        lblTurn.Text = "Yellow"
                    Else
                        picCheckers1.Location = square1
                        str1 = 1
                    End If
                End If
            Case 5
                If picCheckers1.Location.X > 269 And picCheckers1.Location.Y > 149 And Open9 = True Then
                    picCheckers1.Location = square9
                    str1 = 9
                    Open5 = True
                    Open9 = False
                    lblTurn.Text = "Yellow"
                Else
                    picCheckers1.Location = square5
                    str1 = 1
                End If
            Case 6
                If picCheckers1.Location.X < 306 And picCheckers1.Location.Y > 149 And Open9 = True Then
                    picCheckers1.Location = square9
                    str1 = 9
                    Open6 = True
                    Open9 = False
                    lblTurn.Text = "Yellow"
                Else
                    If picCheckers1.Location.X > 344 And picCheckers1.Location.Y > 149 And Open10 = True Then
                        picCheckers1.Location = square10
                        str1 = 10
                        Open6 = True
                        Open10 = False
                        lblTurn.Text = "Yellow"
                    Else
                        picCheckers1.Location = square6
                        str1 = 6
                    End If
                End If
            Case 9
                If picCheckers1.Location.X < 266 And picCheckers1.Location.Y > 189 And Open13 = True Then
                    picCheckers1.Location = square13
                    str1 = 13
                    lblTurn.Text = "Yellow"
                    Open9 = True
                    Open13 = False
                Else
                    If picCheckers1.Location.X > 307 And picCheckers1.Location.Y > 189 And Open14 = True Then
                        picCheckers1.Location = square14
                        str1 = 14
                        lblTurn.Text = "Yellow"
                        Open9 = True
                        Open14 = False
                    Else
                        picCheckers1.Location = square9
                        str1 = 9
                    End If
                End If
            Case 10
                If picCheckers1.Location.X < 345 And picCheckers1.Location.Y > 186 And Open14 = True Then
                    picCheckers1.Location = square14
                    str1 = 14
                    Open10 = True
                    Open13 = False
                    lblTurn.Text = "Yellow"
                Else
                    If picCheckers1.Location.X > 388 And picCheckers1.Location.Y > 186 And Open15 = True Then
                        picCheckers1.Location = square15
                        str1 = 15
                        Open10 = True
                        Open15 = False
                        lblTurn.Text = "Yellow"
                    Else
                        picCheckers1.Location = square10
                        str1 = 10
                    End If
                End If
            Case 13
                If picCheckers1.Location.X > 274 And picCheckers1.Location.Y > 224 And Open17 = True Then
                    picCheckers1.Location = square17
                    str1 = 17
                    lblTurn.Text = "Yellow"
                    Open13 = True
                    Open17 = False
                Else
                    picCheckers1.Location = square13
                    str1 = 13
                End If
            Case 14
                If picCheckers1.Location.X < 306 And picCheckers1.Location.Y > 224 And Open17 = True Then
                    picCheckers1.Location = square17
                    str1 = 17
                    lblTurn.Text = "Yellow"
                    Open14 = True
                    Open17 = False
                Else
                    If picCheckers1.Location.X > 349 And picCheckers1.Location.Y > 224 And Open18 = True Then
                        picCheckers1.Location = square18
                        str1 = 18
                        lblTurn.Text = "Yellow"
                        Open14 = True
                        Open18 = False
                    Else
                        picCheckers1.Location = square14
                        str1 = 14
                    End If
                End If
            Case 15
                If picCheckers1.Location.X < 381 And picCheckers1.Location.Y > 224 And Open18 = True Then
                    picCheckers1.Location = square18
                    str1 = 18
                    Open15 = True
                    Open18 = False
                    lblTurn.Text = "Yellow"
                Else
                    If picCheckers1.Location.X > 424 And picCheckers1.Location.Y > 224 And Open19 = True Then
                        picCheckers1.Location = square19
                        str1 = 19
                        Open15 = True
                        Open19 = False
                        lblTurn.Text = "Yellow"
                    Else
                        picCheckers1.Location = square15
                        str1 = 15
                    End If
                End If
            Case 17
                If picCheckers1.Location.X < 266 And picCheckers1.Location.Y > 255 And Open21 = True Then
                    picCheckers1.Location = square21
                    str1 = 21
                    lblTurn.Text = "Yellow"
                    Open17 = True
                    Open21 = False
                Else
                    If picCheckers1.Location.X > 307 And picCheckers1.Location.Y > 255 And Open22 = True Then
                        picCheckers1.Location = square22
                        str1 = 22
                        lblTurn.Text = "Yellow"
                        Open17 = True
                        Open22 = False
                    Else
                        picCheckers1.Location = square17
                        str1 = 17
                    End If
                End If
            Case 18
                If picCheckers1.Location.X < 351 And picCheckers1.Location.Y > 259 And Open22 = True Then
                    picCheckers1.Location = square22
                    str1 = 22
                    Open18 = True
                    Open22 = False
                    lblTurn.Text = "Yellow"
                Else
                    If picCheckers1.Location.X > 379 And picCheckers1.Location.Y > 259 And Open23 = True Then
                        picCheckers1.Location = square23
                        str1 = 23
                        Open18 = True
                        Open23 = False
                        lblTurn.Text = "Yellow"
                    Else
                        picCheckers1.Location = square18
                        str1 = 18
                    End If
                End If
            Case 19
                If picCheckers1.Location.X < 416 And picCheckers1.Location.Y > 264 And Open23 = True Then
                    picCheckers1.Location = square23
                    str1 = 23
                    Open19 = True
                    Open23 = False
                    lblTurn.Text = "Yellow"
                Else
                    If picCheckers1.Location.X > 459 And picCheckers1.Location.Y > 259 And Open24 = True Then
                        picCheckers1.Location = square24
                        str1 = 24
                        Open19 = True
                        Open24 = False
                        lblTurn.Text = "Yellow"
                    Else
                        picCheckers1.Location = square19
                        str1 = 19
                    End If
                End If
            Case 21
                If picCheckers1.Location.X > 274 And picCheckers1.Location.Y > 299 And Open25 = True Then
                    picCheckers1.Location = square25
                    str1 = 25
                    Open21 = True
                    Open25 = False
                    lblTurn.Text = "Yellow"
                Else
                    picCheckers1.Location = square21
                    str1 = 21
                End If
            Case 22
                If picCheckers1.Location.X < 311 And picCheckers1.Location.Y > 299 And Open25 = True Then
                    picCheckers1.Location = square25
                    str1 = 25
                    Open22 = True
                    Open25 = False
                    lblTurn.Text = "Yellow"
                Else
                    If picCheckers1.Location.X > 344 And picCheckers1.Location.Y > 299 And Open26 = True Then
                        picCheckers1.Location = square26
                        str1 = 26
                        Open22 = True
                        Open26 = False
                        lblTurn.Text = "Yellow"
                    Else
                        picCheckers1.Location = square22
                        str1 = 22
                    End If
                End If
            Case 23
                If picCheckers1.Location.X < 383 And picCheckers1.Location.Y > 299 And Open26 = True Then
                    picCheckers1.Location = square26
                    str1 = 26
                    Open23 = True
                    Open26 = False
                    lblTurn.Text = "Yellow"
                Else
                    If picCheckers1.Location.X > 459 And picCheckers1.Location.Y > 299 And Open27 = True Then
                        picCheckers1.Location = square27
                        str1 = 27
                        Open23 = True
                        Open27 = False
                        lblTurn.Text = "Yellow"
                    Else
                        picCheckers1.Location = square23
                        str1 = 23
                    End If
                End If
            Case 24
                If picCheckers1.Location.X < 459 And picCheckers1.Location.Y > 300 And Open27 = True Then
                    picCheckers1.Location = square27
                    str1 = 27
                    Open24 = True
                    Open27 = False
                    lblTurn.Text = "Yellow"
                Else
                    If picCheckers1.Location.X > 500 And picCheckers1.Location.Y > 300 And Open28 = True Then
                        picCheckers1.Location = square28
                        str1 = 28
                        Open24 = True
                        Open28 = False
                        lblTurn.Text = "Yellow"
                    Else
                        picCheckers1.Location = square24
                        str1 = 24
                    End If
                End If
            Case 25
                If picCheckers1.Location.X < 271 And picCheckers1.Location.Y > 339 And Open29 = True Then
                    picCheckers1.Location = square29
                    str1 = 29
                    Open25 = True
                    Open29 = False
                    lblTurn.Text = "Yellow"
                Else
                    If picCheckers1.Location.X > 309 And picCheckers1.Location.Y > 339 And Open30 = True Then
                        picCheckers1.Location = square30
                        str1 = 30
                        Open25 = True
                        Open30 = False
                        lblTurn.Text = "Yellow"
                    Else
                        picCheckers1.Location = square25
                        str1 = 25
                    End If
                End If
            Case 26
                If picCheckers1.Location.X < 346 And picCheckers1.Location.Y > 339 And Open30 = True Then
                    picCheckers1.Location = square30
                    str1 = 30
                    Open26 = True
                    Open30 = False
                    lblTurn.Text = "Yellow"
                Else
                    If picCheckers1.Location.X > 384 And picCheckers1.Location.Y > 339 And Open31 = True Then
                        picCheckers1.Location = square31
                        str1 = 31
                        Open26 = True
                        Open31 = False
                        lblTurn.Text = "Yellow"
                    End If
                End If
            Case 27
                If picCheckers1.Location.X < 421 And picCheckers1.Location.Y > 339 And Open31 = True Then
                    picCheckers1.Location = square31
                    str1 = 31
                    Open27 = True
                    Open31 = False
                    lblTurn.Text = "Yellow"
                Else
                    If picCheckers1.Location.X > 459 And picCheckers1.Location.Y > 339 And Open32 = True Then
                        picCheckers1.Location = square32
                        str1 = 32
                        Open27 = True
                        Open32 = False
                        lblTurn.Text = "Yellow"
                    Else
                        picCheckers1.Location = square27
                        str1 = 27
                    End If
                End If
            Case 28
                If picCheckers1.Location.X < 500 And picCheckers1.Location.Y > 339 And Open32 = True Then
                    picCheckers1.Location = square32
                    str1 = 32
                    Open28 = True
                    Open32 = False
                    lblTurn.Text = "Yellow"
                Else
                    picCheckers1.Location = square28
                    str1 = 28
                End If
        End Select


the case is the square that the checker is currently in.

I also will attach a zip file of the game so that you can understand it more

there are no errors and everything is working fine but I am trying to find a quicker way to code that doesnt take another 5000 lines of code


Attached File(s)
Attached File  The_Checkers_Game.zip ( 430.85k ) Number of downloads: 90
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:10PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month