99_game 3.1.4 → 3.2.0
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.
- checksums.yaml +8 -8
- data/bin/99_game +29 -33
- data/lib/99_game.rb +5 -7
- data/lib/hand.rb +9 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDIwODlkMTM2MzQ3NmFkMGRhZWNlZWZlZTAyNDA5YmFhNzYxNTU5ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTk5MmExMWRmOTVhNDlkNGI5Y2Q4NDRmYTJhMzg1YTNmMWY3NTFmMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzMzNWE0MzgxZjJkMmQ4YWQyZTA2MDBiNjhlOWYzOWEwMDlmNjg5NjY0ODIw
|
10
|
+
ODQwOGYxZWY0OWM5M2NhODkwZWJlNjQzYjdiYmRkYTZjMDcxZjNjYzA3OWQ0
|
11
|
+
ZjA0MWU0YmQzZTM3OGM2NzA0NjkyYWUwNjU1NmFhMWRjOTQ1OTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmMyY2E1ZGU0NmQ4YWJlMzg4MGE5YTIwZjMwMWUwMDQ4NjdiNmQ3M2I3MDA4
|
14
|
+
YzQ0MDYxM2Q1OGQ3NDY0YzNlMDRlNTdiNGM5OTM3OTI1ZTVlNjMxYjQ4NGYw
|
15
|
+
NmE2Njk1OGJkZmI4MzZmZjEyNDVmNWNiYmFkOGNhMmM5NTNiNDI=
|
data/bin/99_game
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require '99_game'
|
3
3
|
include CardDeck
|
4
|
-
deck = Deck.new jokers: true
|
5
|
-
deck.cards.shuffle!
|
6
4
|
BEGIN { # Looks at its arguements
|
7
5
|
ARGV[0] = "-h" if ARGV.first == "--help"
|
8
6
|
ARGV[0] = "-v" if ARGV[0] == "--version"
|
@@ -23,56 +21,54 @@ BEGIN { # Looks at its arguements
|
|
23
21
|
puts "\u00B7 Gameplay"
|
24
22
|
puts "\t\u00B7 Your goal is to get your opponent to bring the value over 99 by playing 1 of your 3 cards."
|
25
23
|
puts "\t\u00B7 A card will usually increase the value by itself, but there are a few exceptions:"
|
26
|
-
puts "\t\
|
27
|
-
puts "\t\
|
28
|
-
puts "\t\
|
29
|
-
puts "\t\
|
30
|
-
puts "\t\
|
31
|
-
puts "\t\
|
24
|
+
puts "\t\u00B7 Aces are worth 1"
|
25
|
+
puts "\t\u00B7 2 - 10 are worth themselves, with the exception of 4 and 9"
|
26
|
+
puts "\t\u00B7 4, 9, and Jacks are worth 0"
|
27
|
+
puts "\t\u00B7 Queens decrease the value by 10"
|
28
|
+
puts "\t\u00B7 Kings set the value to 99"
|
29
|
+
puts "\t\u00B7 Jokers set the value to 0"
|
32
30
|
exit
|
33
31
|
end
|
34
32
|
}
|
35
33
|
END { # Thanks for playing
|
36
34
|
sleep 1.5
|
37
|
-
puts "\
|
35
|
+
puts "\nThanks for playing 99!"
|
38
36
|
sleep 2.5
|
39
37
|
}
|
40
38
|
$value, value1, value2, value3, dealer, user = 0,0,0,0, Hand.new, Hand.new
|
41
39
|
loop do
|
42
|
-
puts "\
|
43
|
-
i =
|
40
|
+
puts "\nIt's the dealer's turn!"
|
41
|
+
i = 0
|
44
42
|
for card in dealer.cards
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
i += 1
|
43
|
+
case i += 1
|
44
|
+
when 1 then value1 = card_test card, $value
|
45
|
+
when 2 then value2 = card_test card, $value
|
46
|
+
when 3 then value3 = card_test card, $value
|
47
|
+
end
|
51
48
|
end
|
52
49
|
if value1 >= value2 && value1 >= value3
|
53
|
-
$card = dealer.cards
|
54
|
-
dealer.play dealer.cards[0]
|
50
|
+
$card = dealer.play dealer.cards.first
|
55
51
|
elsif value2 >= value1 && value2 >= value3
|
56
|
-
$card = dealer.cards[1]
|
57
|
-
dealer.play dealer.cards[1]
|
52
|
+
$card = dealer.play dealer.cards[1]
|
58
53
|
else
|
59
|
-
$card = dealer.cards[2]
|
60
|
-
dealer.play dealer.cards[2]
|
54
|
+
$card = dealer.play dealer.cards[2]
|
61
55
|
end
|
62
56
|
pause 1.5
|
63
|
-
puts "
|
57
|
+
puts "The dealer played a(n) #{$card}"
|
64
58
|
pause(0.5)
|
65
|
-
puts "
|
59
|
+
puts "The value is now #{$value}\n"
|
66
60
|
pause(1.5)
|
67
61
|
if $value > 99 # Runs when you win and exits loop
|
68
|
-
puts "
|
62
|
+
puts "You win!"
|
69
63
|
break
|
70
64
|
end
|
71
|
-
puts "
|
65
|
+
puts "It's your turn!"
|
72
66
|
pause 1
|
73
|
-
user.
|
67
|
+
user.view_cards
|
74
68
|
pause 0.5
|
75
|
-
|
69
|
+
puts "Pick a card to play by typing in the name of the card"
|
70
|
+
sleep 0.2
|
71
|
+
print "> "
|
76
72
|
input, playing = gets.chomp, true
|
77
73
|
user.cards.each do |card|
|
78
74
|
if card.num == converter(input) && playing
|
@@ -81,12 +77,12 @@ loop do
|
|
81
77
|
end
|
82
78
|
end
|
83
79
|
pause 1
|
84
|
-
puts "
|
85
|
-
pause
|
86
|
-
puts "
|
80
|
+
puts "You drew a(n) #{user.cards[2]}"
|
81
|
+
pause 0.5
|
82
|
+
puts "The value is now #{$value}"
|
87
83
|
pause(1.5)
|
88
84
|
if $value > 99 # Runs when dealer wins and exits loop
|
89
|
-
puts "
|
85
|
+
puts "You lose..."
|
90
86
|
break
|
91
87
|
end
|
92
88
|
end
|
data/lib/99_game.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
autoload :CardDeck, "card_deck"
|
2
2
|
autoload :Card, "card"
|
3
3
|
autoload :Hand, "hand"
|
4
|
-
|
5
4
|
=begin
|
6
5
|
@param card [CardDeck::Card]
|
7
6
|
@param actual_value [Integer]
|
8
|
-
@param test_value [Integer]
|
9
7
|
@return [Integer]
|
10
8
|
@note Used by the CPU to determine which card to play. Parameter card needs to be an instance of Card.
|
11
9
|
=end
|
@@ -48,11 +46,11 @@ def converter(input)
|
|
48
46
|
raise(CardError, "Input cannot be blank") if input == String.new
|
49
47
|
if input.to_i.zero?
|
50
48
|
case input.capitalize
|
51
|
-
when
|
52
|
-
when ?K then "King"
|
53
|
-
when ?J then "Jack"
|
54
|
-
when ?Q then "Queen"
|
55
|
-
when ?A then "Ace"
|
49
|
+
when ?$, "Joker" then "Joker"
|
50
|
+
when ?K, "King" then "King"
|
51
|
+
when ?J, "Jack" then "Jack"
|
52
|
+
when ?Q, "Queen" then "Queen"
|
53
|
+
when ?A, "Ace" then "Ace"
|
56
54
|
end
|
57
55
|
else
|
58
56
|
input.to_i
|
data/lib/hand.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require_relative "card.rb"
|
2
|
+
$deck = Deck.new(jokers: true).cards.shuffle!
|
2
3
|
class Hand # Creates an object that holds and can play cards. Interacts with Deck objects.
|
3
4
|
@@deck = Deck.new.cards.shuffle!
|
4
5
|
attr_accessor :cards # @return [Array<CardDeck::Card>]
|
5
6
|
def initialize
|
6
|
-
@cards = Array.new(3) {
|
7
|
+
@cards = Array.new(3) {$deck.shift}
|
7
8
|
end
|
8
9
|
|
9
10
|
=begin
|
@@ -12,6 +13,7 @@ class Hand # Creates an object that holds and can play cards. Interacts with Dec
|
|
12
13
|
@note Gameplay method
|
13
14
|
=end
|
14
15
|
def play(card)
|
16
|
+
raise "Card not found" unless @cards.include? card
|
15
17
|
if card.num == "King"
|
16
18
|
$value = 99
|
17
19
|
elsif card.num == "Joker"
|
@@ -24,21 +26,22 @@ class Hand # Creates an object that holds and can play cards. Interacts with Dec
|
|
24
26
|
if index.num == card.num and not done
|
25
27
|
discard = @cards[i]
|
26
28
|
@cards.delete_at i
|
27
|
-
@cards.push
|
28
|
-
|
29
|
+
@cards.push $deck.shift
|
30
|
+
$deck.push discard
|
29
31
|
done = true
|
30
32
|
end
|
31
33
|
i += 1
|
32
34
|
end
|
35
|
+
card
|
33
36
|
end
|
34
37
|
|
35
38
|
=begin
|
36
39
|
@return [void]
|
37
40
|
Displays cards
|
38
41
|
=end
|
39
|
-
def
|
40
|
-
print "
|
41
|
-
@cards.each {|card| print "\t#{card
|
42
|
+
def view_cards
|
43
|
+
print "These are your cards: "
|
44
|
+
@cards.each {|card| print "\t#{card}"}
|
42
45
|
end
|
43
46
|
alias inspect cards
|
44
47
|
end
|