PlayRockPaperScissorsGame 2.8.7 → 2.8.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23797206cc342c189737b2b1359295290c8de862
4
- data.tar.gz: 4425cb0de7de2eaa2337415dc162710d544574d6
3
+ metadata.gz: f601a926c5e59f0cfdec18d13e85759ce9a4a768
4
+ data.tar.gz: 578bfd6b4d5e64f7dd359e2cda7714ce4777447f
5
5
  SHA512:
6
- metadata.gz: 7c5177555dfc864665cc2d574cef969682655ed43995cde10f4371bb2732eb6ccd63868d0ff99d25656ea408873ff4d29e14385eff0063c91252dec45a80b7b5
7
- data.tar.gz: 101bf9eb965fc8d8c19db00f9d3a08f3c55044f3fceaa4ba02d28a0f3ab0d57aed06795c43ab0a46304d76f58aff76599002942f8793142b62915375bf6d1e31
6
+ metadata.gz: bdbe1221670ef068ec2a4bbd81d500bb3347e2d89378533e67bd65b672253eaed756354c13bdf8041949b5182d9cd6b336503cc6514999151a2b14c36652fa7b
7
+ data.tar.gz: beb70aed971b4de4bc524974de36c7cde89516236c0b46719520d855a5be047ae9548b4eb7895b97e945a78701f7fdc9d60c4ebf274ab387f90d7ff81ea6a1c1
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/.gitignore CHANGED
@@ -7,9 +7,10 @@
7
7
  *.ste
8
8
  *other langs
9
9
  *RPS.rb
10
+ *RPS_RAW.rb
10
11
  # _site
11
12
  # .sass-cache
12
13
 
13
14
  # If gitignore is not working:
14
15
  # try this:
15
- # git rm -rf --cached .
16
+ # git rm -rf --cached .
@@ -38,25 +38,25 @@ class PlayRockPaperScissorsGame
38
38
  def play(winning_score)
39
39
  while @player_score < winning_score && @computer_score < winning_score # both the player's and the computer's score have to be less than 3
40
40
  puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
41
- ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}"].colorize(:blue)
41
+ ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}."].colorize(:blue)
42
42
  player = PrivateMethods.player_choice
43
43
  computer = Constants::COMPUTER_CHOICES.sample # chooses a random option for the computer
44
- puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}"].colorize(:blue)
45
- puts ColorizedString["Computer chooses #{computer.to_s.downcase}"].colorize(:blue)
44
+ puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}."].colorize(:blue)
45
+ puts ColorizedString["Computer chooses #{computer.to_s.downcase}."].colorize(:blue)
46
46
  case PrivateMethods.player_outcome [player, computer] # pass in player and computer for the contants arrays
47
47
  when :WIN
48
- puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"].colorize(:red)
48
+ puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round."].colorize(:red)
49
49
  @player_score += 1
50
50
  when :LOSE
51
- puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round"].colorize(:red)
51
+ puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round."].colorize(:red)
52
52
  @computer_score += 1
53
53
  else
54
- puts ColorizedString["Tie, choose again"].colorize(:red)
54
+ puts ColorizedString["Tie, choose again."].colorize(:red)
55
55
  @ties += 1
56
56
  end
57
57
  end
58
58
  puts ColorizedString["\nFinal score: player: #{@player_score}, "].colorize(:blue) +
59
- ColorizedString["computer: #{@computer_score} (ties: #{@ties})"].colorize(:blue)
59
+ ColorizedString["computer: #{@computer_score} (ties: #{@ties})."].colorize(:blue)
60
60
  case PrivateMethods.final_outcome(@player_score, @computer_score)
61
61
  when :WIN
62
62
  puts ColorizedString["Player wins!"].colorize(:red)
data/docs/Code.md CHANGED
@@ -35,7 +35,7 @@ Master Code
35
35
  class PlayRockPaperScissorsGame
36
36
 
37
37
  module RockPaperScissors
38
- VERSION = "2.8.7"
38
+ VERSION = "2.8.8"
39
39
  end
40
40
 
41
41
  # import the colorize gem
@@ -45,9 +45,9 @@ class PlayRockPaperScissorsGame
45
45
 
46
46
  module Constants
47
47
  NTRY_TO_SYM = { # define entry to symbol (key to value)
48
- 'p' => :PAPER ,
49
- 'r' => :ROCK ,
50
- 's' => :SCISSORS
48
+ 'p' => :PAPER , 'paper' => :PAPER ,
49
+ 'r' => :ROCK , 'rock' => :ROCK ,
50
+ 's' => :SCISSORS, 'scissors' => :SCISSORS
51
51
  }
52
52
  VALID_ENTRIES = NTRY_TO_SYM.keys
53
53
  COMPUTER_CHOICES = NTRY_TO_SYM.values
@@ -85,17 +85,17 @@ class PlayRockPaperScissorsGame
85
85
  def play(winning_score)
86
86
  while @player_score < winning_score && @computer_score < winning_score
87
87
  puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
88
- ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}"].colorize(:blue)
88
+ ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}."].colorize(:blue)
89
89
  player = PrivateMethods.player_choice
90
90
  computer = Constants::COMPUTER_CHOICES.sample # chooses a "random" option
91
- puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}"].colorize(:blue)
92
- puts ColorizedString["Computer chooses #{computer.to_s.downcase}"].colorize(:blue)
91
+ puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}."].colorize(:blue)
92
+ puts ColorizedString["Computer chooses #{computer.to_s.downcase}."].colorize(:blue)
93
93
  case PrivateMethods.player_outcome [player, computer]
94
94
  when :WIN
95
- puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"].colorize(:red)
95
+ puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round."].colorize(:red)
96
96
  @player_score += 1 # @player_score = @player_score + 1
97
97
  when :LOSE
98
- puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round"].colorize(:red)
98
+ puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round."].colorize(:red)
99
99
  @computer_score += 1
100
100
  else
101
101
  puts ColorizedString["Tie, choose again"].colorize(:red)
@@ -103,7 +103,7 @@ class PlayRockPaperScissorsGame
103
103
  end
104
104
  end
105
105
  puts ColorizedString["\nFinal score: player: #{@player_score}, "].colorize(:blue) +
