Sha256: e40660cee0a3934531c5a78d7e50264022319ee75315e797ee60d47b236f11ce
Contents?: true
Size: 954 Bytes
Versions: 2
Compression:
Stored size: 954 Bytes
Contents
class GlimmerKlondikeSolitaire module Model class FoundationPile attr_reader :suit def initialize(game, suit) @game = game @suit = suit reset! end def reset! playing_cards.clear end # adds a card # validates if it is a card that belongs to the suit def add!(playing_card) if playing_card.suit == suit && ( (playing_cards.empty? && playing_card.rank == 1) || playing_card.rank == (playing_cards.last.rank + 1) ) playing_cards.push(playing_card) else raise "Cannot add #{playing_card} to #{self}" end end def playing_cards @playing_cards ||= [] end def to_s "Foundation Pile #{suit} (#{playing_cards.map {|card| "#{card.rank}#{card.suit.to_s[0].upcase}"}.join(" | ")})" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
glimmer_klondike_solitaire-1.1.0 | app/glimmer_klondike_solitaire/model/foundation_pile.rb |
glimmer_klondike_solitaire-1.0.1 | app/glimmer_klondike_solitaire/model/foundation_pile.rb |