Question Some Questions Involving BlackJack

s2d806

New member
Joined
Mar 15, 2010
Messages
3
Programming Experience
Beginner
Greetings,

I'm having some trouble making my BlackJack game.

This is my code:

VB.NET:
Public Class Card

#Region "structures"

  'Een eige type/structuur maken "CardProperty"
  Private Structure CardProperty
    Dim soort As String
    Dim score As Integer
    Dim rang As Integer
    Dim front As String
    Dim back As String
    Dim schudden As Boolean
  End Structure

#End Region

#Region "Declarations"

  Private deck(51) As CardProperty

#End Region

#Region "Functions"

  'Maakt de kaarten en zet ze in goede volgorde

  Public Function Createcards() As String

    'Declaratie van x,y: twee tellers voor de lussen
    Dim x As Integer
    Dim y As Integer

    'harten
    For x = 1 To 13 Step +1

      'toewijzen van rang, soort en afbeelding van de kaart
      deck(x).rang = x
      deck(x).soort = "harten"
      deck(x).front = "C:\Documents and Settings\Simon De Beukeleer\Desktop\BlackJackGame\BlackJackGame\images\harten" & x & ".jpg"

      'Score toewijzen aan de kaart
      'Nog geen rekening gehouden met aas
      If x < 10 Then
        deck(x).score = x
      ElseIf x > 10 Then
        deck(x).score = 10
      End If

    Next x

    'klaveren
    For x = 14 To 26 Step +1

      'toewijzen van rang, soort en afbeelding van de kaart
      deck(x).rang = (x - 13)
      deck(x).soort = "klaveren"
      deck(x).front = "C:\Documents and Settings\Simon De Beukeleer\Desktop\BlackJackGame\BlackJackGame\images\klaveren" & (x - 13) & ".jpg"

      'Score toewijzen aan de kaart
      'Nog geen rekening gehouden met aas
      If (x - 13) < 10 Then
        deck(x).score = (x - 13)
      ElseIf (x - 13) > 10 Then
        deck(x).score = 10
      End If
    Next x

    'ruiten
    For teller = 27 To 40 Step +1

      'toewijzen van rang, soort en afbeelding van de kaart
      deck(x).rang = (x - 26)
      deck(x).soort = "ruiten"
      deck(x).front = "C:\Documents and Settings\Simon De Beukeleer\Desktop\BlackJackGame\BlackJackGame\images\ruiten" & (x - 26) & ".jpg"

      'Score toewijzen aan de kaart
      'Nog geen rekening gehouden met aas
      If (x - 26) < 10 Then
        deck(x).score = (x - 26)
      ElseIf (x - 26) > 10 Then
        deck(x).score = (10)
      End If

    Next teller

    'schoppen
    For x = 40 To 52 Step +1

      'toewijzen van rang, soort en afbeelding van de kaart
      deck(x).rang = (x - 39)
      deck(x).soort = "schoppen"
      deck(x).front = "C:\Documents and Settings\Simon De Beukeleer\Desktop\BlackJackGame\BlackJackGame\images\" & (x - 39) & ".jpg"

      'Score toewijzen aan de kaart
      'Nog geen rekening gehouden met aas
      If (x - 39) < 10 Then
        deck(x - 39).score = (x - 39)
      ElseIf (x - 39) > 10 Then
        deck(x - 39).score = 10
      End If

    Next x

    'Kaarten zijn niet geschud en achterkant is overal zelfde afbeelding
    For y = 1 To 52
      deck(y).schudden = False
      deck(y).back = "Img\back.jpg"
    Next y

  End Function

#End Region

End Class

This is what I got so far. I think my array is ok, if not feel free to correct me or make suggestions to improve.

My first problem is getting my image from my array into a picturebox.
My second problem is to be able to shuffle the deck and draw random cards into the picturebox.

Any help is welcome.
 
VB.NET:
Dim deck As New List(Of Card)

'Populate deck with 52 cards.

Dim rng As New Random

'Shuffle deck.
deck = deck.OrderBy(Function(c) rng.NextDouble()).ToList()
The easiest way to randomise a list is using LINQ. You can then simply Remove items from the List.
 
We have to shuffle cards by putting our array of cards into another temporary array, not a list. And how do we acces the array into another class?
 
For your first problem, you can set an image in a picturebox by using the LoadAsync function. (It also has a Load function but if you need to load multiple images at ones it will lag your program)

VB.NET:
PictureBox.LoadAsync(FilePath)

For your second problem you should look how you want to see who has wich cards. You could create a set of "Handen" all lists of integers wich point to specific cards in the deck. I would suggest to replace Schudden (Shuffled) within your CardProperty structure with Gedeeld (dealt).
VB.NET:
Private Sub TrekKaart(Hand as integer)
   Randomize
   Dim Kaart as integer 
   'Find a random undeald card
   Do
      Kaart = math.floor(rnd()*52)
   Loop until Kaart.Gedeeld = False
   'Add card to the hand
   Handen(Hand).Add(Kaart)
   'Set that card has been deald
   Kaart.Gedeeld = True
End Sub
In this way the deck is not actually shuffled previous to playing.
 
Back
Top