Class: Game

Inherits:
Object
  • Object
show all
Defined in:
lib/deck/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hands = 3, cards = 3) ⇒ Game

Returns a new instance of Game.



9
10
11
12
13
14
15
16
# File 'lib/deck/game.rb', line 9

def initialize(hands = 3, cards = 3)
  @deck = Deck.new
  @number_of_hands = hands
  @number_of_cards = cards
  1..@number_of_hands.to_i do |n|
    @hands << Hand.new
  end
end

Instance Attribute Details

#deckObject (readonly)

Returns the value of attribute deck.



6
7
8
# File 'lib/deck/game.rb', line 6

def deck
  @deck
end

#handsObject (readonly)

Returns the value of attribute hands.



6
7
8
# File 'lib/deck/game.rb', line 6

def hands
  @hands
end

#number_of_cardsObject (readonly)

Returns the value of attribute number_of_cards.



6
7
8
# File 'lib/deck/game.rb', line 6

def number_of_cards
  @number_of_cards
end

#number_of_handsObject (readonly)

Returns the value of attribute number_of_hands.



6
7
8
# File 'lib/deck/game.rb', line 6

def number_of_hands
  @number_of_hands
end

Instance Method Details

#deal(shuffle = true) ⇒ Object Also known as: deal!



22
23
24
25
26
27
28
29
# File 'lib/deck/game.rb', line 22

def deal(shuffle = true)
  deck.shuffle! if shuffle
  1..@hands.size do |n|
    1..@number_of_cards.to_i do |m|
      @hands[m] << deck.draw
    end  
  end  
end

#inspectObject



18
19
20
# File 'lib/deck/game.rb', line 18

def inspect
  "#{to_s} with #{@number_of_hands} hands each with #{@number_of_cards} cards"
end