106
- ColorizedString["computer: #{@computer_score} (ties: #{@ties})"].colorize(:blue)
106
+ ColorizedString["computer: #{@computer_score} (ties: #{@ties})."].colorize(:blue)
107
107
  case PrivateMethods.final_outcome(@player_score, @computer_score)
108
108
  when :WIN
109
109
  puts ColorizedString["Player wins!"].colorize(:red)
@@ -119,7 +119,7 @@ class PlayRockPaperScissorsGame
119
119
  class << self
120
120
  def player_choice
121
121
  loop do
122
- print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green)
122
+ print ColorizedString["Choose: Rock (r), Paper (p), or Scissors (s): "].colorize(:green)
123
123
  choice = gets.chomp.downcase
124
124
  if Constants::NTRY_TO_SYM.key?(choice)
125
125
  return Constants::NTRY_TO_SYM[choice]
@@ -124,13 +124,32 @@ Subtlety is usually painted all over advanced ruby code. While this does make th
124
124
  ```
125
125
 
126
126
  ```ruby
127
- class PlayRockPaperScissorsGame
127
+ #!/usr/bin/env ruby
128
+
129
+ =begin
130
+ |====================================|
131
+ | Req Ruby Ver | Req Ruby Gems Ver |
132
+ |--------------|---------------------|
133
+ | >= v2.0.0 | >= v2.6.0 |
134
+ |====================================|
135
+ =end
136
+
137
+ class PlayRockPaperScissorsGame
138
+
139
+ module RockPaperScissors
140
+ VERSION = "2.8.8"
141
+ end
142
+
143
+ # import the colorize gem
144
+ require "colorized_string"
145
+ ColorizedString.colors # import colors; ex: red, green, blue from colorize gem
146
+ ColorizedString.modes # import modes; ex: bold, italic, underline from colorize gem
128
147
 
129
148
  module Constants
130
149
  NTRY_TO_SYM = { # define entry to symbol (key to value)
131
- 'p' => :PAPER ,
132
- 'r' => :ROCK ,
133
- 's' => :SCISSORS
150
+ 'p' => :PAPER , 'paper' => :PAPER ,
151
+ 'r' => :ROCK , 'rock' => :ROCK ,
152
+ 's' => :SCISSORS, 'scissors' => :SCISSORS
134
153
  }
135
154
  VALID_ENTRIES = NTRY_TO_SYM.keys
136
155
  COMPUTER_CHOICES = NTRY_TO_SYM.values
@@ -140,60 +159,60 @@ class PlayRockPaperScissorsGame
140
159
  [:PAPER , :ROCK ],
141
160
  [:ROCK , :SCISSORS]
142
161
  ]
143
- LOSERS = WINNERS.map { |player_choice,computer_choice| [computer_choice,player_choice] } # flip the values in the WINNERS array, returning a loss
162
+ LOSERS = WINNERS.map { |player_choice,computer_choice| [computer_choice,player_choice] } # this will take the original WINNERS array and flip the symbols, thus returning a loss for the user/player
144
163
  INIT_STRINGS = [
145
- "You are about to enter a rock-paper-scissors best of 3 match.",
146
- "Press the return/enter key to continue..." ,
164
+ ColorizedString["You are about to enter a rock-paper-scissors best of 3 match."].colorize(:green),
165
+ ColorizedString["Press the return/enter key to continue..."].colorize(:green) ,
147
166
  ""
148
167
  ]
149
168
  end
150
169
 
151
- protected_methods :Constants # make constants module protected
170
+ protected_methods :Constants
152
171
 
153
- class << self
172
+ class << self # define a self calling method within the parent class
154
173
  def continue(str1,str2,str3)
155
- puts str1
174
+ puts str1
156
175
  print str2
157
- gets # press enter/return to continue
176
+ gets # press enter or return to continue
158
177
  puts str3
159
178
  end
160
179
  end
161
180
 
162
- continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2])
181
+ continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2])
163
182
 
164
- def initialize
183
+ def initialize # initialize variables
165
184
  @player_score = @computer_score = @ties = 0
166
- end
185
+ end
167
186
 
168
187
  def play(winning_score)
169
- while @player_score < winning_score && @computer_score < winning_score
170
- puts "Player score: #{@player_score}, " +
171
- "Computer score: #{@computer_score}, Ties: #{@ties}"
188
+ while @player_score < winning_score && @computer_score < winning_score
189
+ puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
190
+ ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}."].colorize(:blue)
172
191
  player = PrivateMethods.player_choice
173
- computer = Constants::COMPUTER_CHOICES.sample # .sample = pick a random choice
174
- puts "\nPlayer chooses #{player.to_s.downcase}"
175
- puts "Computer chooses #{computer.to_s.downcase}"
176
- case PrivateMethods.player_outcome [player, computer]
192
+ computer = Constants::COMPUTER_CHOICES.sample # chooses a "random" option
193
+ puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}."].colorize(:blue)
194
+ puts ColorizedString["Computer chooses #{computer.to_s.downcase}."].colorize(:blue)
195
+ case PrivateMethods.player_outcome [player, computer]
177
196
  when :WIN
178
- puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"
179
- @player_score += 1
197
+ puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round."].colorize(:red)
198
+ @player_score += 1 # @player_score = @player_score + 1
180
199
  when :LOSE
181
- puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round"
200
+ puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round."].colorize(:red)
182
201
  @computer_score += 1
183
- else
184
- puts "Tie, choose again"
202
+ else
203
+ puts ColorizedString["Tie, choose again"].colorize(:red)
185
204
  @ties += 1
186
205
  end
187
206
  end
188
- puts "\nFinal score: player: #{@player_score}, " +
189
- "computer: #{@computer_score} (ties: #{@ties})"
207
+ puts ColorizedString["\nFinal score: player: #{@player_score}, "].colorize(:blue) +
208
+ ColorizedString["computer: #{@computer_score} (ties: #{@ties})."].colorize(:blue)
190
209
  case PrivateMethods.final_outcome(@player_score, @computer_score)
191
210
  when :WIN
192
- puts "Player wins!"
211
+ puts ColorizedString["Player wins!"].colorize(:red)
193
212
  when :LOSE
194
- puts "Computer wins!"
213
+ puts ColorizedString["Computer wins!"].colorize(:red)
195
214
  else
