1 Replies - 919 Views - Last Post: 29 October 2019 - 05:59 PM Rate Topic: -----

#1 Norman_Bates   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 26-February 13

Loop round board

Posted 29 October 2019 - 04:24 PM

I'm trying to create a Monopoly style game. I've got the game piece moving around the board, but I'm having some trouble with the maths keeping it going forward and also getting it to loop round if the piece's current position + dice roll takes > 40.
This is my code
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        lblDice1.Text = rnd.Next(1, 7)
        lblDice2.Text = rnd.Next(1, 7)

        If CInt(lblDice1.Text) = CInt(lblDice2.Text) Then
            iDouble += 1
            If iDouble = 3 Then
                isDouble = True
            End If
        Else
            iDouble = 0
        End If

        If isDouble = True Then
            Button1.Parent = iPic(10)
            Button1.Parent = iPic(10)
            Button1.Top = iPic(10).Height / 2 - Button1.Height / 2
            Button1.Left = iPic(10).Width / 2 - Button1.Width / 2
        End If

        iCounter = (CInt(lblDice1.Text) + (CInt(lblDice2.Text)))

        Try
            If lstPos = 0 Then
                nxtPos = iCounter
                lstPos = iCounter
            Else
                If lstPos + iCounter > 40 Then
                    nxtPos = (lstPos + iCounter) - 40
                Else
                    lstPos = nxtPos
                    nxtPos = lstPos + iCounter
                End If
            End If
            Label1.Text = "iCounter: " & iCounter
            Label2.Text = "lstPos: " & lstPos
            Label3.Text = "nxtPos: " & nxtPos
            Button1.Parent = iPic(nxtPos)
            Button1.Top = iPic(nxtPos).Height / 2 - Button1.Height / 2
            Button1.Left = iPic(nxtPos).Width / 2 - Button1.Width / 2
            Button1.Select()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub



The "isDouble" and "iDouble" are just to check if the player rolls 3 doubles in a row and sends the piece to jail if they do.

The problem I'm having is in the Try.....Catch block. Where am I going wrong?
I'm using label1, label2, and label3 just to visualise what is in my 3 integer values that are moving the piece

Is This A Good Question/Topic? 0
  • +

Replies To: Loop round board

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15357
  • View blog
  • Posts: 61,571
  • Joined: 12-June 08

Re: Loop round board

Posted 29 October 2019 - 05:59 PM

I am not certain what the issue is. Is it moving the piece when it hits a right corner, or tracking it?

Side note - you would honestly do better _NOT_ using the UI elements as variable holders. Instead have a collection or some other variable setup as the actual board, and then ship information to the UI as needed.

Even a basic array would help. That's the "official board" and the UI just represents what is on the current official board.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1