RPSrb 0.0.9 → 0.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/LICENSE +21 -0
- data/RPSrb.gemspec +1 -1
- data/doc/RPSrb.html +3 -1
- data/doc/RockPaperScissors.html +158 -56
- data/doc/created.rid +4 -4
- data/doc/js/navigation.js.gz +0 -0
- data/doc/js/search_index.js +1 -1
- data/doc/js/search_index.js.gz +0 -0
- data/doc/js/searcher.js.gz +0 -0
- data/doc/table_of_contents.html +16 -2
- data/lib/RPSrb/Version.rb +3 -2
- data/lib/RockPaperScissors.rb +31 -17
- data/lib/exec.rb +3 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39d2226eb32ff55c9438d638e79d9ea7b2bdbefb
|
4
|
+
data.tar.gz: c79ebafce73b8392bee88f5a575dae425974dd49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bf2c049a6c5807cc71590b66b81936ac7b7b0a924f7789ee38431e4d325c80d015409dc38f45444820ee0dce2a65891b66f83817d0ba33893249340cf0972db
|
7
|
+
data.tar.gz: c809efedf8946449520b6d54bf8e447fd81aa594c7c4cffabc15066675e047b7f5f9f72fd4d211068cb9bde735e91dc618ef24055a1b8b2096f6124bc386e4a6
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 bag3318
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/RPSrb.gemspec
CHANGED
data/doc/RPSrb.html
CHANGED
@@ -69,7 +69,9 @@
|
|
69
69
|
|
70
70
|
<section class="description">
|
71
71
|
|
72
|
-
<
|
72
|
+
<h1 id="module-RPSrb-label-RubyGems+version+constant">RubyGems version constant<span><a href="#module-RPSrb-label-RubyGems+version+constant">¶</a> <a href="#top">↑</a></span></h1>
|
73
|
+
|
74
|
+
<p>this is required for all rubygem packages</p>
|
73
75
|
|
74
76
|
</section>
|
75
77
|
|
data/doc/RockPaperScissors.html
CHANGED
@@ -71,12 +71,16 @@
|
|
71
71
|
|
72
72
|
<ul class="link-list" role="directory">
|
73
73
|
|
74
|
-
<li ><a href="#method-c-continue">::continue</a>
|
75
|
-
|
76
74
|
<li ><a href="#method-c-new">::new</a>
|
77
75
|
|
76
|
+
<li ><a href="#method-i-final_outcome">#final_outcome</a>
|
77
|
+
|
78
78
|
<li ><a href="#method-i-play">#play</a>
|
79
79
|
|
80
|
+
<li ><a href="#method-i-player_choice">#player_choice</a>
|
81
|
+
|
82
|
+
<li ><a href="#method-i-player_outcome">#player_outcome</a>
|
83
|
+
|
80
84
|
</ul>
|
81
85
|
</div>
|
82
86
|
|
@@ -109,32 +113,44 @@
|
|
109
113
|
|
110
114
|
<dt id="CHOICES">CHOICES
|
111
115
|
|
112
|
-
<dd><
|
116
|
+
<dd><h2 id="label-Make+choices+constant+-282d+list-29">Make choices constant (2d list)<span><a href="#label-Make+choices+constant+-282d+list-29">¶</a> <a href="#top">↑</a></span></h2>
|
117
|
+
|
118
|
+
<p>this 2d array contains all the options (in string format) the user can use</p>
|
113
119
|
|
114
120
|
|
115
121
|
<dt id="COMPUTER_CHOICES">COMPUTER_CHOICES
|
116
122
|
|
117
|
-
<dd><
|
123
|
+
<dd><h2 id="label-Define+possible+computer+choices">Define possible computer choices<span><a href="#label-Define+possible+computer+choices">¶</a> <a href="#top">↑</a></span></h2>
|
124
|
+
|
125
|
+
<p>grab the values of the hash</p>
|
118
126
|
|
119
127
|
|
120
128
|
<dt id="LOSERS">LOSERS
|
121
129
|
|
122
|
-
<dd><
|
130
|
+
<dd><h2 id="label-Map+array+for+losers">Map array for losers<span><a href="#label-Map+array+for+losers">¶</a> <a href="#top">↑</a></span></h2>
|
131
|
+
|
132
|
+
<p>this flips the items in the `WINNERS` 2d array</p>
|
123
133
|
|
124
134
|
|
125
135
|
<dt id="NTRY_TO_SYM">NTRY_TO_SYM
|
126
136
|
|
127
|
-
<dd><
|
137
|
+
<dd><h2 id="label-Define+an+entry+to+symbol+hash">Define an entry to symbol hash<span><a href="#label-Define+an+entry+to+symbol+hash">¶</a> <a href="#top">↑</a></span></h2>
|
138
|
+
|
139
|
+
<p>this is a “hash” that contains the keys and values for winning and losing</p>
|
128
140
|
|
129
141
|
|
130
142
|
<dt id="VALID_ENTRIES">VALID_ENTRIES
|
131
143
|
|
132
|
-
<dd><
|
144
|
+
<dd><h3 id="label-Define+what+our+valid+entries+out">Define what our valid entries out<span><a href="#label-Define+what+our+valid+entries+out">¶</a> <a href="#top">↑</a></span></h3>
|
145
|
+
|
146
|
+
<p>grab the keys of the hash</p>
|
133
147
|
|
134
148
|
|
135
149
|
<dt id="WINNERS">WINNERS
|
136
150
|
|
137
|
-
<dd><
|
151
|
+
<dd><h2 id="label-Define+winners+2d+array">Define winners 2d array<span><a href="#label-Define+winners+2d+array">¶</a> <a href="#top">↑</a></span></h2>
|
152
|
+
|
153
|
+
<p>defines winners in 2d array/list format</p>
|
138
154
|
|
139
155
|
|
140
156
|
</dl>
|
@@ -163,13 +179,13 @@
|
|
163
179
|
|
164
180
|
<div class="method-description">
|
165
181
|
|
166
|
-
<
|
182
|
+
<h2 id="method-c-new-label-Define+constructor+for+class">Define constructor for class<span><a href="#method-c-new-label-Define+constructor+for+class">¶</a> <a href="#top">↑</a></span></h2>
|
167
183
|
|
168
184
|
|
169
185
|
|
170
186
|
|
171
187
|
<div class="method-source-code" id="new-source">
|
172
|
-
<pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line
|
188
|
+
<pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 53</span>
|
173
189
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>
|
174
190
|
<span class="ruby-ivar">@player_score</span> = <span class="ruby-ivar">@computer_score</span> = <span class="ruby-ivar">@ties</span> = <span class="ruby-value">0</span>
|
175
191
|
<span class="ruby-keyword">end</span></pre>
|
@@ -180,50 +196,6 @@
|
|
180
196
|
|
181
197
|
|
182
198
|
|
183
|
-
</div>
|
184
|
-
|
185
|
-
|
186
|
-
</section>
|
187
|
-
|
188
|
-
<section id="protected-class-5Buntitled-5D-method-details" class="method-section">
|
189
|
-
<header>
|
190
|
-
<h3>Protected Class Methods</h3>
|
191
|
-
</header>
|
192
|
-
|
193
|
-
|
194
|
-
<div id="method-c-continue" class="method-detail ">
|
195
|
-
|
196
|
-
<div class="method-heading">
|
197
|
-
<span class="method-name">continue</span><span
|
198
|
-
class="method-args">(str1,str2,str3)</span>
|
199
|
-
|
200
|
-
<span class="method-click-advice">click to toggle source</span>
|
201
|
-
|
202
|
-
</div>
|
203
|
-
|
204
|
-
|
205
|
-
<div class="method-description">
|
206
|
-
|
207
|
-
<p>define entry point for game</p>
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
<div class="method-source-code" id="continue-source">
|
213
|
-
<pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 35</span>
|
214
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">continue</span>(<span class="ruby-identifier">str1</span>,<span class="ruby-identifier">str2</span>,<span class="ruby-identifier">str3</span>)
|
215
|
-
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">str1</span>
|
216
|
-
<span class="ruby-identifier">print</span> <span class="ruby-identifier">str2</span>
|
217
|
-
<span class="ruby-identifier">gets</span>
|
218
|
-
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">str3</span>
|
219
|
-
<span class="ruby-keyword">end</span></pre>
|
220
|
-
</div>
|
221
|
-
|
222
|
-
</div>
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
199
|
</div>
|
228
200
|
|
229
201
|
|
@@ -248,13 +220,16 @@
|
|
248
220
|
|
249
221
|
<div class="method-description">
|
250
222
|
|
251
|
-
<
|
223
|
+
<h2 id="method-i-play-label-Define+play+game+method">Define play game method<span><a href="#method-i-play-label-Define+play+game+method">¶</a> <a href="#top">↑</a></span></h2>
|
224
|
+
|
225
|
+
<p>this method will be public it will also constain most of the “play”
|
226
|
+
functioonality for this game</p>
|
252
227
|
|
253
228
|
|
254
229
|
|
255
230
|
|
256
231
|
<div class="method-source-code" id="play-source">
|
257
|
-
<pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line
|
232
|
+
<pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 61</span>
|
258
233
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">play</span>(<span class="ruby-identifier">winning_score</span>)
|
259
234
|
<span class="ruby-keyword">while</span> <span class="ruby-ivar">@player_score</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">winning_score</span> <span class="ruby-operator">&&</span> <span class="ruby-ivar">@computer_score</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">winning_score</span>
|
260
235
|
<span class="ruby-identifier">puts</span> <span class="ruby-node">"\nPlayer score: #{@player_score}, "</span> <span class="ruby-operator">+</span>
|
@@ -293,6 +268,133 @@
|
|
293
268
|
|
294
269
|
|
295
270
|
|
271
|
+
</div>
|
272
|
+
|
273
|
+
|
274
|
+
</section>
|
275
|
+
|
276
|
+
<section id="protected-instance-5Buntitled-5D-method-details" class="method-section">
|
277
|
+
<header>
|
278
|
+
<h3>Protected Instance Methods</h3>
|
279
|
+
</header>
|
280
|
+
|
281
|
+
|
282
|
+
<div id="method-i-final_outcome" class="method-detail ">
|
283
|
+
|
284
|
+
<div class="method-heading">
|
285
|
+
<span class="method-name">final_outcome</span><span
|
286
|
+
class="method-args">(pl, co)</span>
|
287
|
+
|
288
|
+
<span class="method-click-advice">click to toggle source</span>
|
289
|
+
|
290
|
+
</div>
|
291
|
+
|
292
|
+
|
293
|
+
<div class="method-description">
|
294
|
+
|
295
|
+
<h2 id="method-i-final_outcome-label-Define+final+outcome+function">Define final outcome function<span><a href="#method-i-final_outcome-label-Define+final+outcome+function">¶</a> <a href="#top">↑</a></span></h2>
|
296
|
+
|
297
|
+
<p>this method is protected this will determine who wins the whole match in
|
298
|
+
the end</p>
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
<div class="method-source-code" id="final_outcome-source">
|
304
|
+
<pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 125</span>
|
305
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">final_outcome</span>(<span class="ruby-identifier">pl</span>, <span class="ruby-identifier">co</span>)
|
306
|
+
<span class="ruby-keyword">return</span> <span class="ruby-value">:WIN</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">pl</span> <span class="ruby-operator">></span> <span class="ruby-identifier">co</span>
|
307
|
+
<span class="ruby-keyword">return</span> <span class="ruby-value">:LOSE</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">pl</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">co</span>
|
308
|
+
<span class="ruby-keyword">end</span></pre>
|
309
|
+
</div>
|
310
|
+
|
311
|
+
</div>
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
</div>
|
317
|
+
|
318
|
+
|
319
|
+
<div id="method-i-player_choice" class="method-detail ">
|
320
|
+
|
321
|
+
<div class="method-heading">
|
322
|
+
<span class="method-name">player_choice</span><span
|
323
|
+
class="method-args">()</span>
|
324
|
+
|
325
|
+
<span class="method-click-advice">click to toggle source</span>
|
326
|
+
|
327
|
+
</div>
|
328
|
+
|
329
|
+
|
330
|
+
<div class="method-description">
|
331
|
+
|
332
|
+
<h2 id="method-i-player_choice-label-Make+player+choice+method">Make player choice method<span><a href="#method-i-player_choice-label-Make+player+choice+method">¶</a> <a href="#top">↑</a></span></h2>
|
333
|
+
|
334
|
+
<p>this method will be protected this will sanity check the user's choice</p>
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
<div class="method-source-code" id="player_choice-source">
|
340
|
+
<pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 97</span>
|
341
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">player_choice</span>
|
342
|
+
<span class="ruby-identifier">loop</span> <span class="ruby-keyword">do</span>
|
343
|
+
<span class="ruby-identifier">print</span> <span class="ruby-string">"\nChoose: Rock (r), Paper (p), or Scissors (s): "</span>
|
344
|
+
<span class="ruby-identifier">choice</span> = <span class="ruby-identifier">gets</span>.<span class="ruby-identifier">chomp</span>.<span class="ruby-identifier">downcase</span>
|
345
|
+
<span class="ruby-keyword">if</span> <span class="ruby-constant">NTRY_TO_SYM</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">choice</span>)
|
346
|
+
<span class="ruby-keyword">return</span> <span class="ruby-constant">NTRY_TO_SYM</span>[<span class="ruby-identifier">choice</span>]
|
347
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">choice</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">VALID_ENTRIES</span>
|
348
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-string">"\nThat entry is invalid. Please re-enter.\n"</span>
|
349
|
+
<span class="ruby-keyword">else</span>
|
350
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
|
351
|
+
<span class="ruby-keyword">end</span>
|
352
|
+
<span class="ruby-keyword">end</span>
|
353
|
+
<span class="ruby-keyword">end</span></pre>
|
354
|
+
</div>
|
355
|
+
|
356
|
+
</div>
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
</div>
|
362
|
+
|
363
|
+
|
364
|
+
<div id="method-i-player_outcome" class="method-detail ">
|
365
|
+
|
366
|
+
<div class="method-heading">
|
367
|
+
<span class="method-name">player_outcome</span><span
|
368
|
+
class="method-args">(plays)</span>
|
369
|
+
|
370
|
+
<span class="method-click-advice">click to toggle source</span>
|
371
|
+
|
372
|
+
</div>
|
373
|
+
|
374
|
+
|
375
|
+
<div class="method-description">
|
376
|
+
|
377
|
+
<h2 id="method-i-player_outcome-label-Define+player+outcome">Define player outcome<span><a href="#method-i-player_outcome-label-Define+player+outcome">¶</a> <a href="#top">↑</a></span></h2>
|
378
|
+
|
379
|
+
<p>this method is protected this defines the round outcome of the game</p>
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
<div class="method-source-code" id="player_outcome-source">
|
385
|
+
<pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 115</span>
|
386
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">player_outcome</span>(<span class="ruby-identifier">plays</span>)
|
387
|
+
<span class="ruby-keyword">return</span> <span class="ruby-value">:WIN</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">WINNERS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">plays</span>)
|
388
|
+
<span class="ruby-keyword">return</span> <span class="ruby-value">:LOSE</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">LOSERS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">plays</span>)
|
389
|
+
<span class="ruby-keyword">return</span> <span class="ruby-value">:TIE</span> <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-value">:WIN</span> <span class="ruby-operator">|</span> <span class="ruby-operator">!</span><span class="ruby-value">:LOSE</span>
|
390
|
+
<span class="ruby-keyword">end</span></pre>
|
391
|
+
</div>
|
392
|
+
|
393
|
+
</div>
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
|
296
398
|
</div>
|
297
399
|
|
298
400
|
|
data/doc/created.rid
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Tue, 12 Dec 2017
|
2
|
-
lib/exec.rb
|
3
|
-
lib/RockPaperScissors.rb Tue, 12 Dec 2017
|
4
|
-
lib/RPSrb/Version.rb Tue, 12 Dec 2017 09:
|
1
|
+
Tue, 12 Dec 2017 10:03:36 -0800
|
2
|
+
lib/exec.rb Tue, 12 Dec 2017 09:59:08 -0800
|
3
|
+
lib/RockPaperScissors.rb Tue, 12 Dec 2017 10:03:25 -0800
|
4
|
+
lib/RPSrb/Version.rb Tue, 12 Dec 2017 09:53:54 -0800
|
data/doc/js/navigation.js.gz
CHANGED
Binary file
|
data/doc/js/search_index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var search_data = {"index":{"searchIndex":["rpsrb","rockpaperscissors","
|
1
|
+
var search_data = {"index":{"searchIndex":["rpsrb","rockpaperscissors","final_outcome()","new()","play()","player_choice()","player_outcome()"],"longSearchIndex":["rpsrb","rockpaperscissors","rockpaperscissors#final_outcome()","rockpaperscissors::new()","rockpaperscissors#play()","rockpaperscissors#player_choice()","rockpaperscissors#player_outcome()"],"info":[["RPSrb","","RPSrb.html","","<p>RubyGems version constant\n<p>this is required for all rubygem packages\n"],["RockPaperScissors","","RockPaperScissors.html","",""],["final_outcome","RockPaperScissors","RockPaperScissors.html#method-i-final_outcome","(pl, co)","<p>Define final outcome function\n<p>this method is protected this will determine who wins the whole match in …\n"],["new","RockPaperScissors","RockPaperScissors.html#method-c-new","()","<p>Define constructor for class\n"],["play","RockPaperScissors","RockPaperScissors.html#method-i-play","(winning_score)","<p>Define play game method\n<p>this method will be public it will also constain most of the “play” …\n"],["player_choice","RockPaperScissors","RockPaperScissors.html#method-i-player_choice","()","<p>Make player choice method\n<p>this method will be protected this will sanity check the user's choice\n"],["player_outcome","RockPaperScissors","RockPaperScissors.html#method-i-player_outcome","(plays)","<p>Define player outcome\n<p>this method is protected this defines the round outcome of the game\n"]]}}
|
data/doc/js/search_index.js.gz
CHANGED
Binary file
|
data/doc/js/searcher.js.gz
CHANGED
Binary file
|
data/doc/table_of_contents.html
CHANGED
@@ -28,6 +28,10 @@
|
|
28
28
|
<ul>
|
29
29
|
<li class="module">
|
30
30
|
<a href="RPSrb.html">RPSrb</a>
|
31
|
+
|
32
|
+
<ul>
|
33
|
+
<li><a href="RPSrb.html#label-RubyGems+version+constant">RubyGems version constant</a>
|
34
|
+
</ul>
|
31
35
|
</li>
|
32
36
|
<li class="class">
|
33
37
|
<a href="RockPaperScissors.html">RockPaperScissors</a>
|
@@ -38,12 +42,12 @@
|
|
38
42
|
<ul>
|
39
43
|
|
40
44
|
<li class="method">
|
41
|
-
<a href="RockPaperScissors.html#method-c-
|
45
|
+
<a href="RockPaperScissors.html#method-c-new">::new</a>
|
42
46
|
—
|
43
47
|
<span class="container">RockPaperScissors</span>
|
44
48
|
|
45
49
|
<li class="method">
|
46
|
-
<a href="RockPaperScissors.html#method-
|
50
|
+
<a href="RockPaperScissors.html#method-i-final_outcome">#final_outcome</a>
|
47
51
|
—
|
48
52
|
<span class="container">RockPaperScissors</span>
|
49
53
|
|
@@ -51,6 +55,16 @@
|
|
51
55
|
<a href="RockPaperScissors.html#method-i-play">#play</a>
|
52
56
|
—
|
53
57
|
<span class="container">RockPaperScissors</span>
|
58
|
+
|
59
|
+
<li class="method">
|
60
|
+
<a href="RockPaperScissors.html#method-i-player_choice">#player_choice</a>
|
61
|
+
—
|
62
|
+
<span class="container">RockPaperScissors</span>
|
63
|
+
|
64
|
+
<li class="method">
|
65
|
+
<a href="RockPaperScissors.html#method-i-player_outcome">#player_outcome</a>
|
66
|
+
—
|
67
|
+
<span class="container">RockPaperScissors</span>
|
54
68
|
</ul>
|
55
69
|
</main>
|
56
70
|
|
data/lib/RPSrb/Version.rb
CHANGED
data/lib/RockPaperScissors.rb
CHANGED
@@ -2,36 +2,43 @@ class RockPaperScissors
|
|
2
2
|
|
3
3
|
require_relative 'RPSrb/Version.rb'
|
4
4
|
|
5
|
-
#
|
5
|
+
# == Make choices constant (2d list)
|
6
|
+
# this 2d array contains all the options (in string format) the user can use
|
6
7
|
CHOICES = [['r', 'rock'], ['p', 'paper'], ['s', 'scissors']]
|
7
8
|
|
8
9
|
|
9
|
-
#
|
10
|
+
# == Define an entry to symbol hash
|
11
|
+
# this is a "hash" that contains the keys and values for winning and losing
|
10
12
|
NTRY_TO_SYM = {
|
11
13
|
CHOICES[0][0] => :ROCK , CHOICES[0][1] => :ROCK ,
|
12
14
|
CHOICES[1][0] => :PAPER , CHOICES[1][1] => :PAPER ,
|
13
15
|
CHOICES[2][0] => :SCISSORS, CHOICES[2][1] => :SCISSORS
|
14
16
|
}
|
15
17
|
|
16
|
-
#
|
18
|
+
# === Define what our valid entries out
|
19
|
+
# grab the keys of the hash
|
17
20
|
VALID_ENTRIES = NTRY_TO_SYM.keys
|
18
21
|
|
19
|
-
#
|
22
|
+
# == Define possible computer choices
|
23
|
+
# grab the values of the hash
|
20
24
|
COMPUTER_CHOICES = NTRY_TO_SYM.values
|
21
25
|
|
22
|
-
#
|
26
|
+
# == Define winners 2d array
|
27
|
+
# defines winners in 2d array/list format
|
23
28
|
WINNERS = [
|
24
29
|
[:SCISSORS, :PAPER ],
|
25
30
|
[:PAPER , :ROCK ],
|
26
31
|
[:ROCK , :SCISSORS]
|
27
32
|
]
|
28
33
|
|
29
|
-
#
|
34
|
+
# == Map array for losers
|
35
|
+
# this flips the items in the `WINNERS` 2d array
|
30
36
|
LOSERS = WINNERS.map { |winning_choice,losing_choice| [losing_choice,winning_choice] }
|
31
37
|
|
32
38
|
class << self
|
33
|
-
#
|
34
|
-
|
39
|
+
# == Define entry point for game
|
40
|
+
# this function is private
|
41
|
+
private
|
35
42
|
def continue(str1,str2,str3)
|
36
43
|
puts str1
|
37
44
|
print str2
|
@@ -42,13 +49,14 @@ class RockPaperScissors
|
|
42
49
|
|
43
50
|
continue("\nYou are about to enter a rock-paper-scissors best of 3 match.", "\nPress the return/enter key to continue...", "")
|
44
51
|
|
45
|
-
#
|
46
|
-
protected
|
52
|
+
# == Define constructor for class
|
47
53
|
def initialize
|
48
54
|
@player_score = @computer_score = @ties = 0
|
49
55
|
end
|
50
56
|
|
51
|
-
#
|
57
|
+
# == Define play game method
|
58
|
+
# this method will be public
|
59
|
+
# it will also constain most of the "play" functioonality for this game
|
52
60
|
public
|
53
61
|
def play(winning_score)
|
54
62
|
while @player_score < winning_score && @computer_score < winning_score
|
@@ -82,8 +90,10 @@ class RockPaperScissors
|
|
82
90
|
puts
|
83
91
|
end
|
84
92
|
|
85
|
-
#
|
86
|
-
|
93
|
+
# == Make player choice method
|
94
|
+
# this method will be protected
|
95
|
+
# this will sanity check the user's choice
|
96
|
+
protected
|
87
97
|
def player_choice
|
88
98
|
loop do
|
89
99
|
print "\nChoose: Rock (r), Paper (p), or Scissors (s): "
|
@@ -98,16 +108,20 @@ class RockPaperScissors
|
|
98
108
|
end
|
99
109
|
end
|
100
110
|
|
101
|
-
#
|
102
|
-
|
111
|
+
# == Define player outcome
|
112
|
+
# this method is protected
|
113
|
+
# this defines the round outcome of the game
|
114
|
+
protected
|
103
115
|
def player_outcome(plays)
|
104
116
|
return :WIN if WINNERS.include?(plays)
|
105
117
|
return :LOSE if LOSERS.include?(plays)
|
106
118
|
return :TIE if !:WIN | !:LOSE
|
107
119
|
end
|
108
120
|
|
109
|
-
#
|
110
|
-
|
121
|
+
# == Define final outcome function
|
122
|
+
# this method is protected
|
123
|
+
# this will determine who wins the whole match in the end
|
124
|
+
protected
|
111
125
|
def final_outcome(pl, co)
|
112
126
|
return :WIN if pl > co
|
113
127
|
return :LOSE if pl < co
|
data/lib/exec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RPSrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bag3318
|
@@ -102,6 +102,7 @@ extra_rdoc_files:
|
|
102
102
|
files:
|
103
103
|
- ".gitignore"
|
104
104
|
- Gemfile
|
105
|
+
- LICENSE
|
105
106
|
- README.md
|
106
107
|
- RPSrb.gemspec
|
107
108
|
- Rakefile
|