PlayRockPaperScissorsGame 2.2.3 → 2.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/bin/PlayRockPaperScissorsGame +12 -4
- data/bin/rps +7 -0
- data/lib/ref/PrivateMethods.rb +8 -2
- data/lib/rps/version.rb +1 -1
- data/rps.gemspec +1 -1
- data/test/test_rps.rb +7 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c1015020d251332e0b2be0db5ac330a37cc46d9
|
4
|
+
data.tar.gz: 6dc05775f91dd30253190f37253346dfd4ca761c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 866311fa990c33a9e77772e9c99db464e690e0c8ed78db3559c0b7b2ef061a004060f71fe87f468e4f6b60b242067225befa3430853a47bf6182e74498e235c0
|
7
|
+
data.tar.gz: f3986f9fe53c3dc4adf444a664582a704cda75f307cdd3c18a7e01c32f4997808c50770b8c0ab0220e4f620dfee283e27a30bb8e2d2c854cc70d23e047f8cc30
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -11,12 +11,13 @@
|
|
11
11
|
|
12
12
|
class PlayRockPaperScissorsGame
|
13
13
|
|
14
|
+
# intiate the colorize gem
|
14
15
|
require "colorized_string"
|
15
16
|
ColorizedString.colors
|
16
17
|
ColorizedString.modes
|
17
18
|
|
18
19
|
module Constants
|
19
|
-
protected
|
20
|
+
protected # make constants protected
|
20
21
|
NTRY_TO_SYM = { 'p' => :PAPER, 'r' => :ROCK, 's' => :SCISSORS }
|
21
22
|
VALID_ENTRIES = NTRY_TO_SYM.keys
|
22
23
|
COMPUTER_CHOICES = NTRY_TO_SYM.values
|
@@ -26,10 +27,10 @@ class PlayRockPaperScissorsGame
|
|
26
27
|
end
|
27
28
|
|
28
29
|
class << self
|
29
|
-
def continue(str1,
|
30
|
+
def continue(str1,str2,str3) # pass in 3 parameters
|
30
31
|
puts ColorizedString[str1].colorize(:color => :green)
|
31
32
|
print ColorizedString[str2].colorize(:color => :green)
|
32
|
-
gets
|
33
|
+
gets # press enter or return to continue
|
33
34
|
puts ColorizedString[str3].colorize(:color => :green)
|
34
35
|
end
|
35
36
|
end
|
@@ -42,7 +43,7 @@ class PlayRockPaperScissorsGame
|
|
42
43
|
puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
|
43
44
|
ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}"].colorize(:blue)
|
44
45
|
player = PrivateMethods.player_choice
|
45
|
-
computer = Constants::COMPUTER_CHOICES.sample
|
46
|
+
computer = Constants::COMPUTER_CHOICES.sample # chooses a random option
|
46
47
|
puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}"].colorize(:blue)
|
47
48
|
puts ColorizedString["Computer chooses #{computer.to_s.downcase}"].colorize(:blue)
|
48
49
|
case PrivateMethods.player_outcome [player, computer]
|
@@ -81,6 +82,13 @@ class PlayRockPaperScissorsGame
|
|
81
82
|
elsif choice != Constants::VALID_ENTRIES
|
82
83
|
puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green)
|
83
84
|
end
|
85
|
+
# # one may also do this:
|
86
|
+
# case
|
87
|
+
# when Constants::NTRY_TO_SYM.key?(choice)
|
88
|
+
# return Constants::NTRY_TO_SYM[choice]
|
89
|
+
# when choice != Constants::VALID_ENTRIES
|
90
|
+
# puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green)
|
91
|
+
# end
|
84
92
|
end
|
85
93
|
end
|
86
94
|
def player_outcome(plays)
|
data/bin/rps
CHANGED
@@ -81,6 +81,13 @@ class PlayRockPaperScissorsGame
|
|
81
81
|
elsif choice != Constants::VALID_ENTRIES
|
82
82
|
puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green)
|
83
83
|
end
|
84
|
+
# # one may also do this:
|
85
|
+
# case
|
86
|
+
# when Constants::NTRY_TO_SYM.key?(choice)
|
87
|
+
# return Constants::NTRY_TO_SYM[choice]
|
88
|
+
# when choice != Constants::VALID_ENTRIES
|
89
|
+
# puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green)
|
90
|
+
# end
|
84
91
|
end
|
85
92
|
end
|
86
93
|
def player_outcome(plays)
|
data/lib/ref/PrivateMethods.rb
CHANGED
@@ -7,13 +7,19 @@ module PrivateMethods
|
|
7
7
|
def player_choice
|
8
8
|
loop do
|
9
9
|
print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green)
|
10
|
-
choice = gets.chomp.
|
11
|
-
|
10
|
+
choice = gets.chomp.downcasec
|
12
11
|
if Constants::NTRY_TO_SYM.key?(choice)
|
13
12
|
return Constants::NTRY_TO_SYM[choice]
|
14
13
|
elsif choice != Constants::VALID_ENTRIES
|
15
14
|
puts ColorizedString["That entry is invalid. Please re-enter"].colorize(:green)
|
16
15
|
end
|
16
|
+
# # one may also do this:
|
17
|
+
# case
|
18
|
+
# when Constants::NTRY_TO_SYM.key?(choice)
|
19
|
+
# return Constants::NTRY_TO_SYM[choice]
|
20
|
+
# when choice != Constants::VALID_ENTRIES
|
21
|
+
# puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green)
|
22
|
+
# end
|
17
23
|
end
|
18
24
|
end
|
19
25
|
def player_outcome(plays)
|
data/lib/rps/version.rb
CHANGED
data/rps.gemspec
CHANGED
data/test/test_rps.rb
CHANGED
@@ -77,6 +77,13 @@ class RakeTest # create test
|
|
77
77
|
elsif choice != Constants::VALID_ENTRIES
|
78
78
|
puts ColorizedString["That entry is invalid. Please re-enter"].colorize(:green)
|
79
79
|
end
|
80
|
+
# # one may also do this:
|
81
|
+
# case
|
82
|
+
# when Constants::NTRY_TO_SYM.key?(choice)
|
83
|
+
# return Constants::NTRY_TO_SYM[choice]
|
84
|
+
# when choice != Constants::VALID_ENTRIES
|
85
|
+
# puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green)
|
86
|
+
# end
|
80
87
|
end
|
81
88
|
end
|
82
89
|
def player_outcome(plays)
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|