Blackjack class help

Khyzinn

New member
Joined
Mar 8, 2010
Messages
4
Programming Experience
Beginner
Hi guys,

A week ago i posted something because i needed help with my array, problems are solved with that. We need to make a blackjack game for a school project, and now we got this nice, working code. Small problem, when we showed this to our teacher, he said we MUST have classes (which we don't). So we're stuck with making a class to show our cards. I'll just post the code we have, so you can see. Just some tips on how we could make some classes out of this would be nice, we're really stuck.

Thanks in advance
 

Attachments

  • VB.Net Blackjack code.zip
    25.1 KB · Views: 31
i've not looked at your project, but here is a tip. Classes can be re-used, so you could create a Card class that has some properties like Number and Suit. Then you just need a collection and you can simply do what you need with the card classes.

VB.NET:
Public Class Card
    Private _number As String
    Private _suit As String

    Public Property Number() As String
        Get
            Return _number
        End Get
        Set(ByVal value As String)
            _number = value
        End Set
    End Property

    Public Property Suit() As String
        Get
            Return _suit
        End Get
        Set(ByVal value As String)
            _suit= value
        End Set
    End Property
End Class

and the collection

VB.NET:
Imports System.Collections

Public Class CardCollection
    Inherits CollectionBase

    Default Public Property Item(ByVal index As Integer) As Card
        Get
            Return CType(List(index), Card)
        End Get
        Set(ByVal value As Card)
            List(index) = value
        End Set
    End Property

    Public Function Add(ByVal value As Card) As Integer
        Return List.Add(value)
    End Function 'Add

    Public Function IndexOf(ByVal value As Card) As Integer
        Return List.IndexOf(value)
    End Function 'IndexOf

    Public Sub Insert(ByVal index As Integer, ByVal value As Card)
        List.Insert(index, value)
    End Sub 'Insert

    Public Sub Remove(ByVal value As Card)
        List.Remove(value)
    End Sub 'Remove

    Public Function Contains(ByVal value As Card) As Boolean
        ' If value is not of type Card, this will return false.
        Return List.Contains(value)
    End Function 'Contains
End Class

I hope that helps
 
r3plica, about CollectionBase, from .Net 2.0 onwards you should inherit Collection(Of T) instead, see post 3 here: http://www.vbdotnetforums.com/windows-forms/23067-collection-list.html
You can also skip defining a strongly typed collection type and instead just declare an instance of List(Of T) that you use for storage, in this case a List(Of Card).
 
and how can we integrate this in our code? Dim _card as New Card?
and should we place our array in the card too, or will things get complicated?
 
Back
Top