196
- puts "It's a tie!"
215
+ puts ColorizedString["It's a tie!"].colorize(:red)
197
216
  end
198
217
  gets
199
218
  end
@@ -202,27 +221,29 @@ class PlayRockPaperScissorsGame
202
221
  class << self
203
222
  def player_choice
204
223
  loop do
205
- print "Choose rock (r), paper (p) or scissors (s): "
224
+ print ColorizedString["Choose: Rock (r), Paper (p), or Scissors (s): "].colorize(:green)
206
225
  choice = gets.chomp.downcase
207
- if Constants::NTRY_TO_SYM.key?(choice)
226
+ if Constants::NTRY_TO_SYM.key?(choice)
208
227
  return Constants::NTRY_TO_SYM[choice]
209
- elsif choice != Constants::VALID_ENTRIES
210
- puts "That entry is invalid. Please re-enter." entry message
228
+ elsif choice != Constants::VALID_ENTRIES
229
+ puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:red)
211
230
  else
212
231
  return nil
213
232
  end
214
233
  end
215
234
  end
235
+
216
236
  def player_outcome(plays)
217
237
  # plays = [player_choice, computer_choice]
218
238
  return :WIN if Constants::WINNERS.include?(plays)
219
239
  return :LOSE if Constants::LOSERS.include?(plays)
220
- return :TIE if !:WIN | !:LOSE
221
- end
240
+ return :TIE if !:WIN | !:LOSE
241
+ end
242
+
222
243
  def final_outcome(pl,co)
223
244
  return :WIN if pl > co
224
245
  return :LOSE if pl < co
225
- # there will never be a tie for the final outcome because of the play() method
246
+ # there will never be a tie fore the final outcome due to the code in the play() method
226
247
  end
227
248
  end
228
249
  end
@@ -231,5 +252,5 @@ class PlayRockPaperScissorsGame
231
252
 
232
253
  end
233
254
 
