card_play_21 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +29 -29
- data/lib/card.rb +21 -0
- data/lib/card_play_21/version.rb +1 -1
- data/lib/card_value.rb +65 -0
- data/lib/computer_player.rb +13 -0
- data/lib/dack.rb +42 -0
- data/lib/empty_class.rb +4 -0
- data/lib/game.rb +27 -0
- data/lib/player.rb +26 -0
- data/lib/suit.rb +33 -0
- data/spec/card_play_21_spec.rb +9 -0
- data/spec/card_spec.rb +9 -0
- data/spec/dack_spec.rb +10 -0
- data/spec/game_spec.rb +34 -0
- data/spec/spec_helper.rb +11 -0
- metadata +21 -3
data/README.md
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
# CardPlay21
|
|
2
|
-
|
|
3
|
-
TODO: Write a gem description
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Add this line to your application's Gemfile:
|
|
8
|
-
|
|
9
|
-
gem 'card_play_21'
|
|
10
|
-
|
|
11
|
-
And then execute:
|
|
12
|
-
|
|
13
|
-
$ bundle
|
|
14
|
-
|
|
15
|
-
Or install it yourself as:
|
|
16
|
-
|
|
17
|
-
$ gem install card_play_21
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
TODO: Write usage instructions here
|
|
22
|
-
|
|
23
|
-
## Contributing
|
|
24
|
-
|
|
25
|
-
1. Fork it
|
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
|
29
|
-
5. Create new Pull Request
|
|
1
|
+
# CardPlay21
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'card_play_21'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install card_play_21
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
TODO: Write usage instructions here
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
1. Fork it
|
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
29
|
+
5. Create new Pull Request
|
data/lib/card.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "card_play_21/version"
|
|
2
|
+
|
|
3
|
+
class Card
|
|
4
|
+
attr_reader :value, :suit
|
|
5
|
+
|
|
6
|
+
def initialize value, suit
|
|
7
|
+
raise ArgumentError.new 'wrong arguments for card. please, check it' unless inputs_right?(value, suit)
|
|
8
|
+
@value = value
|
|
9
|
+
@suit = suit
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def to_s
|
|
13
|
+
@value.to_s + @suit.to_s
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def inputs_right? value, suit
|
|
19
|
+
value.kind_of?(CardValue) && suit.kind_of?(Suit)
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/card_play_21/version.rb
CHANGED
data/lib/card_value.rb
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require "card_play_21/version"
|
|
2
|
+
|
|
3
|
+
class CardValue
|
|
4
|
+
attr_reader :value
|
|
5
|
+
|
|
6
|
+
def initialize value
|
|
7
|
+
@value = value
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.two
|
|
11
|
+
CardValue.new 2
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.three
|
|
15
|
+
CardValue.new 3
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.four
|
|
19
|
+
CardValue.new 4
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.five
|
|
23
|
+
CardValue.new 5
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.six
|
|
27
|
+
CardValue.new 6
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.seven
|
|
31
|
+
CardValue.new 7
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.eight
|
|
35
|
+
CardValue.new 8
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.nine
|
|
39
|
+
CardValue.new 9
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.ten
|
|
43
|
+
CardValue.new 10
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.j
|
|
47
|
+
CardValue.new 'j'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.q
|
|
51
|
+
CardValue.new 'q'
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.k
|
|
55
|
+
CardValue.new 'k'
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.a
|
|
59
|
+
CardValue.new 'a'
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def to_s
|
|
63
|
+
@value.to_s.upcase
|
|
64
|
+
end
|
|
65
|
+
end
|
data/lib/dack.rb
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require "card_play_21/version"
|
|
2
|
+
|
|
3
|
+
class Dack
|
|
4
|
+
attr_reader :cards
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@cards = Array.new
|
|
8
|
+
# ������� ����� ��� ������ ����� � ��� ������� ��������. �������� � @cards
|
|
9
|
+
Suit.methods.each do |suit_method_name|
|
|
10
|
+
if not(contains_standart_method?(suit_method_name))
|
|
11
|
+
CardValue.methods.each do |card_value_method_name|
|
|
12
|
+
if !contains_standart_method? card_value_method_name
|
|
13
|
+
card = Card.new(CardValue.send(card_value_method_name.to_s), Suit.send(suit_method_name.to_s))
|
|
14
|
+
@cards << card
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
mix_cards
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def next_card
|
|
23
|
+
@cards.pop
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def empty?
|
|
27
|
+
@cards.empty?
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def contains_standart_method? method_name
|
|
33
|
+
EmptyClass.methods.include? method_name
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def mix_cards
|
|
40
|
+
# TODO mix cards randomly
|
|
41
|
+
end
|
|
42
|
+
end
|
data/lib/empty_class.rb
ADDED
data/lib/game.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require "card_play_21/version"
|
|
2
|
+
|
|
3
|
+
class Game
|
|
4
|
+
attr_reader :players, :dack, :turn
|
|
5
|
+
|
|
6
|
+
def initialize players, dack = Dack.new, turn = 0
|
|
7
|
+
@players = players
|
|
8
|
+
raise ArgumentError.new 'dack can not be empty' if dack == nil || dack.empty?
|
|
9
|
+
@dack = dack
|
|
10
|
+
@turn = turn
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def add_player player
|
|
14
|
+
@players << player
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def next_card
|
|
18
|
+
player = @players[@turn]
|
|
19
|
+
if player.one_more_card?
|
|
20
|
+
card = @players[@turn].one_more_card
|
|
21
|
+
@turn = (@turn + 1) % @players.length if card != nil
|
|
22
|
+
card
|
|
23
|
+
else
|
|
24
|
+
nil
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/player.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require "card_play_21/version"
|
|
2
|
+
|
|
3
|
+
class Player
|
|
4
|
+
attr_reader :name, :dack, :cards, :points
|
|
5
|
+
|
|
6
|
+
def initialize name, dack, cards = [], score = 0
|
|
7
|
+
@name = name
|
|
8
|
+
@dack = dack
|
|
9
|
+
@cards = cards
|
|
10
|
+
@score = score
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def to_s
|
|
14
|
+
@name
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def one_more_card
|
|
18
|
+
@cards << @dack.next_card
|
|
19
|
+
@cards.last
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def one_more_card?
|
|
23
|
+
# TODO ask about if player wants one more card
|
|
24
|
+
true
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/suit.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require "card_play_21/version"
|
|
2
|
+
|
|
3
|
+
class Suit
|
|
4
|
+
attr_reader :suit, :short_suit
|
|
5
|
+
|
|
6
|
+
def self.spade # ����
|
|
7
|
+
Suit.new 'spade', 'S'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.heart # �����
|
|
11
|
+
Suit.new 'heart', 'H'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.rect # �����
|
|
15
|
+
Suit.new 'rect', 'R'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.cross # ������
|
|
19
|
+
Suit.new 'cross', 'C'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def to_s
|
|
23
|
+
@short_suit
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def initialize suit, short_suit
|
|
30
|
+
@suit = suit
|
|
31
|
+
@short_suit = short_suit
|
|
32
|
+
end
|
|
33
|
+
end
|
data/spec/card_spec.rb
ADDED
data/spec/dack_spec.rb
ADDED
data/spec/game_spec.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Game do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@dack = Dack.new
|
|
6
|
+
first_player = Player.new 'Nick', @dack
|
|
7
|
+
second_player = ComputerPlayer.new @dack
|
|
8
|
+
@players = [first_player, second_player]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
context "initialize" do
|
|
12
|
+
it "should return new game with valid arguments" do
|
|
13
|
+
game = Game.new(@players, @dack)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should raise an error with an empty dack" do
|
|
17
|
+
while (@dack.next_card != nil) ; end
|
|
18
|
+
expect {Game.new(@players, @dack)}.to raise_error (ArgumentError)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "next card" do
|
|
23
|
+
it "should be given next player" do
|
|
24
|
+
game = Game.new(@players, @dack)
|
|
25
|
+
card = game.next_card
|
|
26
|
+
# puts 'card = ' + card.to_s
|
|
27
|
+
# puts 'turn = ' + game.turn.to_s
|
|
28
|
+
expect @players[game.turn-1].cards.last == card
|
|
29
|
+
card = game.next_card
|
|
30
|
+
# puts 'card = ' + card.to_s
|
|
31
|
+
expect @players[game.turn-1].cards.last == card
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: card_play_21
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-08-
|
|
12
|
+
date: 2012-08-20 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rspec
|
|
@@ -40,8 +40,21 @@ files:
|
|
|
40
40
|
- README.md
|
|
41
41
|
- Rakefile
|
|
42
42
|
- card_play_21.gemspec
|
|
43
|
+
- lib/card.rb
|
|
43
44
|
- lib/card_play_21.rb
|
|
44
45
|
- lib/card_play_21/version.rb
|
|
46
|
+
- lib/card_value.rb
|
|
47
|
+
- lib/computer_player.rb
|
|
48
|
+
- lib/dack.rb
|
|
49
|
+
- lib/empty_class.rb
|
|
50
|
+
- lib/game.rb
|
|
51
|
+
- lib/player.rb
|
|
52
|
+
- lib/suit.rb
|
|
53
|
+
- spec/card_play_21_spec.rb
|
|
54
|
+
- spec/card_spec.rb
|
|
55
|
+
- spec/dack_spec.rb
|
|
56
|
+
- spec/game_spec.rb
|
|
57
|
+
- spec/spec_helper.rb
|
|
45
58
|
homepage: ''
|
|
46
59
|
licenses: []
|
|
47
60
|
post_install_message:
|
|
@@ -66,5 +79,10 @@ rubygems_version: 1.8.24
|
|
|
66
79
|
signing_key:
|
|
67
80
|
specification_version: 3
|
|
68
81
|
summary: Write a gem summary
|
|
69
|
-
test_files:
|
|
82
|
+
test_files:
|
|
83
|
+
- spec/card_play_21_spec.rb
|
|
84
|
+
- spec/card_spec.rb
|
|
85
|
+
- spec/dack_spec.rb
|
|
86
|
+
- spec/game_spec.rb
|
|
87
|
+
- spec/spec_helper.rb
|
|
70
88
|
has_rdoc:
|