Class: GlimmerKlondikeSolitaire::Model::DealingPile

Inherits:
Object
  • Object
show all
Defined in:
app/glimmer_klondike_solitaire/model/dealing_pile.rb

Constant Summary collapse

DEALING_INITIAL_COUNT =
24

Instance Method Summary collapse

Constructor Details

#initialize(game) ⇒ DealingPile

Returns a new instance of DealingPile.



6
7
8
9
# File 'app/glimmer_klondike_solitaire/model/dealing_pile.rb', line 6

def initialize(game)
  @game = game
  reset!
end

Instance Method Details

#deal!Object



16
17
18
19
20
21
22
23
24
25
26
# File 'app/glimmer_klondike_solitaire/model/dealing_pile.rb', line 16

def deal!
    playing_card = playing_cards.shift
    if playing_card.nil?
      @game.dealt_pile.playing_cards.each do |a_playing_card|
        playing_cards << a_playing_card
      end
      @game.dealt_pile.playing_cards.clear
    else
      @game.dealt_pile.push!(playing_card)
    end
end

#playing_cardsObject



28
29
30
# File 'app/glimmer_klondike_solitaire/model/dealing_pile.rb', line 28

def playing_cards
  @playing_cards ||= []
end

#reset!Object



11
12
13
14
# File 'app/glimmer_klondike_solitaire/model/dealing_pile.rb', line 11

def reset!
  playing_cards.clear
  DEALING_INITIAL_COUNT.times { playing_cards << @game.deck.pop }
end