#1
|
|||
|
|||
Need some VB help (numbers, lists, random thingy, eliminating variables)
; - ; 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 -- Code:
Dim RanMem As Random num = RanMem.Next(1, 11) Cards(i) = num -- But I have no idea how to "eliminate" a number from the set without making a loop that would check the random number after it is generated and force the program to make a new random number. Any suggestions? D: |
#5
|
|||
|
|||
Code:
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 So I planned on having this code generate random number from 1 - 10 twice, but now I realize that I'd need to have it do that three times maybe? That might be excessive but I want to randomly choose the tiles to pair instead of having all the tiles on the top be one set of pairs and all the tiles on the bottom be another. I don't know if that is clear. |
#8
|
||||
|
||||
I don't know how to explain this in VB but try to translate my python to vb
Quote:
Last edited by KingOfKYA; January 28, 2010 at 12:44:13 AM. |
|