Class: Deck
- Inherits:
-
Object
show all
- Defined in:
- lib/deckcrystel.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Deck
Returns a new instance of Deck.
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/deckcrystel.rb', line 16
def initialize
@position = []
@groups = []
["c", "h", "s", "d"].each do |suit|
for card in 2..10
@position.push("#{card}#{suit}")
end
["a", "j", "q", "k"].each do |card|
@position.push("#{card}#{suit}")
end
end
shuffle
end
|
Instance Attribute Details
#groups ⇒ Object
Returns the value of attribute groups.
3
4
5
|
# File 'lib/deckcrystel.rb', line 3
def groups
@groups
end
|
#position ⇒ Object
Returns the value of attribute position.
2
3
4
|
# File 'lib/deckcrystel.rb', line 2
def position
@position
end
|
Instance Method Details
#card_at(card) ⇒ Object
29
30
31
|
# File 'lib/deckcrystel.rb', line 29
def card_at(card)
@position[card]
end
|
#combine ⇒ Object
51
52
53
54
55
|
# File 'lib/deckcrystel.rb', line 51
def combine
@position.push(@groups.flatten).flatten!
@groups = []
self
end
|
#deal(num_cards, num_hands) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/deckcrystel.rb', line 42
def deal(num_cards, num_hands)
for i in 0...num_hands
@groups.push(top(num_cards))
for x in 0...num_cards
@position.shift
end
end
self
end
|
#deal_in ⇒ Object
56
57
58
|
# File 'lib/deckcrystel.rb', line 56
def deal_in
combine
end
|
#group_no(group, top_no, place, placein = 1) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/deckcrystel.rb', line 59
def group_no(group, top_no, place, placein=1)
if (1..@groups.length).include?(place)
@groups[place-1].insert(placein-1, @groups[group-1][0...top_no]).flatten!
@groups[group-1][0...top_no].each do |card|
@groups[group-1].delete(card)
end
else
@position.insert(placein-1, @groups[group-1][0...top_no]).flatten!
@groups[group-1][0...top_no].each do |card|
@groups[group-1].delete(card)
end
end
end
|
#index_of(card) ⇒ Object
32
33
34
|
# File 'lib/deckcrystel.rb', line 32
def index_of(card)
@position.index(card)
end
|
#shuffle ⇒ Object
10
11
12
13
14
15
|
# File 'lib/deckcrystel.rb', line 10
def shuffle
for x in 0..200
swap
end
self
end
|
#swap(one = rand(@position.size), two = rand(@position.size)) ⇒ Object
4
5
6
7
8
9
|
# File 'lib/deckcrystel.rb', line 4
def swap(one=rand(@position.size), two=rand(@position.size))
swap = @position[one]
@position[one] = @position[two]
@position[two] = swap
self
end
|
#top(number) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/deckcrystel.rb', line 35
def top(number)
if number > @position.length + 1
@position
else
@position[0...number]
end
end
|