Results 1 to 9 of 9

Thread: beginner prob

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    4

    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

  2. #2
    Frenzied Member
    Join Date
    Jul 2009
    Posts
    1,103

    Re: beginner prob

    why dont you start playing with random number?

    If you find my reply helpful , then rate it

  3. #3
    Addicted Member theonetrueace's Avatar
    Join Date
    Jan 2002
    Location
    South Alabama
    Posts
    196

    Re: beginner prob

    Quote Originally Posted by gautamshaw View Post
    why dont you start playing with random number?
    what he said....

    http://msdn.microsoft.com/en-us/libr...em.random.aspx

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    4

    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

  5. #5
    Hyperactive Member The Fire Snake's Avatar
    Join Date
    Sep 2009
    Location
    USA
    Posts
    401

    Re: beginner prob

    Quote Originally Posted by harry85 View Post
    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

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    4

    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

  7. #7
    Addicted Member DramaQueen's Avatar
    Join Date
    Mar 2010
    Posts
    187

    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:
    1. Dim C As Card = Cards(5)
    2.  
    3. If C.TimesCalled < 4 Then
    4.     C.Call()
    5.     C.TimesCalled +=1
    6. Else
    7.     GetAnotherCard()
    8. End If

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    4

    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

  9. #9
    Hyperactive Member The Fire Snake's Avatar
    Join Date
    Sep 2009
    Location
    USA
    Posts
    401

    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:
    1. Dim rnd As New Random()
    2.  
    3. 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
  •  



Click Here to Expand Forum to Full Width