Sha256: 6ef76e415a6b54975ec5bf4b6859d296c04df2474f44bae9f9128968e4bf9d70
Contents?: true
Size: 891 Bytes
Versions: 4
Compression:
Stored size: 891 Bytes
Contents
module HDeck # Provides a Harrow deck for a Card Caster to interact with class Deck include Enumerable def initialize card_data = JSON.parse(File.read('cards.json')) @cards = get_cards(card_data) end def length @cards.length end def each(&block) @cards.each(&block) end def draw(replace: true) replace ? @cards.last : @cards.pop end def shuffle counter = @cards.length - 1 while counter > 0 ri = rand(counter) @cards[counter], @cards[ri] = @cards[ri], @cards[counter] counter -= 1 end @cards end private def get_cards(card_data) card_data.map do |data| Card.new( name: data['name'], desc: data['desc'], morality: data['morality'], ability: data['ability'] ) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
hdeck-0.1.3 | lib/hdeck/deck.rb |
hdeck-0.1.2 | lib/hdeck/deck.rb |
hdeck-0.1.1 | lib/hdeck/deck.rb |
hdeck-0.1.0 | lib/hdeck/deck.rb |