deck 1.0.6 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/deck/game.rb +8 -8
- data/lib/deck/hand.rb +1 -1
- data/lib/deck/version.rb +1 -1
- data/test/game_test.rb +9 -2
- metadata +1 -1
data/lib/deck/game.rb
CHANGED
@@ -6,11 +6,12 @@ class Game
|
|
6
6
|
attr_reader :deck, :hands, :number_of_hands, :number_of_cards
|
7
7
|
|
8
8
|
|
9
|
-
def initialize(
|
9
|
+
def initialize(p_hands = 3, p_cards = 3)
|
10
10
|
@deck = Deck.new
|
11
|
-
@number_of_hands =
|
12
|
-
@number_of_cards =
|
13
|
-
|
11
|
+
@number_of_hands = p_hands
|
12
|
+
@number_of_cards = p_cards
|
13
|
+
@hands = []
|
14
|
+
@number_of_hands.to_i.times do
|
14
15
|
@hands << Hand.new
|
15
16
|
end
|
16
17
|
end
|
@@ -21,12 +22,11 @@ class Game
|
|
21
22
|
|
22
23
|
def deal(shuffle = true)
|
23
24
|
deck.shuffle! if shuffle
|
24
|
-
1
|
25
|
-
|
26
|
-
|
25
|
+
(1..hands.size).each do |n|
|
26
|
+
number_of_cards.times do
|
27
|
+
hands[n-1] << deck.draw
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
|
-
alias :deal! :deal
|
32
32
|
end
|
data/lib/deck/hand.rb
CHANGED
data/lib/deck/version.rb
CHANGED
data/test/game_test.rb
CHANGED
@@ -7,15 +7,22 @@ class GameTest < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
|
10
|
-
def
|
10
|
+
def test_deals_ok
|
11
11
|
game = Game.new(10,5)
|
12
|
+
game.deal
|
12
13
|
assert_equal 10, game.hands.size
|
13
14
|
|
14
15
|
(1..10).each do |n|
|
15
|
-
assert_equal 5, game.hands[n].size
|
16
|
+
assert_equal 5, game.hands[n-1].size
|
16
17
|
end
|
17
18
|
|
18
19
|
assert_equal 2, game.deck.size
|
19
20
|
end
|
20
21
|
|
22
|
+
def test_default_deal_works
|
23
|
+
game = Game.new
|
24
|
+
game.deal
|
25
|
+
assert_instance_of Game, game
|
26
|
+
end
|
27
|
+
|
21
28
|
end
|