234
- PlayRockPaperScissorsGame.new.play(2)
255
+ PlayRockPaperScissorsGame.new.play(2) # call the play method and pass in 3 (0, 1, 2) for the winning score
235
256
  ```
@@ -7,7 +7,7 @@
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
8
8
  <meta name="theme-color" content="#157878"/>
9
9
  <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css' />
10
- <link rel="stylesheet" href="/assets/css/style.css?v=bf6ec5a78a162d5292114fcb1a031ba03f4b561e"/>
10
+ <link rel="stylesheet" href="/assets/css/style.css?v=9dfdf3a7dbe502b5dba0b21bd04c4f6cd97868ee"/>
11
11
  <script src="assets/js/pace.min.js"></script>
12
12
 
13
13
  <link rel="apple-touch-icon" sizes="180x180" href="assets/favicons/apple-touch-icon.png"/>
data/docs/_site/code.html CHANGED
@@ -7,7 +7,7 @@
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
8
8
  <meta name="theme-color" content="#157878"/>
9
9
  <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css' />
10
- <link rel="stylesheet" href="/assets/css/style.css?v=bf6ec5a78a162d5292114fcb1a031ba03f4b561e"/>
10
+ <link rel="stylesheet" href="/assets/css/style.css?v=9dfdf3a7dbe502b5dba0b21bd04c4f6cd97868ee"/>
11
11
  <script src="assets/js/pace.min.js"></script>
12
12
 
13
13
  <link rel="apple-touch-icon" sizes="180x180" href="assets/favicons/apple-touch-icon.png"/>
@@ -69,7 +69,7 @@
69
69
  <span class="k">class</span> <span class="nc">PlayRockPaperScissorsGame</span>
70
70
 
71
71
  <span class="k">module</span> <span class="nn">RockPaperScissors</span>
72
- <span class="no">VERSION</span> <span class="o">=</span> <span class="s2">"2.8.7"</span>
72
+ <span class="no">VERSION</span> <span class="o">=</span> <span class="s2">"2.8.8"</span>
73
73
  <span class="k">end</span>
74
74
 
75
75
  <span class="c1"># import the colorize gem</span>
@@ -79,9 +79,9 @@
79
79
 
80
80
  <span class="k">module</span> <span class="nn">Constants</span>
81
81
  <span class="no">NTRY_TO_SYM</span> <span class="o">=</span> <span class="p">{</span> <span class="c1"># define entry to symbol (key to value)</span>
82
- <span class="s1">'p'</span> <span class="o">=&gt;</span> <span class="ss">:PAPER</span> <span class="p">,</span>
83
- <span class="s1">'r'</span> <span class="o">=&gt;</span> <span class="ss">:ROCK</span> <span class="p">,</span>
84
- <span class="s1">'s'</span> <span class="o">=&gt;</span> <span class="ss">:SCISSORS</span>
82
+ <span class="s1">'p'</span> <span class="o">=&gt;</span> <span class="ss">:PAPER</span> <span class="p">,</span> <span class="s1">'paper'</span> <span class="o">=&gt;</span> <span class="ss">:PAPER</span> <span class="p">,</span>
83
+ <span class="s1">'r'</span> <span class="o">=&gt;</span> <span class="ss">:ROCK</span> <span class="p">,</span> <span class="s1">'rock'</span> <span class="o">=&gt;</span> <span class="ss">:ROCK</span> <span class="p">,</span>
84
+ <span class="s1">'s'</span> <span class="o">=&gt;</span> <span class="ss">:SCISSORS</span><span class="p">,</span> <span class="s1">'scissors'</span> <span class="o">=&gt;</span> <span class="ss">:SCISSORS</span>
85
85
  <span class="p">}</span>
86
86
  <span class="no">VALID_ENTRIES</span> <span class="o">=</span> <span class="no">NTRY_TO_SYM</span><span class="p">.</span><span class="nf">keys</span>
87
87
  <span class="no">COMPUTER_CHOICES</span> <span class="o">=</span> <span class="no">NTRY_TO_SYM</span><span class="p">.</span><span class="nf">values</span>
@@ -119,17 +119,17 @@
119
119
  <span class="k">def</span> <span class="nf">play</span><span class="p">(</span><span class="n">winning_score</span><span class="p">)</span>
120
120
  <span class="k">while</span> <span class="vi">@player_score</span> <span class="o">&lt;</span> <span class="n">winning_score</span> <span class="o">&amp;&amp;</span> <span class="vi">@computer_score</span> <span class="o">&lt;</span> <span class="n">winning_score</span>
121
121
  <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Player score: </span><span class="si">#{</span><span class="vi">@player_score</span><span class="si">}</span><span class="s2">, "</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span> <span class="o">+</span>
122
- <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Computer score: </span><span class="si">#{</span><span class="vi">@computer_score</span><span class="si">}</span><span class="s2">, Ties: </span><span class="si">#{</span><span class="vi">@ties</span><span class="si">}</span><span class="s2">"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
122
+ <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Computer score: </span><span class="si">#{</span><span class="vi">@computer_score</span><span class="si">}</span><span class="s2">, Ties: </span><span class="si">#{</span><span class="vi">@ties</span><span class="si">}</span><span class="s2">."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
123
123
  <span class="n">player</span> <span class="o">=</span> <span class="no">PrivateMethods</span><span class="p">.</span><span class="nf">player_choice</span>
124
124
  <span class="n">computer</span> <span class="o">=</span> <span class="no">Constants</span><span class="o">::</span><span class="no">COMPUTER_CHOICES</span><span class="p">.</span><span class="nf">sample</span> <span class="c1"># chooses a "random" option</span>
125
- <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Player chooses </span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
126
- <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Computer chooses </span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
125
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Player chooses </span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
126
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Computer chooses </span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
127
127
  <span class="k">case</span> <span class="no">PrivateMethods</span><span class="p">.</span><span class="nf">player_outcome</span> <span class="p">[</span><span class="n">player</span><span class="p">,</span> <span class="n">computer</span><span class="p">]</span>
128
128
  <span class="k">when</span> <span class="ss">:WIN</span>
129
- <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">capitalize</span><span class="si">}</span><span class="s2"> beats </span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">, player wins the round"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
129
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">capitalize</span><span class="si">}</span><span class="s2"> beats </span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">, player wins the round."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
130
130
  <span class="vi">@player_score</span> <span class="o">+=</span> <span class="mi">1</span> <span class="c1"># @player_score = @player_score + 1</span>
131
131
  <span class="k">when</span> <span class="ss">:LOSE</span>
132
- <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">capitalize</span><span class="si">}</span><span class="s2"> beats </span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">, computer wins the round"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
132
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">capitalize</span><span class="si">}</span><span class="s2"> beats </span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">, computer wins the round."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
133
133
  <span class="vi">@computer_score</span> <span class="o">+=</span> <span class="mi">1</span>
134
134
  <span class="k">else</span>
135
135
  <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Tie, choose again"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
@@ -137,7 +137,7 @@
137
137
  <span class="k">end</span>
138
138
  <span class="k">end</span>
139
139
  <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Final score: player: </span><span class="si">#{</span><span class="vi">@player_score</span><span class="si">}</span><span class="s2">, "</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span> <span class="o">+</span>
140
- <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"computer: </span><span class="si">#{</span><span class="vi">@computer_score</span><span class="si">}</span><span class="s2"> (ties: </span><span class="si">#{</span><span class="vi">@ties</span><span class="si">}</span><span class="s2">)"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
140
+ <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"computer: </span><span class="si">#{</span><span class="vi">@computer_score</span><span class="si">}</span><span class="s2"> (ties: </span><span class="si">#{</span><span class="vi">@ties</span><span class="si">}</span><span class="s2">)."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
141
141
  <span class="k">case</span> <span class="no">PrivateMethods</span><span class="p">.</span><span class="nf">final_outcome</span><span class="p">(</span><span class="vi">@player_score</span><span class="p">,</span> <span class="vi">@computer_score</span><span class="p">)</span>
142
142
  <span class="k">when</span> <span class="ss">:WIN</span>
143
143
  <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Player wins!"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
@@ -153,7 +153,7 @@
153
153
  <span class="k">class</span> <span class="o">&lt;&lt;</span> <span class="nb">self</span>
154
154
  <span class="k">def</span> <span class="nf">player_choice</span>
155
155
  <span class="kp">loop</span> <span class="k">do</span>
156
- <span class="nb">print</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Choose rock (r), paper (p) or scissors (s): "</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:green</span><span class="p">)</span>
156
+ <span class="nb">print</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Choose: Rock (r), Paper (p), or Scissors (s): "</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:green</span><span class="p">)</span>
157
157
  <span class="n">choice</span> <span class="o">=</span> <span class="nb">gets</span><span class="p">.</span><span class="nf">chomp</span><span class="p">.</span><span class="nf">downcase</span>
158
158
  <span class="k">if</span> <span class="no">Constants</span><span class="o">::</span><span class="no">NTRY_TO_SYM</span><span class="p">.</span><span class="nf">key?</span><span class="p">(</span><span class="n">choice</span><span class="p">)</span>
159
159
  <span class="k">return</span> <span class="no">Constants</span><span class="o">::</span><span class="no">NTRY_TO_SYM</span><span class="p">[</span><span class="n">choice</span><span class="p">]</span>
@@ -7,7 +7,7 @@
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
8
8
  <meta name="theme-color" content="#157878"/>
9
9
  <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css' />
10
- <link rel="stylesheet" href="/assets/css/style.css?v=bf6ec5a78a162d5292114fcb1a031ba03f4b561e"/>
10
+ <link rel="stylesheet" href="/assets/css/style.css?v=9dfdf3a7dbe502b5dba0b21bd04c4f6cd97868ee"/>
11
11
  <script src="assets/js/pace.min.js"></script>
12
12
 
13
13
  <link rel="apple-touch-icon" sizes="180x180" href="assets/favicons/apple-touch-icon.png"/>
@@ -176,13 +176,32 @@
176
176
  </code></pre>
177
177
  </div>
178
178
 
179
- <div class="language-ruby highlighter-rouge"><pre class="highlight"><code><span class="k">class</span> <span class="nc">PlayRockPaperScissorsGame</span>
179
+ <div class="language-ruby highlighter-rouge"><pre class="highlight"><code><span class="c1">#!/usr/bin/env ruby</span>
180
+
181
+ <span class="cm">=begin
182
+ |====================================|
183
+ | Req Ruby Ver | Req Ruby Gems Ver |
184
+ |--------------|---------------------|
185
+ | &gt;= v2.0.0 | &gt;= v2.6.0 |
186
+ |====================================|
187
+ =end</span>
188
+
189
+ <span class="k">class</span> <span class="nc">PlayRockPaperScissorsGame</span>
190
+
191
+ <span class="k">module</span> <span class="nn">RockPaperScissors</span>
192
+ <span class="no">VERSION</span> <span class="o">=</span> <span class="s2">"2.8.8"</span>
193
+ <span class="k">end</span>
194
+
195
+ <span class="c1"># import the colorize gem</span>
196
+ <span class="nb">require</span> <span class="s2">"colorized_string"</span>
197
+ <span class="no">ColorizedString</span><span class="p">.</span><span class="nf">colors</span> <span class="c1"># import colors; ex: red, green, blue from colorize gem</span>
198
+ <span class="no">ColorizedString</span><span class="p">.</span><span class="nf">modes</span> <span class="c1"># import modes; ex: bold, italic, underline from colorize gem</span>
180
199
 
181
200
  <span class="k">module</span> <span class="nn">Constants</span>
182
201
  <span class="no">NTRY_TO_SYM</span> <span class="o">=</span> <span class="p">{</span> <span class="c1"># define entry to symbol (key to value)</span>
183
- <span class="s1">'p'</span> <span class="o">=&gt;</span> <span class="ss">:PAPER</span> <span class="p">,</span>
184
- <span class="s1">'r'</span> <span class="o">=&gt;</span> <span class="ss">:ROCK</span> <span class="p">,</span>
185
- <span class="s1">'s'</span> <span class="o">=&gt;</span> <span class="ss">:SCISSORS</span>
202
+ <span class="s1">'p'</span> <span class="o">=&gt;</span> <span class="ss">:PAPER</span> <span class="p">,</span> <span class="s1">'paper'</span> <span class="o">=&gt;</span> <span class="ss">:PAPER</span> <span class="p">,</span>
203
+ <span class="s1">'r'</span> <span class="o">=&gt;</span> <span class="ss">:ROCK</span> <span class="p">,</span> <span class="s1">'rock'</span> <span class="o">=&gt;</span> <span class="ss">:ROCK</span> <span class="p">,</span>
204
+ <span class="s1">'s'</span> <span class="o">=&gt;</span> <span class="ss">:SCISSORS</span><span class="p">,</span> <span class="s1">'scissors'</span> <span class="o">=&gt;</span> <span class="ss">:SCISSORS</span>
186
205
  <span class="p">}</span>
187
206
  <span class="no">VALID_ENTRIES</span> <span class="o">=</span> <span class="no">NTRY_TO_SYM</span><span class="p">.</span><span class="nf">keys</span>
188
207
  <span class="no">COMPUTER_CHOICES</span> <span class="o">=</span> <span class="no">NTRY_TO_SYM</span><span class="p">.</span><span class="nf">values</span>
@@ -192,60 +211,60 @@
192
211
  <span class="p">[</span><span class="ss">:PAPER</span> <span class="p">,</span> <span class="ss">:ROCK</span> <span class="p">],</span>
193
212
  <span class="p">[</span><span class="ss">:ROCK</span> <span class="p">,</span> <span class="ss">:SCISSORS</span><span class="p">]</span>
194
213
  <span class="p">]</span>
195
- <span class="no">LOSERS</span> <span class="o">=</span> <span class="no">WINNERS</span><span class="p">.</span><span class="nf">map</span> <span class="p">{</span> <span class="o">|</span><span class="n">player_choice</span><span class="p">,</span><span class="n">computer_choice</span><span class="o">|</span> <span class="p">[</span><span class="n">computer_choice</span><span class="p">,</span><span class="n">player_choice</span><span class="p">]</span> <span class="p">}</span> <span class="c1"># flip the values in the WINNERS array, returning a loss</span>
214
+ <span class="no">LOSERS</span> <span class="o">=</span> <span class="no">WINNERS</span><span class="p">.</span><span class="nf">map</span> <span class="p">{</span> <span class="o">|</span><span class="n">player_choice</span><span class="p">,</span><span class="n">computer_choice</span><span class="o">|</span> <span class="p">[</span><span class="n">computer_choice</span><span class="p">,</span><span class="n">player_choice</span><span class="p">]</span> <span class="p">}</span> <span class="c1"># this will take the original WINNERS array and flip the symbols, thus returning a loss for the user/player</span>
196
215
  <span class="no">INIT_STRINGS</span> <span class="o">=</span> <span class="p">[</span>
197
- <span class="s2">"You are about to enter a rock-paper-scissors best of 3 match."</span><span class="p">,</span>
198
- <span class="s2">"Press the return/enter key to continue..."</span> <span class="p">,</span>
216
+ <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"You are about to enter a rock-paper-scissors best of 3 match."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:green</span><span class="p">),</span>
217
+ <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Press the return/enter key to continue..."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:green</span><span class="p">)</span> <span class="p">,</span>
199
218
  <span class="s2">""</span>
200
219
  <span class="p">]</span>
201
220
  <span class="k">end</span>
202
221
 
203
- <span class="nb">protected_methods</span> <span class="ss">:Constants</span> <span class="c1"># make constants module protected</span>
222
+ <span class="nb">protected_methods</span> <span class="ss">:Constants</span>
204
223
 
205
- <span class="k">class</span> <span class="o">&lt;&lt;</span> <span class="nb">self</span>
224
+ <span class="k">class</span> <span class="o">&lt;&lt;</span> <span class="nb">self</span> <span class="c1"># define a self calling method within the parent class</span>
206
225
  <span class="k">def</span> <span class="nf">continue</span><span class="p">(</span><span class="n">str1</span><span class="p">,</span><span class="n">str2</span><span class="p">,</span><span class="n">str3</span><span class="p">)</span>
207
- <span class="nb">puts</span> <span class="n">str1</span>
226
+ <span class="nb">puts</span> <span class="n">str1</span>
208
227
  <span class="nb">print</span> <span class="n">str2</span>
209
- <span class="nb">gets</span> <span class="c1"># press enter/return to continue</span>
228
+ <span class="nb">gets</span> <span class="c1"># press enter or return to continue</span>
210
229
  <span class="nb">puts</span> <span class="n">str3</span>
211
230
  <span class="k">end</span>
212
231
  <span class="k">end</span>
213
232
 
214
- <span class="n">continue</span><span class="p">(</span><span class="no">Constants</span><span class="o">::</span><span class="no">INIT_STRINGS</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="no">Constants</span><span class="o">::</span><span class="no">INIT_STRINGS</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="no">Constants</span><span class="o">::</span><span class="no">INIT_STRINGS</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
233
+ <span class="n">continue</span><span class="p">(</span><span class="no">Constants</span><span class="o">::</span><span class="no">INIT_STRINGS</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="no">Constants</span><span class="o">::</span><span class="no">INIT_STRINGS</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="no">Constants</span><span class="o">::</span><span class="no">INIT_STRINGS</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
215
234
 
216
- <span class="k">def</span> <span class="nf">initialize</span>
235
+ <span class="k">def</span> <span class="nf">initialize</span> <span class="c1"># initialize variables</span>
217
236
  <span class="vi">@player_score</span> <span class="o">=</span> <span class="vi">@computer_score</span> <span class="o">=</span> <span class="vi">@ties</span> <span class="o">=</span> <span class="mi">0</span>
218
- <span class="k">end</span>
237
+ <span class="k">end</span>
219
238
 
220
239
  <span class="k">def</span> <span class="nf">play</span><span class="p">(</span><span class="n">winning_score</span><span class="p">)</span>
221
- <span class="k">while</span> <span class="vi">@player_score</span> <span class="o">&lt;</span> <span class="n">winning_score</span> <span class="o">&amp;&amp;</span> <span class="vi">@computer_score</span> <span class="o">&lt;</span> <span class="n">winning_score</span>
222
- <span class="nb">puts</span> <span class="s2">"Player score: </span><span class="si">#{</span><span class="vi">@player_score</span><span class="si">}</span><span class="s2">, "</span> <span class="o">+</span>
223
- <span class="s2">"Computer score: </span><span class="si">#{</span><span class="vi">@computer_score</span><span class="si">}</span><span class="s2">, Ties: </span><span class="si">#{</span><span class="vi">@ties</span><span class="si">}</span><span class="s2">"</span>
240
+ <span class="k">while</span> <span class="vi">@player_score</span> <span class="o">&lt;</span> <span class="n">winning_score</span> <span class="o">&amp;&amp;</span> <span class="vi">@computer_score</span> <span class="o">&lt;</span> <span class="n">winning_score</span>
241
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Player score: </span><span class="si">#{</span><span class="vi">@player_score</span><span class="si">}</span><span class="s2">, "</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span> <span class="o">+</span>
242
+ <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Computer score: </span><span class="si">#{</span><span class="vi">@computer_score</span><span class="si">}</span><span class="s2">, Ties: </span><span class="si">#{</span><span class="vi">@ties</span><span class="si">}</span><span class="s2">."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
224
243
  <span class="n">player</span> <span class="o">=</span> <span class="no">PrivateMethods</span><span class="p">.</span><span class="nf">player_choice</span>
225
- <span class="n">computer</span> <span class="o">=</span> <span class="no">Constants</span><span class="o">::</span><span class="no">COMPUTER_CHOICES</span><span class="p">.</span><span class="nf">sample</span> <span class="c1"># .sample = pick a random choice</span>
226
- <span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">Player chooses </span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">"</span>
227
- <span class="nb">puts</span> <span class="s2">"Computer chooses </span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">"</span>
228
- <span class="k">case</span> <span class="no">PrivateMethods</span><span class="p">.</span><span class="nf">player_outcome</span> <span class="p">[</span><span class="n">player</span><span class="p">,</span> <span class="n">computer</span><span class="p">]</span>
244
+ <span class="n">computer</span> <span class="o">=</span> <span class="no">Constants</span><span class="o">::</span><span class="no">COMPUTER_CHOICES</span><span class="p">.</span><span class="nf">sample</span> <span class="c1"># chooses a "random" option</span>
245
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Player chooses </span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
246
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Computer chooses </span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
247
+ <span class="k">case</span> <span class="no">PrivateMethods</span><span class="p">.</span><span class="nf">player_outcome</span> <span class="p">[</span><span class="n">player</span><span class="p">,</span> <span class="n">computer</span><span class="p">]</span>
229
248
  <span class="k">when</span> <span class="ss">:WIN</span>
230
- <span class="nb">puts</span> <span class="s2">"</span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">capitalize</span><span class="si">}</span><span class="s2"> beats </span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">, player wins the round"</span>
231
- <span class="vi">@player_score</span> <span class="o">+=</span> <span class="mi">1</span>
249
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">capitalize</span><span class="si">}</span><span class="s2"> beats </span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">, player wins the round."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
250
+ <span class="vi">@player_score</span> <span class="o">+=</span> <span class="mi">1</span> <span class="c1"># @player_score = @player_score + 1</span>
232
251
  <span class="k">when</span> <span class="ss">:LOSE</span>
233
- <span class="nb">puts</span> <span class="s2">"</span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">capitalize</span><span class="si">}</span><span class="s2"> beats </span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">, computer wins the round"</span>
252
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">capitalize</span><span class="si">}</span><span class="s2"> beats </span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">, computer wins the round."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
234
253
  <span class="vi">@computer_score</span> <span class="o">+=</span> <span class="mi">1</span>
235
- <span class="k">else</span>
236
- <span class="nb">puts</span> <span class="s2">"Tie, choose again"</span>
254
+ <span class="k">else</span>
255
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Tie, choose again"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
237
256
  <span class="vi">@ties</span> <span class="o">+=</span> <span class="mi">1</span>
238
257
  <span class="k">end</span>
239
258
  <span class="k">end</span>
240
- <span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">Final score: player: </span><span class="si">#{</span><span class="vi">@player_score</span><span class="si">}</span><span class="s2">, "</span> <span class="o">+</span>
241
- <span class="s2">"computer: </span><span class="si">#{</span><span class="vi">@computer_score</span><span class="si">}</span><span class="s2"> (ties: </span><span class="si">#{</span><span class="vi">@ties</span><span class="si">}</span><span class="s2">)"</span>
259
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Final score: player: </span><span class="si">#{</span><span class="vi">@player_score</span><span class="si">}</span><span class="s2">, "</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span> <span class="o">+</span>
260
+ <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"computer: </span><span class="si">#{</span><span class="vi">@computer_score</span><span class="si">}</span><span class="s2"> (ties: </span><span class="si">#{</span><span class="vi">@ties</span><span class="si">}</span><span class="s2">)."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
242
261
  <span class="k">case</span> <span class="no">PrivateMethods</span><span class="p">.</span><span class="nf">final_outcome</span><span class="p">(</span><span class="vi">@player_score</span><span class="p">,</span> <span class="vi">@computer_score</span><span class="p">)</span>
243
262
  <span class="k">when</span> <span class="ss">:WIN</span>
244
- <span class="nb">puts</span> <span class="s2">"Player wins!"</span>
263
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Player wins!"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
245
264
  <span class="k">when</span> <span class="ss">:LOSE</span>
246
- <span class="nb">puts</span> <span class="s2">"Computer wins!"</span>
265
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Computer wins!"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
247
266
  <span class="k">else</span>
248
- <span class="nb">puts</span> <span class="s2">"It's a tie!"</span>
267
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"It's a tie!"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
249
268
  <span class="k">end</span>
250
269
  <span class="nb">gets</span>
251
270
  <span class="k">end</span>
@@ -254,27 +273,29 @@
254
273
  <span class="k">class</span> <span class="o">&lt;&lt;</span> <span class="nb">self</span>
255
274
  <span class="k">def</span> <span class="nf">player_choice</span>
256
275
  <span class="kp">loop</span> <span class="k">do</span>
257
- <span class="nb">print</span> <span class="s2">"Choose rock (r), paper (p) or scissors (s): "</span>
276
+ <span class="nb">print</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Choose: Rock (r), Paper (p), or Scissors (s): "</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:green</span><span class="p">)</span>
258
277
  <span class="n">choice</span> <span class="o">=</span> <span class="nb">gets</span><span class="p">.</span><span class="nf">chomp</span><span class="p">.</span><span class="nf">downcase</span>
259
- <span class="k">if</span> <span class="no">Constants</span><span class="o">::</span><span class="no">NTRY_TO_SYM</span><span class="p">.</span><span class="nf">key?</span><span class="p">(</span><span class="n">choice</span><span class="p">)</span>
278
+ <span class="k">if</span> <span class="no">Constants</span><span class="o">::</span><span class="no">NTRY_TO_SYM</span><span class="p">.</span><span class="nf">key?</span><span class="p">(</span><span class="n">choice</span><span class="p">)</span>
260
279
  <span class="k">return</span> <span class="no">Constants</span><span class="o">::</span><span class="no">NTRY_TO_SYM</span><span class="p">[</span><span class="n">choice</span><span class="p">]</span>
261
- <span class="k">elsif</span> <span class="n">choice</span> <span class="o">!=</span> <span class="no">Constants</span><span class="o">::</span><span class="no">VALID_ENTRIES</span>
262
- <span class="nb">puts</span> <span class="s2">"That entry is invalid. Please re-enter."</span> <span class="n">entry</span> <span class="n">message</span>
280
+ <span class="k">elsif</span> <span class="n">choice</span> <span class="o">!=</span> <span class="no">Constants</span><span class="o">::</span><span class="no">VALID_ENTRIES</span>
281
+ <span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"That entry is invalid. Please re-enter."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
263
282
  <span class="k">else</span>
264
283
  <span class="k">return</span> <span class="kp">nil</span>
265
284
  <span class="k">end</span>
266
285
  <span class="k">end</span>
267
286
  <span class="k">end</span>
287
+
268
288
  <span class="k">def</span> <span class="nf">player_outcome</span><span class="p">(</span><span class="n">plays</span><span class="p">)</span>
269
289
  <span class="c1"># plays = [player_choice, computer_choice]</span>
270
290
  <span class="k">return</span> <span class="ss">:WIN</span> <span class="k">if</span> <span class="no">Constants</span><span class="o">::</span><span class="no">WINNERS</span><span class="p">.</span><span class="nf">include?</span><span class="p">(</span><span class="n">plays</span><span class="p">)</span>
271
291
  <span class="k">return</span> <span class="ss">:LOSE</span> <span class="k">if</span> <span class="no">Constants</span><span class="o">::</span><span class="no">LOSERS</span><span class="p">.</span><span class="nf">include?</span><span class="p">(</span><span class="n">plays</span><span class="p">)</span>
272
- <span class="k">return</span> <span class="ss">:TIE</span> <span class="k">if</span> <span class="o">!</span><span class="ss">:WIN</span> <span class="o">|</span> <span class="o">!</span><span class="ss">:LOSE</span>
273
- <span class="k">end</span>
292
+ <span class="k">return</span> <span class="ss">:TIE</span> <span class="k">if</span> <span class="o">!</span><span class="ss">:WIN</span> <span class="o">|</span> <span class="o">!</span><span class="ss">:LOSE</span>
293
+ <span class="k">end</span>
294
+
274
295
  <span class="k">def</span> <span class="nf">final_outcome</span><span class="p">(</span><span class="n">pl</span><span class="p">,</span><span class="n">co</span><span class="p">)</span>
275
296
  <span class="k">return</span> <span class="ss">:WIN</span> <span class="k">if</span> <span class="n">pl</span> <span class="o">&gt;</span> <span class="n">co</span>
276
297
  <span class="k">return</span> <span class="ss">:LOSE</span> <span class="k">if</span> <span class="n">pl</span> <span class="o">&lt;</span> <span class="n">co</span>
277
- <span class="c1"># there will never be a tie for the final outcome because of the play() method</span>
298
+ <span class="c1"># there will never be a tie fore the final outcome due to the code in the play() method</span>
278
299
  <span class="k">end</span>
279
300
  <span class="k">end</span>
280
301
  <span class="k">end</span>
@@ -283,7 +304,7 @@
283
304
 
284
305
  <span class="k">end</span>
285
306
 
286
- <span class="no">PlayRockPaperScissorsGame</span><span class="p">.</span><span class="nf">new</span><span class="p">.</span><span class="nf">play</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
307
+ <span class="no">PlayRockPaperScissorsGame</span><span class="p">.</span><span class="nf">new</span><span class="p">.</span><span class="nf">play</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="c1"># call the play method and pass in 3 (0, 1, 2) for the winning score</span>
287
308
  </code></pre>
288
309
  </div>
289
310
 
@@ -7,7 +7,7 @@
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
8
8
  <meta name="theme-color" content="#157878"/>
9
9
  <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css' />
10
- <link rel="stylesheet" href="/assets/css/style.css?v=bf6ec5a78a162d5292114fcb1a031ba03f4b561e"/>
10
+ <link rel="stylesheet" href="/assets/css/style.css?v=9dfdf3a7dbe502b5dba0b21bd04c4f6cd97868ee"/>
11
11
  <script src="assets/js/pace.min.js"></script>
12
12
 
13
13
  <link rel="apple-touch-icon" sizes="180x180" href="assets/favicons/apple-touch-icon.png"/>
@@ -7,7 +7,7 @@
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
8
8
  <meta name="theme-color" content="#157878"/>
9
9
  <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css' />
10
- <link rel="stylesheet" href="/assets/css/style.css?v=bf6ec5a78a162d5292114fcb1a031ba03f4b561e"/>
10
+ <link rel="stylesheet" href="/assets/css/style.css?v=9dfdf3a7dbe502b5dba0b21bd04c4f6cd97868ee"/>
11
11
  <script src="assets/js/pace.min.js"></script>
12
12
 
13
13
  <link rel="apple-touch-icon" sizes="180x180" href="assets/favicons/apple-touch-icon.png"/>
@@ -7,7 +7,7 @@
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
8
8
  <meta name="theme-color" content="#157878"/>
9
9
  <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css' />
10
- <link rel="stylesheet" href="/assets/css/style.css?v=bf6ec5a78a162d5292114fcb1a031ba03f4b561e"/>
10
+ <link rel="stylesheet" href="/assets/css/style.css?v=9dfdf3a7dbe502b5dba0b21bd04c4f6cd97868ee"/>
11
11
  <script src="assets/js/pace.min.js"></script>
12
12
 
13
13
  <link rel="apple-touch-icon" sizes="180x180" href="assets/favicons/apple-touch-icon.png"/>
@@ -7,7 +7,7 @@
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
8
8
  <meta name="theme-color" content="#157878"/>
9
9
  <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css' />
10
- <link rel="stylesheet" href="/assets/css/style.css?v=bf6ec5a78a162d5292114fcb1a031ba03f4b561e"/>
10
+ <link rel="stylesheet" href="/assets/css/style.css?v=9dfdf3a7dbe502b5dba0b21bd04c4f6cd97868ee"/>
11
11
  <script src="assets/js/pace.min.js"></script>
12
12
 
13
13
  <link rel="apple-touch-icon" sizes="180x180" href="assets/favicons/apple-touch-icon.png"/>
@@ -5,7 +5,7 @@ module PrivateMethods
5
5
  class << self
6
6
  def player_choice
7
7
  loop do
8
- print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green)
8
+ print ColorizedString["Choose: Rock (r), Paper (p), or Scissors (s): "].colorize(:green)
9
9
  choice = gets.chomp.downcase
10
10
  if Constants::NTRY_TO_SYM.key?(choice)
11
11
  return Constants::NTRY_TO_SYM[choice]
data/lib/rps/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RockPaperScissors
2
- VERSION = "2.8.7"
2
+ VERSION = "2.8.8"
3
3
  end
data/rps.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "PlayRockPaperScissorsGame"
3
- spec.version = "2.8.7"
4
- spec.date = "2017-08-29"
3
+ spec.version = "2.8.8"
4
+ spec.date = "2017-08-31"
5
5
  spec.summary = "A Rock Paper Scissors Ruby Gem"
6
6
  spec.description = <<-EOF
7
7
  A Ruby-programmed rock paper scissors game.
data/test/test_rps.rb CHANGED
@@ -32,25 +32,25 @@ class RakeTest # create test
32
32
  def testPlay(winning_score)
33
33
  while @player_score < winning_score && @computer_score < winning_score
34
34
  puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
35
- ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}"].colorize(:blue)
35
+ ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}."].colorize(:blue)
36
36
  player = PrivateMethods.player_choice
37
37
  computer = Constants::COMPUTER_CHOICES.sample
38
- puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}"].colorize(:blue)
39
- puts ColorizedString["Computer chooses #{computer.to_s.downcase}"].colorize(:blue)
38
+ puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}."].colorize(:blue)
39
+ puts ColorizedString["Computer chooses #{computer.to_s.downcase}."].colorize(:blue)
40
40
  case PrivateMethods.player_outcome [player, computer]
41
41
  when :WIN
42
- puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"].colorize(:red)
42
+ puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round."].colorize(:red)
43
43
  @player_score += 1
44
44
  when :LOSE
45
- puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round"].colorize(:red)
45
+ puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round."].colorize(:red)
46
46
  @computer_score += 1
47
47
  else
48
- puts ColorizedString["Tie, choose again"].colorize(:red)
48
+ puts ColorizedString["Tie, choose again."].colorize(:red)
49
49
  @ties += 1
50
50
  end
51
51
  end
52
52
  puts ColorizedString["\nFinal score: player: #{@player_score}, "].colorize(:blue) +
53
- ColorizedString["computer: #{@computer_score} (ties: #{@ties})"].colorize(:blue)
53
+ ColorizedString["computer: #{@computer_score} (ties: #{@ties})."].colorize(:blue)
54
54
  case PrivateMethods.final_outcome(@player_score, @computer_score)
55
55
  when :WIN
56
56
  puts ColorizedString["Player wins!"].colorize(:red)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: PlayRockPaperScissorsGame
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.7
4
+ version: 2.8.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - bag3318
@@ -30,7 +30,7 @@ cert_chain:
30
30
  ft+uhriUZSVDBJRLSlrQEH2f0866a9dA4oUmvvFU46Mh6pozDjOcLJIp/tCnbVOc
31
31
  HSdXPrjfOoDbhBPH/4wUd5P0rDoNKN1hxH4SzA==
32
32
  -----END CERTIFICATE-----
33
- date: 2017-08-29 00:00:00.000000000 Z
33
+ date: 2017-08-31 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: bundler
metadata.gz.sig CHANGED
Binary file