99_game 2.0.2 → 2.0.3.pre.68
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.rspec +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +14 -14
- data/bin/99_game +93 -94
- data/lib/99_game.rb +137 -136
- data/spec/lib/{99_game.rb → 99_game_spec.rb} +48 -48
- data/spec/spec_helper.rb +76 -77
- metadata +15 -13
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MWIwMTQzYmNiMjYwMzc2OTFmYWNiYzI4NzgzMmQ1ZTBmYTY1ODMxNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
N2E0NGE1Zjk0ZWVmNTlmYTUyODE3OTc1YWU1MGRjNDg5YjM1ZWFjMw==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDI1N2EyM2UxMzQ5MTk0N2IyOWI1NmE1ZjVjOGE2YmFhNzQ4MzFlYWUxMzE3
|
10
|
+
MWFhMzQ2YzRjMWE4M2M3MDU2Zjc3M2ZmNGU4NTk3MWVmN2I1Mzc3Zjc4NGI2
|
11
|
+
OGIxNDQ2Mzk0NDg4NWIyNGI0MjQzNjU2MmQxN2RkYjE3YTBjZjk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjZlZDQzMjYxMjcxZWNlMDQwYmJlZmFiZjk1Mjg3YWFmYjY2NzhjZDBmMzVm
|
14
|
+
NWJmZWU4ZWQ3MWFiOTcyZmE5MGQ3OWJhOGVmMDI3NjM2NzNjYzIxZTk4YTZj
|
15
|
+
ODhhNWNhOTdkZGZmYTU4NDZkZjNmM2Y4ZDJkOTgyNWRjNDM4Mjc=
|
data/.rspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
--color
|
2
|
-
--require spec_helper.rb
|
3
|
-
--warnings
|
4
|
-
--format doc
|
1
|
+
--color
|
2
|
+
--require spec_helper.rb
|
3
|
+
--warnings
|
4
|
+
--format doc
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) {{{2014}}} {{{Zachary Roth Perlmutter}}}
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) {{{2014}}} {{{Zachary Roth Perlmutter}}}
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
|
2
|
-
# 99_game
|
3
|
-
|
4
|
-
To install: `gem install 99_game`
|
5
|
-
|
6
|
-
For the rules and arguments: `99_game -h`
|
7
|
-
|
8
|
-
## Badges
|
9
|
-
[![Gem Version](https://badge.fury.io/rb/99_game.png)](http://badge.fury.io/rb/99_game)
|
10
|
-
[![Build Status](https://travis-ci.org/Zrp200/99_game.svg?branch=master)](https://travis-ci.org/Zrp200/99_game)
|
11
|
-
[![Code Climate](https://codeclimate.com/github/Zrp200/99_game.png)](https://codeclimate.com/github/Zrp200/99_game)
|
12
|
-
[![Dependency Status](https://gemnasium.com/Zrp200/99_game.svg)](https://gemnasium.com/Zrp200/99_game)
|
13
|
-
[![Inline docs](http://inch-ci.org/github/Zrp200/99_game.png?branch=master)](http://inch-ci.org/github/Zrp200/99_game)
|
14
|
-
[![Test Coverage](https://codeclimate.com/github/Zrp200/99_game/coverage.png)](https://codeclimate.com/github/Zrp200/99_game)
|
1
|
+
|
2
|
+
# 99_game
|
3
|
+
|
4
|
+
To install: `gem install 99_game`
|
5
|
+
|
6
|
+
For the rules and arguments: `99_game -h`
|
7
|
+
|
8
|
+
## Badges
|
9
|
+
[![Gem Version](https://badge.fury.io/rb/99_game.png)](http://badge.fury.io/rb/99_game)
|
10
|
+
[![Build Status](https://travis-ci.org/Zrp200/99_game.svg?branch=master)](https://travis-ci.org/Zrp200/99_game)
|
11
|
+
[![Code Climate](https://codeclimate.com/github/Zrp200/99_game.png)](https://codeclimate.com/github/Zrp200/99_game)
|
12
|
+
[![Dependency Status](https://gemnasium.com/Zrp200/99_game.svg)](https://gemnasium.com/Zrp200/99_game)
|
13
|
+
[![Inline docs](http://inch-ci.org/github/Zrp200/99_game.png?branch=master)](http://inch-ci.org/github/Zrp200/99_game)
|
14
|
+
[![Test Coverage](https://codeclimate.com/github/Zrp200/99_game/coverage.png)](https://codeclimate.com/github/Zrp200/99_game)
|
data/bin/99_game
CHANGED
@@ -1,94 +1,93 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require '99_game'
|
3
|
-
deck = Deck.new
|
4
|
-
BEGIN { # Looks at its arguements
|
5
|
-
ARGV[0] = "-h" if ARGV[0] == "--help"
|
6
|
-
ARGV[0] = "-v" if ARGV[0] == "--version"
|
7
|
-
case ARGV[0]
|
8
|
-
when "-v"
|
9
|
-
puts "2.0.1"
|
10
|
-
exit
|
11
|
-
when "-h"
|
12
|
-
puts "\u00B7 Commands"
|
13
|
-
puts "\t\u00b7 -v/--version - display version"
|
14
|
-
puts "\t\u00B7 -h/--help - shows this message\n"
|
15
|
-
puts "\u00B7 Abbrevations"
|
16
|
-
puts "\t\u00B7 J -> Jack"
|
17
|
-
puts "\t\u00b7 Q -> Queen"
|
18
|
-
puts "\t\u00b7 K -> King"
|
19
|
-
puts "\t\u00b7 A -> Ace"
|
20
|
-
puts "\t\u00b7 $ -> Joker"
|
21
|
-
puts "\u00B7 Gameplay"
|
22
|
-
puts "\t\u00B7 Your goal is to get your opponent to bring the value over 99 by playing 1 of your 3 cards."
|
23
|
-
puts "\t\u00B7 A card will usually increase the value by itself, but there are a few exceptions:"
|
24
|
-
puts "\t\t\u00B7 Aces are worth 1"
|
25
|
-
puts "\t\t\u00B7 1 - 10 are worth themselves, with the exception of 4 and 9"
|
26
|
-
puts "\t\t\u00B7 4, 9, and Jacks are worth 0"
|
27
|
-
puts "\t\t\u00B7 Queens decrease the value by 10"
|
28
|
-
puts "\t\t\u00B7 Kings set the value to 99"
|
29
|
-
puts "\t\t\u00B7 Jokers set the value to 0"
|
30
|
-
exit
|
31
|
-
end
|
32
|
-
}
|
33
|
-
END { # Thanks for playing
|
34
|
-
sleep(1.5)
|
35
|
-
puts "\n\tThanks for playing 99!"
|
36
|
-
sleep(2.5)
|
37
|
-
}
|
38
|
-
$value, value1, value2, value3, dealer, user = 0,0,0,0, Hand.new(deck), Hand.new(deck)
|
39
|
-
loop do
|
40
|
-
puts
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
when
|
46
|
-
when
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
puts
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
Programmed by: Zachary Perlmutter
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require '99_game'
|
3
|
+
deck = Deck.new
|
4
|
+
BEGIN { # Looks at its arguements
|
5
|
+
ARGV[0] = "-h" if ARGV[0] == "--help"
|
6
|
+
ARGV[0] = "-v" if ARGV[0] == "--version"
|
7
|
+
case ARGV[0]
|
8
|
+
when "-v"
|
9
|
+
puts "2.0.1"
|
10
|
+
exit
|
11
|
+
when "-h"
|
12
|
+
puts "\u00B7 Commands"
|
13
|
+
puts "\t\u00b7 -v/--version - display version"
|
14
|
+
puts "\t\u00B7 -h/--help - shows this message\n"
|
15
|
+
puts "\u00B7 Abbrevations"
|
16
|
+
puts "\t\u00B7 J -> Jack"
|
17
|
+
puts "\t\u00b7 Q -> Queen"
|
18
|
+
puts "\t\u00b7 K -> King"
|
19
|
+
puts "\t\u00b7 A -> Ace"
|
20
|
+
puts "\t\u00b7 $ -> Joker"
|
21
|
+
puts "\u00B7 Gameplay"
|
22
|
+
puts "\t\u00B7 Your goal is to get your opponent to bring the value over 99 by playing 1 of your 3 cards."
|
23
|
+
puts "\t\u00B7 A card will usually increase the value by itself, but there are a few exceptions:"
|
24
|
+
puts "\t\t\u00B7 Aces are worth 1"
|
25
|
+
puts "\t\t\u00B7 1 - 10 are worth themselves, with the exception of 4 and 9"
|
26
|
+
puts "\t\t\u00B7 4, 9, and Jacks are worth 0"
|
27
|
+
puts "\t\t\u00B7 Queens decrease the value by 10"
|
28
|
+
puts "\t\t\u00B7 Kings set the value to 99"
|
29
|
+
puts "\t\t\u00B7 Jokers set the value to 0"
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
}
|
33
|
+
END { # Thanks for playing
|
34
|
+
sleep(1.5)
|
35
|
+
puts "\n\tThanks for playing 99!"
|
36
|
+
sleep(2.5)
|
37
|
+
}
|
38
|
+
$value, value1, value2, value3, dealer, user = 0,0,0,0, Hand.new(deck), Hand.new(deck)
|
39
|
+
loop do
|
40
|
+
puts "\n\tIt is the dealer's turn!"
|
41
|
+
i = 1
|
42
|
+
for card in dealer.hand
|
43
|
+
case i
|
44
|
+
when 1 then test card, $value, value1
|
45
|
+
when 2 then test card, $value, value2
|
46
|
+
when 3 then test card, $value, value3
|
47
|
+
end
|
48
|
+
i += 1
|
49
|
+
end
|
50
|
+
if value1 >= value2 && value1 >= value3
|
51
|
+
$card = dealer.hand[0].num
|
52
|
+
dealer.play dealer.hand[0]
|
53
|
+
elsif value1 <= value2 && value2 >= value3
|
54
|
+
$card = dealer.hand[1].num
|
55
|
+
dealer.play dealer.hand[1]
|
56
|
+
else
|
57
|
+
$card = dealer.hand[2].num
|
58
|
+
dealer.play(dealer.hand[2])
|
59
|
+
end
|
60
|
+
pause(1.5)
|
61
|
+
puts "\tThe dealer played a(n) #{$card}"
|
62
|
+
pause(0.5)
|
63
|
+
puts "\tThe value is now #{$value}"
|
64
|
+
puts
|
65
|
+
pause(1.5)
|
66
|
+
if $value > 99 # Runs when you win and exits loop
|
67
|
+
puts "\tYou win!"
|
68
|
+
break
|
69
|
+
end
|
70
|
+
puts "\tIt's your turn!"
|
71
|
+
pause 1
|
72
|
+
user.view
|
73
|
+
pause 0.5
|
74
|
+
print "\tPick a card to play by typing in the name of the card => "
|
75
|
+
input, turn = gets.chomp, true
|
76
|
+
for card in user.hand
|
77
|
+
if card.num == converter(input) && turn
|
78
|
+
user.play(card)
|
79
|
+
turn = false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
pause 1
|
83
|
+
puts "\tYou drew a(n) #{user.hand[2].num}"
|
84
|
+
pause(0.5)
|
85
|
+
puts "\tThe value is now #{$value}"
|
86
|
+
pause(1.5)
|
87
|
+
if $value > 99 # Runs when dealer wins and exits loop
|
88
|
+
puts "\tYou lose"
|
89
|
+
break
|
90
|
+
end
|
91
|
+
end
|
92
|
+
__END__
|
93
|
+
Programmed by: Zachary Perlmutter
|
data/lib/99_game.rb
CHANGED
@@ -1,136 +1,137 @@
|
|
1
|
-
# Used by the CPU to determine which card to play. Parameter card needs to be an instance of Card.
|
2
|
-
def test(card, actual_value, test_value)
|
3
|
-
if card.num == "King"
|
4
|
-
test_value = 99
|
5
|
-
elsif card.num == "Joker"
|
6
|
-
test_value = 0
|
7
|
-
else; test_value = actual_value + card.value
|
8
|
-
end
|
9
|
-
test_value = -100 if test_value > 99
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
if input
|
24
|
-
|
25
|
-
|
26
|
-
when "
|
27
|
-
when "
|
28
|
-
when "
|
29
|
-
when "
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
class
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
when
|
47
|
-
when
|
48
|
-
when
|
49
|
-
when
|
50
|
-
when
|
51
|
-
when
|
52
|
-
when "
|
53
|
-
when "
|
54
|
-
when "
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
when
|
62
|
-
when
|
63
|
-
when
|
64
|
-
when "
|
65
|
-
when "
|
66
|
-
when
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
@hand
|
90
|
-
@hand.
|
91
|
-
@deck.
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
@cards.push Card.new("
|
116
|
-
@cards.push Card.new("
|
117
|
-
@cards.push Card.new("
|
118
|
-
@cards.push Card.new(
|
119
|
-
@cards.push Card.new(
|
120
|
-
@cards.push Card.new(
|
121
|
-
@cards.push Card.new(
|
122
|
-
@cards.push Card.new(
|
123
|
-
@cards.push Card.new(
|
124
|
-
@cards.push Card.new(
|
125
|
-
@cards.push Card.new(
|
126
|
-
@cards.push Card.new(
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
end
|
136
|
-
|
1
|
+
# Used by the CPU to determine which card to play. Parameter card needs to be an instance of Card.
|
2
|
+
def test(card, actual_value, test_value)
|
3
|
+
if card.num == "King"
|
4
|
+
test_value = 99
|
5
|
+
elsif card.num == "Joker"
|
6
|
+
test_value = 0
|
7
|
+
else; test_value = actual_value + card.value
|
8
|
+
end
|
9
|
+
test_value = -100 if test_value > 99
|
10
|
+
return test_value
|
11
|
+
end
|
12
|
+
# Tests if obj is not nil.
|
13
|
+
def not_nil?(obj)
|
14
|
+
if obj.nil?
|
15
|
+
return false
|
16
|
+
else
|
17
|
+
return true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
# Converts input to an integer if String#capitalize does something. If parameter input is an abbreviation, _input_ is converted to what it stands for. Otherwise, it simply returns a capitalized version of _input_. If _input_ is nil or an emtpy string, raises a CardError
|
21
|
+
def converter(input)
|
22
|
+
abbrev = {"$" => "Joker", "K" => "King", "J" => "Jack", "Q" => "Queen", "A" => "Ace"}
|
23
|
+
raise(CardError, "Input cannot be blank") if input == String.new
|
24
|
+
if input.to_i == 0
|
25
|
+
case input.capitalize
|
26
|
+
when "$" then "Joker"
|
27
|
+
when "K" then "King"
|
28
|
+
when "J" then "Jack"
|
29
|
+
when "Q" then "Queen"
|
30
|
+
when "A" then "Ace"
|
31
|
+
end
|
32
|
+
else
|
33
|
+
input.to_i
|
34
|
+
end
|
35
|
+
end
|
36
|
+
# Expected errors
|
37
|
+
class CardError < Exception; end
|
38
|
+
class Card # Represents a card in the deck
|
39
|
+
# Gives the number on the card
|
40
|
+
attr_reader :num
|
41
|
+
# Gives the Card's value
|
42
|
+
attr_reader :value
|
43
|
+
# Backup method for Card#value
|
44
|
+
def _value
|
45
|
+
return case @num
|
46
|
+
when "Ace" then 1
|
47
|
+
when 2..3 then @num
|
48
|
+
when 4 then 0
|
49
|
+
when 5..8 then @num
|
50
|
+
when 9 then 0
|
51
|
+
when 10 then 10
|
52
|
+
when "Jack" then 0
|
53
|
+
when "Queen" then -10
|
54
|
+
when "King" then 99
|
55
|
+
when "Joker" then 0
|
56
|
+
end
|
57
|
+
end
|
58
|
+
# Creates a new card with num as the attribute :num
|
59
|
+
def initialize(num)
|
60
|
+
@num, @value = num, case num
|
61
|
+
when "Ace" then 1
|
62
|
+
when 4 then 0
|
63
|
+
when 9 then 0
|
64
|
+
when "Jack" then 0
|
65
|
+
when "Joker" then 0
|
66
|
+
when "King" then 99
|
67
|
+
when "Queen" then -10
|
68
|
+
else
|
69
|
+
num.to_i
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
class Hand # Creates an object that holds and can play cards. Interacts with Deck objects.
|
74
|
+
# The actual hand
|
75
|
+
attr_accessor :hand
|
76
|
+
# Creates a new Hand. The deck argument tells the object which deck to use in Hand#play
|
77
|
+
def initialize(deck_in_use)
|
78
|
+
@hand, @deck = [deck_in_use.draw, deck_in_use.draw, deck_in_use.draw], deck_in_use
|
79
|
+
end
|
80
|
+
# Gameplay method. The parameter 'card' is the card being played.
|
81
|
+
def play(card)
|
82
|
+
if card.num == "King"; $value = 99
|
83
|
+
elsif card.num == "Joker"; $value = 0
|
84
|
+
else; $value += card.value
|
85
|
+
end
|
86
|
+
i, done = 0, false
|
87
|
+
for index in @hand
|
88
|
+
if index.num == card.num and not done
|
89
|
+
discard = @hand[ i ]
|
90
|
+
@hand.delete_at i
|
91
|
+
@hand.push @deck.draw
|
92
|
+
@deck.discard discard
|
93
|
+
done = true
|
94
|
+
end
|
95
|
+
i += 1
|
96
|
+
end
|
97
|
+
end
|
98
|
+
# Allows you to see your cards.
|
99
|
+
def view
|
100
|
+
print "\tThese are your cards: "
|
101
|
+
@hand.each {|card| print "\t#{card.num}"}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
# Combines sleep and a newline. 'p' is the amount of time waited.
|
105
|
+
def pause(p)
|
106
|
+
sleep p
|
107
|
+
puts
|
108
|
+
end
|
109
|
+
class Deck # Cards are stored in these objects
|
110
|
+
# The contents of the deck
|
111
|
+
attr_reader :cards
|
112
|
+
def initialize # Creates a new deck that can now be used for playing the game
|
113
|
+
@cards = Array.new
|
114
|
+
4.times do # Add the cards to the deck
|
115
|
+
@cards.push Card.new("Ace")
|
116
|
+
@cards.push Card.new("King")
|
117
|
+
@cards.push Card.new("Queen")
|
118
|
+
@cards.push Card.new("Jack")
|
119
|
+
@cards.push Card.new(10)
|
120
|
+
@cards.push Card.new(9)
|
121
|
+
@cards.push Card.new(8)
|
122
|
+
@cards.push Card.new(7)
|
123
|
+
@cards.push Card.new(6)
|
124
|
+
@cards.push Card.new(5)
|
125
|
+
@cards.push Card.new(4)
|
126
|
+
@cards.push Card.new(3)
|
127
|
+
@cards.push Card.new(2)
|
128
|
+
end
|
129
|
+
2.times {@cards.push Card.new("Joker")}
|
130
|
+
50.times {@cards.shuffle!}
|
131
|
+
end
|
132
|
+
# Draw from the deck
|
133
|
+
def draw; @cards.shift; end
|
134
|
+
# Adds 'card' to the deck. Used with Hand#play.
|
135
|
+
def discard(card); @cards.push card; end
|
136
|
+
end
|
137
|
+
|
@@ -1,48 +1,48 @@
|
|
1
|
-
deck = Deck.new
|
2
|
-
describe Deck do
|
3
|
-
subject {Deck.new}
|
4
|
-
describe "#length" do
|
5
|
-
it "should == 54" do; expect(subject.cards.length).to eq 54; end
|
6
|
-
end
|
7
|
-
end
|
8
|
-
describe Card do
|
9
|
-
cards = ["Ace", "King", "Queen", "Jack", "Joker"] + (2..10).to_a
|
10
|
-
describe "#value" do
|
11
|
-
for card in cards
|
12
|
-
describe "#{card}" do
|
13
|
-
it "should == #{Card.new(card)._value}" do;
|
14
|
-
expect(Card.new(card).value).to eq Card.new(card)._value
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
describe "converter" do
|
21
|
-
context "when a number" do
|
22
|
-
it "should return the input as a number" do
|
23
|
-
expect(converter("5")).to eq 5
|
24
|
-
end
|
25
|
-
end
|
26
|
-
context "when an abbreveation" do
|
27
|
-
it "should expand it" do
|
28
|
-
expect(converter("K")).to eq "King"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
describe Hand do
|
33
|
-
hand = Hand.new Deck.new
|
34
|
-
describe "#hand" do
|
35
|
-
describe "#length" do
|
36
|
-
subject { hand.hand.length }
|
37
|
-
it "should == 3" do; expect( subject ).to eq 3; end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
describe "#initialize" do
|
41
|
-
describe "Deck#length" do
|
42
|
-
it "should have three less cards after initialization" do
|
43
|
-
deck1, hand, deck2 = deck.cards.length, Hand.new( deck ), deck.cards.length
|
44
|
-
expect( deck1 ).to be > deck2
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
1
|
+
deck = Deck.new
|
2
|
+
describe Deck do
|
3
|
+
subject {Deck.new}
|
4
|
+
describe "#length" do
|
5
|
+
it "should == 54" do; expect(subject.cards.length).to eq 54; end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
describe Card do
|
9
|
+
cards = ["Ace", "King", "Queen", "Jack", "Joker"] + (2..10).to_a
|
10
|
+
describe "#value" do
|
11
|
+
for card in cards
|
12
|
+
describe "#{card}" do
|
13
|
+
it "should == #{Card.new(card)._value}" do;
|
14
|
+
expect(Card.new(card).value).to eq Card.new(card)._value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
describe "converter" do
|
21
|
+
context "when a number" do
|
22
|
+
it "should return the input as a number" do
|
23
|
+
expect(converter("5")).to eq 5
|
24
|
+
end
|
25
|
+
end
|
26
|
+
context "when an abbreveation" do
|
27
|
+
it "should expand it" do
|
28
|
+
expect(converter("K")).to eq "King"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
describe Hand do
|
33
|
+
hand = Hand.new Deck.new
|
34
|
+
describe "#hand" do
|
35
|
+
describe "#length" do
|
36
|
+
subject { hand.hand.length }
|
37
|
+
it "should == 3" do; expect( subject ).to eq 3; end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
describe "#initialize" do
|
41
|
+
describe "Deck#length" do
|
42
|
+
it "should have three less cards after initialization" do
|
43
|
+
deck1, hand, deck2 = deck.cards.length, Hand.new( deck ), deck.cards.length
|
44
|
+
expect( deck1 ).to be > deck2
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,77 +1,76 @@
|
|
1
|
-
require "99_game"
|
2
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
3
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
4
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
5
|
-
# file to always be loaded, without a need to explicitly require it in any files.
|
6
|
-
#
|
7
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
-
# individual file that may not need all of that loaded. Instead, make a
|
11
|
-
# separate helper file that requires this one and then use it only in the specs
|
12
|
-
# that actually need it.
|
13
|
-
#
|
14
|
-
# The `.rspec` file also contains a few flags that are not defaults but that
|
15
|
-
# users commonly want.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
config.
|
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
|
-
#
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
#
|
57
|
-
|
58
|
-
|
59
|
-
#
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
|
67
|
-
|
68
|
-
#
|
69
|
-
#
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
#
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
1
|
+
require "99_game"
|
2
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
3
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
4
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
5
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, make a
|
11
|
+
# separate helper file that requires this one and then use it only in the specs
|
12
|
+
# that actually need it.
|
13
|
+
#
|
14
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
15
|
+
# users commonly want.
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
RSpec.configure do |config|
|
18
|
+
# The settings below are suggested to provide a good initial experience
|
19
|
+
# with RSpec, but feel free to customize to your heart's content.
|
20
|
+
# These two settings work together to allow you to limit a spec run
|
21
|
+
# to individual examples or groups you care about by tagging them with
|
22
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
23
|
+
# get run.
|
24
|
+
config.filter_run :focus
|
25
|
+
config.run_all_when_everything_filtered = true
|
26
|
+
|
27
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
28
|
+
# file, and it's useful to allow more verbose output when running an
|
29
|
+
# individual spec file.
|
30
|
+
if config.files_to_run.one?
|
31
|
+
# Use the documentation formatter for detailed output,
|
32
|
+
# unless a formatter has already been configured
|
33
|
+
# (e.g. via a command-line flag).
|
34
|
+
config.default_formatter = 'doc'
|
35
|
+
end
|
36
|
+
|
37
|
+
# Print the 10 slowest examples and example groups at the
|
38
|
+
# end of the spec run, to help surface which specs are running
|
39
|
+
# particularly slow.
|
40
|
+
config.profile_examples = 10
|
41
|
+
|
42
|
+
# Run specs in random order to surface order dependencies. If you find an
|
43
|
+
# order dependency and want to debug it, you can fix the order by providing
|
44
|
+
# the seed, which is printed after each run.
|
45
|
+
# --seed 1234
|
46
|
+
config.order = :random
|
47
|
+
|
48
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
49
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
50
|
+
# test failures related to randomization by passing the same `--seed` value
|
51
|
+
# as the one that triggered the failure.
|
52
|
+
Kernel.srand config.seed
|
53
|
+
|
54
|
+
# rspec-expectations config goes here. You can use an alternate
|
55
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
56
|
+
# assertions if you prefer.
|
57
|
+
config.expect_with :rspec do |expectations|
|
58
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
59
|
+
# For more details, see:
|
60
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
61
|
+
expectations.syntax = :expect
|
62
|
+
end
|
63
|
+
|
64
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
65
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
66
|
+
config.mock_with :rspec do |mocks|
|
67
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
68
|
+
# For more details, see:
|
69
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
70
|
+
mocks.syntax = :expect
|
71
|
+
|
72
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
73
|
+
# a real object. This is generally recommended.
|
74
|
+
mocks.verify_partial_doubles = true
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 99_game
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3.pre.68
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Perlmutter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
13
|
+
description: ! 'This is a text-based interpretation of the card game 99. Comes with
|
14
|
+
the gem in the form of an executable. Make sure to read the rules in `99_game -h`
|
15
|
+
before playing.
|
16
|
+
|
17
|
+
'
|
15
18
|
email: zrp200@gmail.com
|
16
19
|
executables:
|
17
20
|
- 99_game
|
@@ -20,12 +23,12 @@ extra_rdoc_files:
|
|
20
23
|
- README.md
|
21
24
|
- LICENSE.txt
|
22
25
|
files:
|
23
|
-
-
|
26
|
+
- .rspec
|
24
27
|
- LICENSE.txt
|
25
28
|
- README.md
|
26
29
|
- bin/99_game
|
27
30
|
- lib/99_game.rb
|
28
|
-
- spec/lib/
|
31
|
+
- spec/lib/99_game_spec.rb
|
29
32
|
- spec/spec_helper.rb
|
30
33
|
homepage: https://rubygems.org/gems/99_game
|
31
34
|
licenses:
|
@@ -37,22 +40,21 @@ require_paths:
|
|
37
40
|
- lib
|
38
41
|
required_ruby_version: !ruby/object:Gem::Requirement
|
39
42
|
requirements:
|
40
|
-
- -
|
43
|
+
- - ! '>='
|
41
44
|
- !ruby/object:Gem::Version
|
42
45
|
version: 1.9.3
|
43
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
47
|
requirements:
|
45
|
-
- -
|
48
|
+
- - ! '>'
|
46
49
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
50
|
+
version: 1.3.1
|
48
51
|
requirements: []
|
49
52
|
rubyforge_project:
|
50
|
-
rubygems_version: 2.
|
53
|
+
rubygems_version: 2.4.2
|
51
54
|
signing_key:
|
52
55
|
specification_version: 4
|
53
56
|
summary: The game of 99.
|
54
57
|
test_files:
|
55
|
-
- spec/lib/
|
56
|
-
-
|
58
|
+
- spec/lib/99_game_spec.rb
|
59
|
+
- .rspec
|
57
60
|
- spec/spec_helper.rb
|
58
|
-
has_rdoc:
|