-
Notifications
You must be signed in to change notification settings - Fork 1
/
deck.rb
47 lines (41 loc) · 1.1 KB
/
deck.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require './card'
class Deck
#Initialize the deck with all possible combinations.
def initialize
#Initialize empty deck.
@deck = []
#Describing cards possible value
@colors = ["red", "green", "purple"]
@numbers = ["one", "two", "three"]
@shapes = ["squiggle", "diamond", "oval"]
@shadings = ["solid", "striped", "open"]
#Each attribute combination is looped through to generate a new card instance.
@colors.each do |color|
@numbers.each do |number|
@shapes.each do |shape|
@shadings.each do |shading|
@deck << Card.new(color, number, shape, shading)
end
end
end
end
end
#Returns the size of the deck.
def size
@deck.length
end
#Random shuffle.
def shuffle
@deck.shuffle!
end
#Dealing cards.
def deal
@deck.pop
end
#Checking if the deck is empty.
def empty?
@deck.empty?
end
end
# Path: deck.rb
# Compare this snippet from card.rb: