Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [indent=4]
- uses
- GLib
- Gee
- enum Suit
- Club
- Diamond
- Heart
- Spade
- class Card : Object
- prop suit : Suit
- prop value : int
- def static mkmap() : dict of int,string
- var map = new dict of int,string
- map[11] = "J"
- map[12] = "Q"
- map[13] = "K"
- map[1] = "A"
- return map
- _map: static dict of int,string = mkmap()
- def static mksuitmap() : dict of Suit,string
- var map = new dict of Suit,string
- map[Suit.Club] = "C"
- map[Suit.Diamond] = "D"
- map[Suit.Heart] = "H"
- map[Suit.Spade] = "S"
- return map
- _mapsuit: static dict of Suit,string = mksuitmap()
- SUITS : static array of Suit = { Suit.Club, Suit.Diamond, Suit.Heart, Suit.Spade }
- construct (v : int, s : Suit)
- self.suit = s
- self.value = v
- def short_name(): string
- v : string
- if value > 1 and value < 11
- v = value.to_string()
- else
- v = _map[value]
- return v + " " + _mapsuit[suit]
- class Deck : Object
- prop packs : int
- prop cards : list of Card
- construct (number_of_packs: int)
- packs = number_of_packs
- cards = new list of Card
- for var c = 1 to packs
- for var suit = 0 to 4
- for var i = 1 to 13
- cards.add(new Card(i,(Suit)suit))
- print "%d", cards.size
- def deal(num : int) : Gee.List of Card
- print "cards size: %d", cards.size
- var nc = cards.slice(0, num-1) #core dump here!!
- print "nc size: %d", nc.size
- for var i = 0 to (num-1)
- cards.remove_at(i)
- return nc
- init
- var deck = new Deck(1)
- var card = deck.deal(1)[0]
- print card.short_name()
- //suits : array of int = { Suit.Club, Suit.Diamond, Suit.Heart, Suit.Spade }
- //print "%d", suits.length
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement