99_game 3.2.0 → 3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/bin/99_game +56 -52
- data/lib/99_game.rb +6 -7
- data/lib/hand.rb +8 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2JlNmYzM2M3YzNlZjBmM2EwYTFlMjNmMGYyYWJlMzNhN2YyNDNmOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZGNkNjVhYTE2NDcxZTAzYmU0NmZlNjk0MzE4MjRlY2FmNzZjMzVhOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2E2NDdkNDBhZDBmNzU1MDZkZjU5M2QwN2NmMWEyMGE3YjI4OWI2MzA5ZWEx
|
10
|
+
M2JlODk0ODk3ODA2N2M1OTMxMjFmY2Q0ZjZmYWYzODBhNWE5YzM1YzA0NmM4
|
11
|
+
ZDM4ZTkzNDlmNjc1NmQ5MWEzNTQzNGZmZThkMjViN2ExZGI0MTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjA2NGE1YzgzMmM3NjBlNGZiNjZlN2VlY2VlNjI1ZTZhNjc0ZjJjN2Y5MDVj
|
14
|
+
YmM5Y2FlNzFjODY5ZDYxOTIyMzIwZjJmNDFhNTFjMzQwZTNlZWM2ODgwMTIw
|
15
|
+
ZDJkZmFlODk1NGQ1YmQ3ZmU2ZjcwODdmMGY3NTFiZmUxMDNlZTI=
|
data/bin/99_game
CHANGED
@@ -6,13 +6,13 @@ BEGIN { # Looks at its arguements
|
|
6
6
|
ARGV[0] = "-v" if ARGV[0] == "--version"
|
7
7
|
case ARGV[0]
|
8
8
|
when "-v"
|
9
|
-
puts "3.
|
9
|
+
puts "3.2.2"
|
10
10
|
exit
|
11
11
|
when "-h"
|
12
12
|
puts "\u00B7 Commands"
|
13
13
|
puts "\t\u00b7 -v/--version - display version"
|
14
14
|
puts "\t\u00B7 -h/--help - shows this message\n"
|
15
|
-
puts "\u00B7 Abbrevations"
|
15
|
+
puts "\u00B7 Abbrevations can be used instead of inputting the whole name of a card"
|
16
16
|
puts "\t\u00B7 J -> Jack"
|
17
17
|
puts "\t\u00b7 Q -> Queen"
|
18
18
|
puts "\t\u00b7 K -> King"
|
@@ -21,12 +21,11 @@ BEGIN { # Looks at its arguements
|
|
21
21
|
puts "\u00B7 Gameplay"
|
22
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
23
|
puts "\t\u00B7 A card will usually increase the value by itself, but there are a few exceptions:"
|
24
|
-
puts "\t\u00B7 Aces are worth 1"
|
25
|
-
puts "\t\
|
26
|
-
puts "\t\u00B7
|
27
|
-
puts "\t\u00B7
|
28
|
-
puts "\t\u00B7
|
29
|
-
puts "\t\u00B7 Jokers set the value to 0"
|
24
|
+
puts "\t\t\u00B7 Aces are worth 1"
|
25
|
+
puts "\t\tu00B7 4, 9, and Jacks are worth 0"
|
26
|
+
puts "\t\t\u00B7 Queens decrease the value by 10"
|
27
|
+
puts "\t\t\u00B7 Kings set the value to 99"
|
28
|
+
puts "\t\t\u00B7 Jokers set the value to 0"
|
30
29
|
exit
|
31
30
|
end
|
32
31
|
}
|
@@ -37,54 +36,59 @@ END { # Thanks for playing
|
|
37
36
|
}
|
38
37
|
$value, value1, value2, value3, dealer, user = 0,0,0,0, Hand.new, Hand.new
|
39
38
|
loop do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
39
|
+
puts "\nIt's the dealer's turn!"
|
40
|
+
i = 0
|
41
|
+
for card in dealer.cards
|
42
|
+
case i += 1
|
43
|
+
when 1 then value1 = card_test card, $value
|
44
|
+
when 2 then value2 = card_test card, $value
|
45
|
+
when 3 then value3 = card_test card, $value
|
46
|
+
end
|
47
47
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
$card = dealer.play dealer.cards[2]
|
55
|
-
end
|
56
|
-
pause 1.5
|
57
|
-
puts "The dealer played a(n) #{$card}"
|
58
|
-
pause(0.5)
|
59
|
-
puts "The value is now #{$value}\n"
|
60
|
-
pause(1.5)
|
61
|
-
if $value > 99 # Runs when you win and exits loop
|
62
|
-
puts "You win!"
|
63
|
-
break
|
64
|
-
end
|
65
|
-
puts "It's your turn!"
|
66
|
-
pause 1
|
67
|
-
user.view_cards
|
68
|
-
pause 0.5
|
69
|
-
puts "Pick a card to play by typing in the name of the card"
|
70
|
-
sleep 0.2
|
71
|
-
print "> "
|
72
|
-
input, playing = gets.chomp, true
|
73
|
-
user.cards.each do |card|
|
74
|
-
if card.num == converter(input) && playing
|
75
|
-
user.play card
|
76
|
-
playing = false
|
48
|
+
if value1 >= value2 && value1 >= value3
|
49
|
+
$card = dealer.play dealer.cards.first
|
50
|
+
elsif value2 >= value1 && value2 >= value3
|
51
|
+
$card = dealer.play dealer.cards[1]
|
52
|
+
else
|
53
|
+
$card = dealer.play dealer.cards.last
|
77
54
|
end
|
78
|
-
|
55
|
+
pause 1.5
|
56
|
+
puts "The dealer played #{$card}"
|
57
|
+
pause(0.5)
|
58
|
+
puts "The value is now #{$value}\n"
|
59
|
+
pause(1.5)
|
60
|
+
if $value > 99 # Runs when you win and exits loop
|
61
|
+
puts "You win!"
|
62
|
+
break
|
63
|
+
end
|
64
|
+
puts "It's your turn!"
|
65
|
+
pause 1
|
66
|
+
user.view_cards
|
67
|
+
pause 0.5
|
68
|
+
puts "Pick a card to play by typing in the name of the card"
|
69
|
+
sleep 0.2
|
70
|
+
playing = true
|
71
|
+
while playing
|
72
|
+
print "> "
|
73
|
+
input = gets.chomp
|
74
|
+
user.cards.each do |card|
|
75
|
+
if card.num == converter(input) && playing
|
76
|
+
user.play card
|
77
|
+
playing = false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
sleep 0.2
|
81
|
+
puts "Illegal input. Please enter a legal card" if playing
|
82
|
+
end
|
79
83
|
pause 1
|
80
|
-
puts "You drew
|
84
|
+
puts "You drew #{user.cards.last}"
|
81
85
|
pause 0.5
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
86
|
+
puts "The value is now #{$value}"
|
87
|
+
pause(1.5)
|
88
|
+
if $value > 99 # Runs when dealer wins and exits loop
|
89
|
+
puts "You lose..."
|
90
|
+
break
|
91
|
+
end
|
88
92
|
end
|
89
93
|
__END__
|
90
94
|
Programmed by: Zachary Perlmutter
|
data/lib/99_game.rb
CHANGED
@@ -8,15 +8,14 @@ autoload :Hand, "hand"
|
|
8
8
|
@note Used by the CPU to determine which card to play. Parameter card needs to be an instance of Card.
|
9
9
|
=end
|
10
10
|
def card_test(card, actual_value)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
test_value = 0
|
11
|
+
test_value = case card.num
|
12
|
+
when "King" then 99
|
13
|
+
when "Joker" then 0
|
15
14
|
else
|
16
|
-
|
15
|
+
actual_value + card.value
|
17
16
|
end
|
18
|
-
test_value = -
|
19
|
-
|
17
|
+
test_value = -1 if test_value > 99
|
18
|
+
test_value
|
20
19
|
end
|
21
20
|
# Tests if obj is not nil.
|
22
21
|
def not_nil?(obj)
|
data/lib/hand.rb
CHANGED
@@ -7,11 +7,9 @@ class Hand # Creates an object that holds and can play cards. Interacts with Dec
|
|
7
7
|
@cards = Array.new(3) {$deck.shift}
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@note Gameplay method
|
14
|
-
=end
|
10
|
+
# @param card [CardDeck::Card] the card played
|
11
|
+
# @return [void]
|
12
|
+
# @note Gameplay method
|
15
13
|
def play(card)
|
16
14
|
raise "Card not found" unless @cards.include? card
|
17
15
|
if card.num == "King"
|
@@ -29,19 +27,18 @@ class Hand # Creates an object that holds and can play cards. Interacts with Dec
|
|
29
27
|
@cards.push $deck.shift
|
30
28
|
$deck.push discard
|
31
29
|
done = true
|
30
|
+
$deck.shuffle!
|
32
31
|
end
|
33
32
|
i += 1
|
34
33
|
end
|
35
34
|
card
|
36
35
|
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
Displays cards
|
41
|
-
=end
|
37
|
+
# @return [void]
|
38
|
+
# Displays cards
|
42
39
|
def view_cards
|
43
|
-
print "These are your cards:
|
44
|
-
@cards.each {|card| print "
|
40
|
+
print "These are your cards: "
|
41
|
+
@cards.each {|card| print "#{card} "}
|
45
42
|
end
|
46
43
|
alias inspect cards
|
47
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 99_game
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.
|
4
|
+
version: 3.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Roth Perlmutter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: card_deck
|