Thanks for the feedback. With your help, the BegnnerBlitzMax.pdf and some Googling this is what I came up with. It's got some basic functionality, that would be easy to add more to I think. It's also my first attempt with OOP, I think I'm slowly getting my head around it. :-)
If there is anything I should do differently, please let me know.
p.s. LarsG: De kommentarene dine hjalp ogsaa, selv om de ikke var paa Engelsk. :-)
If there is anything I should do differently, please let me know.
'==========' ' CARDDECK ' '==========' ' - deck of cards test. Strict 'Global Deck:TList = CreateList() Global Suits:String[] = [ "clubs","diamonds","hearts","spades" ] ' Base class for anything that can hold cards (i.e. the deck, players, discard pile, the table etc.) Type THolder Field Card:TList = CreateList() Method GetCard:TCard( Number ) Local n=0 For Local c:TCard = EachIn Card n:+1 If n = Number Then Return c Next End Method Method PullCard:TCard() Local TempCard:TCard = Self.GetCard(1) Self.Card.Remove( TempCard) Return TempCard End Method Method PutCard:TCard( inCard:TCard ) Self.Card.AddLast( inCard ) End Method End Type ' Base class for the deck of cards. Type TDeck Extends THolder ' Creates a deck of cards. ' From:Int=2 -> The card to start building the deck from. Used to create decks without the lowest cards. Function Create:TDeck( From:Int=2 ) Local Deck:TDeck = New TDeck For Local Suit:String = EachIn Suits For Local n=From To 14 Deck.Card.AddLast(TCard.Create(Suit,n)) Next Next Return Deck End Function End Type ' Base class for hand of cards Type THand Extends THolder Function Create:THand( Number:Int, inDeck:TDeck ) Local TempHand:THand = New THand For Local n=1 To 5 TempHand.PutCard(inDeck.PullCard()) Next Return TempHand End Function End Type ' Base class for each playing card. Type TCard Field Suit:String ' clubs, diamonds, hearts, spades Field Value:Int ' 2..14 ( 11=jack, 12=queen, 13=king, 14=ace) Method GetSuit:String() Return Self.Suit End Method Method GetValue:Int() Return Self.Value End Method Function Create:TCard( inSuit:String, inValue ) Local Card:TCard = New TCard Card.Suit = inSuit Card.Value = inValue Return Card End Function End Type Local myDeck:TDeck = TDeck.Create() Print myDeck.GetCard(1).GetSuit() Print myDeck.GetCard(1).GetValue() Local myHand:THand = THand.Create( 5, myDeck ) Print myHand.GetCard(1).GetSuit() Print myHand.GetCard(1).GetValue()
p.s. LarsG: De kommentarene dine hjalp ogsaa, selv om de ikke var paa Engelsk. :-)