You are viewing an archive of Victory Road.
Victory Road closed on January 8, 2018. Thank you for making us a part of your lives since 2006! Please read this thread for details if you missed it.
; - ; Visual Basic is so easy . . until I want to do things that become complicated.
So I'm probably missing some very easy method to what I want to do, but I just dont see it. I'm using VisualBasic2008, and I want to do a program w/ a memory game. So my idea is;
Buttons on the interface. Then the first button is clicked (say btn1A) the number or image below is shown (or rather the button becomes invisible). This "image" has a value. Then the user clicks another button and gets a different value. If the two match then both buttons remain invisible and then the user gets "points" added. if they are wrong then the buttons become visible again.
My problem lies in the begining step, randomizing the numbers or values under the buttons. When I start up I want to randomly assign values to each spot, making sure that there will be pairs. So I would;
1A = Random number from 1 - 10 (There are 20 tiles, 10 pairs)
1B = Random number from 1 - 10 (not including 1A.)
There is my problem! I can generate the random numbers --
Dim RanMem As Random
num = RanMem.Next(1, 11)
Cards(i) = num
Public Class frmMainGUI
Dim Cards(19) As Integer
Dim num As Integer
'I planned on having the GUI ask what you want to play and if you choose to play memory then the panel containing memory will be displayed.
Private Sub PanelMemory_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PanelMemory.VisibleChanged
'Just to be sure that numbers are only generated when the user can see the panel.
If PanelMemory.Visible = True Then
'Loop for the 20 squares (5 x 4)
For i As Integer = 0 To 19
Dim RanMem As Random
num = RanMem.Next(1, 11)
Cards(i) = num
Next
End If
End Sub
End Class
I must apologize. I have been out of the progamming loop for a month now (only making tiny changes to stuff like site code). As I will be forced to resume programming (for class), I'll be able to help you in a couple days when I'm thinking along that track.
Sorry.
But if you are lucky enough to remind me 5 minutes after I finish my CS homework, I'd have a much easier time. ![]()
I don't know how to explain this in VB but try to translate my python to vb
|
//first save possable valurs to list/array items = [0,1,2,3,4,5,6,7,8,9] //returns one item from list and removes it from list val1 = items.pop(random(9)) val2 = items.pop(random(8 )) val3 = items.pop(random(7)) //var1-3 are what you app needs |