Class: BoxOfCards
- Defined in:
- tomes/components/deck_builder/box_of_cards.rb
Overview
A Hand with the ability to generate a base set of Cards. Games should only use one box of cards.
Instance Attribute Summary
Attributes inherited from Hand
Instance Method Summary collapse
-
#assign_card_string(procedure) ⇒ Void
Assigns a #to_s value for each Card in #cards.
-
#copy(dup_cards = self.cards, number_of_times = 1) ⇒ Array<Cards>
Returns a number of copies for the provided Card or Array of Cards.
-
#copy_and_add(dup_cards = self.cards, number_of_times = 1) ⇒ Void
(also: #duplicate)
Copies the provided Card or Array of Cards a number of times then adds it to #cards.
-
#generate_deck ⇒ Deck
Generates a Deck instance using #cards.
-
#make_cards(quantity = 1) ⇒ Void
Creates the given number of default Cards and adds them to the list.
Methods inherited from Hand
#[], #all_types, #all_values, #discard, #discard_index, #move, #pop, #receive, #shuffle!, #sort!
Methods included from HandInformation
#empty?, #full?, #include?, #length
Methods included from HandIteration
Instance Method Details
#assign_card_string(procedure) ⇒ Void
Assigns a #to_s value for each Card in #cards.
69 70 71 |
# File 'tomes/components/deck_builder/box_of_cards.rb', line 69 def assign_card_string(procedure) each { |card| card.to_s = procedure.call(card) } end |
#copy(dup_cards = self.cards, number_of_times = 1) ⇒ Array<Cards>
Returns a number of copies for the provided Card or Array of Cards.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'tomes/components/deck_builder/box_of_cards.rb', line 46 def copy(dup_cards = self.cards, number_of_times = 1) dup_cards = [dup_cards] unless dup_cards.is_a? Array copies = [] number_of_times.times do dup_cards.each do |original_card| copies << Card.new(original_card.types, original_card.values) end end copies end |
#copy_and_add(dup_cards = self.cards, number_of_times = 1) ⇒ Void Also known as: duplicate
Copies the provided Card or Array of Cards a number of times then adds it to #cards.
38 39 40 |
# File 'tomes/components/deck_builder/box_of_cards.rb', line 38 def copy_and_add(dup_cards = self.cards, number_of_times = 1) self.cards += copy(dup_cards, number_of_times) end |
#generate_deck ⇒ Deck
Generates a Deck instance using #cards.
62 63 64 |
# File 'tomes/components/deck_builder/box_of_cards.rb', line 62 def generate_deck Deck.new(cards) end |
#make_cards(quantity = 1) ⇒ Void
24 25 26 27 28 29 30 31 32 33 |
# File 'tomes/components/deck_builder/box_of_cards.rb', line 24 def make_cards(quantity = 1) new_cards = Array.new(quantity) { Card.new } new_cards.each_with_index do |card, index| yield(card, index) if block_given? end self.cards += new_cards new_cards end |