-
Notifications
You must be signed in to change notification settings - Fork 0
/
card.rb
52 lines (37 loc) · 855 Bytes
/
card.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
48
49
50
51
class Card
COLORS = [ :red, :green, :blue, :yellow ]
ACTIONS = [ :skip, :reverse, :plus2 ]
attr_reader :color, :value
attr_writer :color
def initialize color, value=nil, wild=false
@color, @value, @wild = color, value, wild
end
def to_s
if @value
"#{@color.to_s[0..0]}/#{@value}"
else
@color.to_s[0..0]
end
end
def wild?
@wild
end
def Card.deck
deck = []
# 4 of each wild type
4.times {
deck << Card.new(nil, nil, true)
deck << Card.new(nil, :plus4, true)
}
# one 0 for each color
COLORS.each { |c| deck << Card.new(c, 0) }
# two of each action and number per color
2.times do
COLORS.each do |c|
ACTIONS.each { |a| deck << Card.new(c, a) }
(1..9).each { |n| deck << Card.new(c, n) }
end
end
deck
end
end