Advertisement
Guest User

Untitled

a guest
Jun 7th, 2014
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Genie 1.92 KB | None | 0 0
  1. [indent=4]
  2. uses
  3.     GLib
  4.     Gee
  5.  
  6. enum Suit
  7.     Club
  8.     Diamond
  9.     Heart
  10.     Spade
  11.  
  12. class Card : Object
  13.     prop suit : Suit
  14.     prop value : int
  15.    
  16.     def static mkmap() : dict of int,string
  17.         var map = new dict of int,string
  18.         map[11] = "J"
  19.         map[12] = "Q"
  20.         map[13] = "K"
  21.         map[1] = "A"
  22.         return map
  23.  
  24.     _map: static dict of int,string = mkmap()
  25.  
  26.     def static mksuitmap() : dict of Suit,string
  27.         var map = new dict of Suit,string
  28.         map[Suit.Club] = "C"
  29.         map[Suit.Diamond] = "D"
  30.         map[Suit.Heart] = "H"
  31.         map[Suit.Spade] = "S"
  32.         return map
  33.  
  34.     _mapsuit: static dict of Suit,string = mksuitmap()
  35.  
  36.     SUITS : static array of Suit = { Suit.Club, Suit.Diamond, Suit.Heart, Suit.Spade }
  37.  
  38.     construct (v : int, s : Suit)
  39.         self.suit = s
  40.         self.value = v
  41.  
  42.     def short_name(): string
  43.         v : string
  44.         if value > 1 and value < 11
  45.             v = value.to_string()
  46.         else
  47.             v = _map[value]
  48.  
  49.         return v + " " + _mapsuit[suit]
  50.  
  51. class Deck : Object
  52.     prop packs : int
  53.     prop cards : list of Card
  54.  
  55.     construct (number_of_packs: int)
  56.         packs = number_of_packs
  57.         cards = new list of Card
  58.         for var c = 1 to packs
  59.             for var suit = 0 to 4
  60.                 for var i = 1 to 13
  61.                     cards.add(new Card(i,(Suit)suit))
  62.                     print "%d", cards.size
  63.  
  64.     def deal(num : int) : Gee.List of Card
  65.         print "cards size: %d", cards.size
  66.         var nc = cards.slice(0, num-1) #core dump here!!
  67.     print "nc size: %d", nc.size
  68.         for var i = 0 to (num-1)
  69.             cards.remove_at(i)
  70.  
  71.         return nc
  72.  
  73. init
  74.     var deck = new Deck(1)
  75.     var card = deck.deal(1)[0]
  76.     print card.short_name()
  77.     //suits : array of int = { Suit.Club, Suit.Diamond, Suit.Heart, Suit.Spade }
  78.     //print "%d", suits.length
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement