99_game 1.0.3 → 1.1.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 +4 -4
- data/lib/99_game.rb +41 -22
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d47c0af29852aaaf7ccb6080d1fe48e4c2a3c48
|
4
|
+
data.tar.gz: 7478123f5a2add309177b0215c63426cb05c96d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e71d95456f26037773646c1996f524ca471bdfd9fea4b6ab85aa278a4afeaddc08a65c89e9e10d30aee1cd58f56936b96495563251c81b92f1354121cdd1f39f
|
7
|
+
data.tar.gz: 67ee15ff49322cd10eab7cf272d38e9e19a2bee2574be742c9eddba6ab86cde3e8d73804169ebc4a4a43413ac7d68b6c6f69a59534d58110d289295222a231f3
|
data/lib/99_game.rb
CHANGED
@@ -1,20 +1,34 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# Tests if obj is not nil.
|
2
|
+
def not_nil?(obj)
|
3
|
+
if obj.nil
|
4
|
+
return false
|
5
|
+
else
|
6
|
+
return true
|
7
|
+
end
|
4
8
|
end
|
9
|
+
# Converts _input_ to an integer if String#capitalize does something. If _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
|
5
10
|
def converter(input)
|
6
|
-
|
7
|
-
|
11
|
+
abbrev = {"$".to_sym => "Joker", K: "King", J: "Jack", Q: "Queen", A: "Ace"}
|
12
|
+
if input == input.capitalize
|
13
|
+
return input.to_i
|
14
|
+
elsif not_nil? abbrev[input.capitalize.to_sym]
|
15
|
+
return abbrev[input.capitalize.to_sym]
|
16
|
+
elsif input.nil || input == String.new
|
17
|
+
raise CardError, "Input not allowed"
|
18
|
+
else
|
19
|
+
return input.capitalize
|
8
20
|
end
|
9
21
|
end
|
10
22
|
class CardError < Exception; end
|
11
23
|
class Card # Represents a card in the deck
|
12
24
|
attr_reader :num
|
13
25
|
@@value = {"Ace" => 1, 4 => 0, 9 => 0, "Jack" => 0, "Joker" => 0, "King" => 99, "Queen" => -10}
|
26
|
+
# Gives the Card's value
|
14
27
|
def value
|
15
28
|
@@value.default = @num.to_i
|
16
29
|
return @@value[@num]
|
17
30
|
end
|
31
|
+
# Backup method for Card#value
|
18
32
|
def _value
|
19
33
|
return case @num
|
20
34
|
when "Ace" then 1
|
@@ -29,11 +43,14 @@ class Card # Represents a card in the deck
|
|
29
43
|
when "Joker" then 0
|
30
44
|
end
|
31
45
|
end
|
46
|
+
# Creates a new card
|
32
47
|
def initialize(card); @num = card; end
|
33
48
|
end
|
34
|
-
class Hand # Creates
|
49
|
+
class Hand # Creates an object that holds and can play cards
|
35
50
|
attr_reader :hand
|
51
|
+
# Creates a new Hand
|
36
52
|
def initialize; @hand = [$deck.shift, $deck.shift, $deck.shift]; end
|
53
|
+
# Gameplay method
|
37
54
|
def play(card)
|
38
55
|
if card.num == "King"; $value = 99
|
39
56
|
elsif card.num == "Joker"; $value = 0
|
@@ -52,31 +69,33 @@ class Hand # Creates a object that holds and can play cards
|
|
52
69
|
i += 1
|
53
70
|
end
|
54
71
|
end
|
72
|
+
# Allows you to see your cards.
|
55
73
|
def view
|
56
|
-
|
74
|
+
print "\tThese are your cards: "
|
57
75
|
@hand.each {|card| print "\t#{card.num}"}
|
58
76
|
end
|
59
77
|
end
|
78
|
+
# Combines sleep and a newline.
|
60
79
|
def pause(p)
|
61
|
-
sleep
|
80
|
+
sleep p
|
62
81
|
puts
|
63
82
|
end
|
64
83
|
$deck = Array.new
|
65
84
|
4.times do # Add the cards to the deck
|
66
|
-
$deck.push
|
67
|
-
$deck.push
|
68
|
-
$deck.push
|
69
|
-
$deck.push
|
70
|
-
$deck.push
|
71
|
-
$deck.push
|
72
|
-
$deck.push
|
73
|
-
$deck.push
|
74
|
-
$deck.push
|
75
|
-
$deck.push
|
76
|
-
$deck.push
|
77
|
-
$deck.push
|
78
|
-
$deck.push
|
85
|
+
$deck.push Card.new("Ace")
|
86
|
+
$deck.push Card.new("King")
|
87
|
+
$deck.push Card.new("Queen")
|
88
|
+
$deck.push Card.new("Jack")
|
89
|
+
$deck.push Card.new(10)
|
90
|
+
$deck.push Card.new(9)
|
91
|
+
$deck.push Card.new(8)
|
92
|
+
$deck.push Card.new(7)
|
93
|
+
$deck.push Card.new(6)
|
94
|
+
$deck.push Card.new(5)
|
95
|
+
$deck.push Card.new(4)
|
96
|
+
$deck.push Card.new(3)
|
97
|
+
$deck.push Card.new(2)
|
79
98
|
end
|
80
|
-
2.times {$deck.push
|
99
|
+
2.times {$deck.push Card.new("Joker")}
|
81
100
|
$deck.shuffle!
|
82
101
|
__END__
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 99_game
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
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-06-
|
11
|
+
date: 2014-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
|
-
This is a text-based interpretation of the card game 99.
|
14
|
+
This is a text-based interpretation of the card game 99. Comes with the gem in the form of an executable.
|
15
15
|
email: zrp200@gmail.com
|
16
16
|
executables:
|
17
17
|
- 99_game
|