|
-
Apr 15th, 2010, 09:49 AM
#1
Thread Starter
New Member
beginner prob
hi
I'm doing a project at the moment for school,I need to randomly pick a number from an array,which I can do but I can only use that number three times,I dont want an answer just a few hints please
thanks
-
Apr 15th, 2010, 10:31 AM
#2
Frenzied Member
Re: beginner prob
why dont you start playing with random number?
If you find my reply helpful , then rate it
-
Apr 15th, 2010, 10:40 AM
#3
Addicted Member
Re: beginner prob
 Originally Posted by gautamshaw
why dont you start playing with random number?
what he said....
http://msdn.microsoft.com/en-us/libr...em.random.aspx
-
Apr 15th, 2010, 12:08 PM
#4
Thread Starter
New Member
Re: beginner prob
I understand the random function,I just dont know how to keep count of which element of the array I already used
-
Apr 15th, 2010, 12:13 PM
#5
Hyperactive Member
Re: beginner prob
 Originally Posted by harry85
I understand the random function,I just dont know how to keep count of which element of the array I already used
Why not use another array(or List collection) to store the indices that you already used from the first array. So every time you use an element from the first array, store that integer index into the 2nd array. Then when you go to grab a value from the first array check this 2nd array to see if you have already looked at that index.
Remember to click on the scales to the left and rep me if I helped 
-
Apr 16th, 2010, 05:07 AM
#6
Thread Starter
New Member
Re: beginner prob
I have a modified black jack game to create,which deals two cards to the dealer and the player,The value of the cards are stored in an array,which are 1 to 11,I can only use each card 4 times,how do i keep count of which card i have already used,i tried using two arrays but getting nowhere
-
Apr 16th, 2010, 05:50 AM
#7
Addicted Member
Re: beginner prob
Write a class for the cards, with properties Number and TimesCalled. Create a list of the cards, and then you can just do something like this...
vb Code:
Dim C As Card = Cards(5) If C.TimesCalled < 4 Then C.Call() C.TimesCalled +=1 Else GetAnotherCard() End If
-
Apr 16th, 2010, 06:08 AM
#8
Thread Starter
New Member
Re: beginner prob
Thanks for the reply,i havent done classes in school yet so im going to have to do it another way,im randomly picking two card values each for the player and the computer and adding them together to give the total of the first hand,so im going to have to keep count of them first
Code:
Dim deck() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
Dim deck2(10) As Integer
Dim dtotal As Integer
Dim ptotal As Integer
Dim num As Integer
Dim num2 As Integer
Dim num3 As Integer
Dim num4 As Integer
Dim dh As Integer
Dim dh2 As Integer
Dim ph As Integer
Dim ph2 As Integer
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize()
num = Int(Rnd() * (10) + 1)
num2 = Int(Rnd() * (10) + 1)
num3 = Int(Rnd() * (10) + 1)
num4 = Int(Rnd() * (10) + 1)
dh = deck(num)
dh2 = deck(num2)
ph = deck(num3)
ph2 = deck(num4)
dtotal = dh + dh2
ptotal = ph + dh2
txtdealer.Text = CStr(dtotal)
txtplayer.Text = CStr(ptotal)
End Sub
End Class
-
Apr 16th, 2010, 11:48 AM
#9
Hyperactive Member
Re: beginner prob
Have you done structures yet? If so use that concept as they are like a less sophisticated class. Also the way you are trying to create random numbers is not correct/appropriate in VB.Net. Don't use Randomize() or Rnd. Use the Random class like this:
vb Code:
Dim rnd As New Random() Dim Random As Integer = rnd.Next()
Remember to click on the scales to the left and rep me if I helped 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|