Ok so here's my code

spin is a button

P1 is a picture array and there are 4 of them

timer1 is a timer

Private Sub spin_Click()

If spin.Caption = "SPIN" Then

spin.Caption = "STOP"

Else

spin.Caption = "SPIN"

End If

If Timer1.Enabled = True Then

Timer1.Enabled = False

Else

Timer1.Enabled = True

End If

End Sub

Private Sub Timer1_Timer()

For i = 0 To 3

If P1(i).Left = "2520" Then

P1(i).Left = Rnmp

P1(i).Top = Rnmp

ElseIf P1(i).Left = "3720" Then

P1(i).Left = Rnmp

P1(i).Top = Rnmp

ElseIf P1(i).Left = "5280" Then

P1(i).Left = Rnmp

P1(i).Top = Rnmp

ElseIf P1(i).Left = "6480" Then

P1(i).Left = Rnmp

P1(i).Top = Rnmp

End If

Randomize

Rnmp = Int(Rnd * 4) + 1

Select Case Rnmp

Case "1"

P1(i).Top = "4680"

P1(i).Left = "2520"

Case "2"

P1(i).Top = "3480"

P1(i).Left = "3720"

Case "3"

P1(i).Top = "3480"

P1(i).Left = "5280"

Case "4"

P1(i).Top = "4680"

P1(i).Left = "6480"

End Select

Next i

l1.Caption = P1(0).Left & " " & P1(0).Top

l2.Caption = P1(1).Left & " " & P1(1).Top

l3.Caption = P1(2).Left & " " & P1(2).Top

l4.Caption = P1(3).Left & " " & P1(3).Top

End Sub

l1, l2, l3 and l4 are labels that show the positions of the pictures and they DO show that the pictures are overlapping

What happens with this code is the 4 pictures start in designated places, which are equivalent to each of the 4 cases. Picture one starts where case 1 is, picture 2 where case 2 is, etc.

The problem arises when I start "spinning" or moving the images. I want them to move to one of the case points other than where they start, and NOT overlapping another image where they currently do. They need to pick their own unused space and then keep moving to a different one.

How is this possible?

Thanks in advance,

Mike

spin is a button

P1 is a picture array and there are 4 of them

timer1 is a timer

Private Sub spin_Click()

If spin.Caption = "SPIN" Then

spin.Caption = "STOP"

Else

spin.Caption = "SPIN"

End If

If Timer1.Enabled = True Then

Timer1.Enabled = False

Else

Timer1.Enabled = True

End If

End Sub

Private Sub Timer1_Timer()

For i = 0 To 3

If P1(i).Left = "2520" Then

P1(i).Left = Rnmp

P1(i).Top = Rnmp

ElseIf P1(i).Left = "3720" Then

P1(i).Left = Rnmp

P1(i).Top = Rnmp

ElseIf P1(i).Left = "5280" Then

P1(i).Left = Rnmp

P1(i).Top = Rnmp

ElseIf P1(i).Left = "6480" Then

P1(i).Left = Rnmp

P1(i).Top = Rnmp

End If

Randomize

Rnmp = Int(Rnd * 4) + 1

Select Case Rnmp

Case "1"

P1(i).Top = "4680"

P1(i).Left = "2520"

Case "2"

P1(i).Top = "3480"

P1(i).Left = "3720"

Case "3"

P1(i).Top = "3480"

P1(i).Left = "5280"

Case "4"

P1(i).Top = "4680"

P1(i).Left = "6480"

End Select

Next i

l1.Caption = P1(0).Left & " " & P1(0).Top

l2.Caption = P1(1).Left & " " & P1(1).Top

l3.Caption = P1(2).Left & " " & P1(2).Top

l4.Caption = P1(3).Left & " " & P1(3).Top

End Sub

l1, l2, l3 and l4 are labels that show the positions of the pictures and they DO show that the pictures are overlapping

What happens with this code is the 4 pictures start in designated places, which are equivalent to each of the 4 cases. Picture one starts where case 1 is, picture 2 where case 2 is, etc.

The problem arises when I start "spinning" or moving the images. I want them to move to one of the case points other than where they start, and NOT overlapping another image where they currently do. They need to pick their own unused space and then keep moving to a different one.

How is this possible?

Thanks in advance,

Mike

http://www.acky.net/vb/vbgames/shuffle.zip

http://www.imt.net/~joe/matt/program/vb/Tutorials/ShuffleDeck.txt

You may also want to preset an array of positions:

Option Explicit

Private Type POINTAPI

X As Long

Y As Long

End Type

Dim pos(3) As POINTAPI

Private Sub Form_Load()

'Load positions

pos(0).Y = 4680

pos(0).X = 2520

pos(1).Y = 3480

pos(1).X = 3720

pos(2).Y = 3480

pos(2).X = 5280

pos(3).Y = 4680

pos(3).X = 6480

End Sub

Private Sub spin_Click()

Timer1.Enabled = Not (Timer1.Enabled)

Spin.Caption = IIf(Timer1.Enabled, "STOP", "SPIN")

End Sub

After shuffle do something like this:

For i= 0 to 3

p1(i).Move pos(Deck(i)).X, pos(Deck(i)).Y

Next

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

Option Explicit

Private Type POINTAPI

X As Long

Y As Long

End Type

Dim pos(3) As POINTAPI

Dim Cards(3) As Integer 'Cards is an array of 4 numbers 0-3

Dim CardValue, X

Private Sub spin_Click()

Timer1.Enabled = Not (Timer1.Enabled)

spin.Caption = IIf(Timer1.Enabled, "STOP", "SPIN")

End Sub

Private Sub Shuffle()

X = 0

Erase Cards

'This is where the random shuffle is made.

'First, we initialize the randomizer.

Randomize

'Cardvalue is then set as a random number from 1 to 4,

CardValue = Int((4 * Rnd) + 1)

'and the value of the first element of the array is set.

Cards(0) = CardValue

'We must repeat the last three steps for the next 11 cards, using the

'IsInArray function to check for duplicates.

For X = 1 To 3

Do While IsInArray = True

'If IsInArray is true, we keep looping until a non-duplicate number

'is generated by the randomizer.

Randomize

CardValue = Int((4 * Rnd) + 1)

IsInArray

Loop

Cards(X) = CardValue

Next X

End Sub

Public Function IsInArray() As Boolean

'This function checks for duplicate numbers in the array.

Dim Y As Integer

For Y = 0 To X

If CardValue = Cards(Y) Then

IsInArray = True

Exit Function

End If

Next Y

IsInArray = False

End Function

Private Sub Form_Load()

'Init positions

pos(0).Y = 4680

pos(0).X = 2520

pos(1).Y = 3480

pos(1).X = 3720

pos(2).Y = 3480

pos(2).X = 5280

pos(3).Y = 4680

pos(3).X = 6480

End Sub

Private Sub Timer1_Timer()

Dim i As Long

Shuffle

For i = 0 To 3

P1(i).Move pos(Cards(i) - 1).X, pos(Cards(i) - 1).Y

Next

L1.Caption = P1(0).Left & " " & P1(0).Top

L2.Caption = P1(1).Left & " " & P1(1).Top

L3.Caption = P1(2).Left & " " & P1(2).Top

L4.Caption = P1(3).Left & " " & P1(3).Top

End Sub