Sha256: 81dfd225690803f1e69b18197c2f03c4e8c8ffb991c9d9edd8d26172ca7d90a2

Contents?: true

Size: 734 Bytes

Versions: 2

Compression:

Stored size: 734 Bytes

Contents

require 'twenty_one/card'
require 'twenty_one/face_card'
require 'twenty_one/ace_card'

module TwentyOne
	class Deck
		@@DECK_LENGTH = 52
		attr_reader :cards

		def initialize
			@cards = [] 

			@cards.concat generate_suit(:clubs)
			@cards.concat generate_suit(:diamonds)
			@cards.concat generate_suit(:hearts)
			@cards.concat generate_suit(:spades)
		end

		def shuffle
			@cards.shuffle!	
		end

		def draw
			@cards.shift	
		end
		
		private

		def generate_suit(suit)
			set = []

			set.push AceCard.new(suit)

			for i  in 2..@@DECK_LENGTH / 4 - 3 
				set.push Card.new suit, i	
			end

			set.push FaceCard.new suit, :jack
			set.push FaceCard.new suit, :queen
			set.push FaceCard.new suit, :king

			set
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twenty_one-0.1.1 lib/twenty_one/deck.rb
twenty_one-0.1.0 lib/twenty_one/deck.rb