rpsg 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/PrivateMethods.html +11 -11
- data/doc/{Constants.html → ProtectedConstants.html} +8 -7
- data/doc/RockPaperScissorsGame.html +23 -23
- data/doc/created.rid +5 -5
- data/doc/index.html +2 -2
- 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 +2 -2
- data/docs/_pages/code.txt +64 -64
- data/docs/_site/bundler.html +1 -1
- data/docs/_site/code.html +64 -64
- data/docs/_site/index.html +1 -1
- data/docs/_site/install.html +1 -1
- data/docs/_site/readme.html +1 -1
- data/docs/_site/simple.html +1 -1
- data/docs/_site/test.html +1 -1
- data/docs/_site/uninstall.html +1 -1
- data/docs/_site/update.html +1 -1
- data/lib/Constants.rb +18 -18
- data/lib/Main.rb +30 -30
- data/lib/PrivateMethods.rb +15 -15
- data/lib/rpsg/version.rb +2 -2
- data/rpsg.gemspec +7 -7
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69f4c5cd3f3b69775a37793c9bdbddaf8ef5ba21
|
4
|
+
data.tar.gz: a89996a251d71265cd562a696e36d23993a1ff4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02af8650b0b3442fcbb0fa356a1194882a71c0ad1f4d7cb5d21bdb528ef8fea54d57258ba100b1d8b31618f3b9d35c7b307d01e29856aec9509b7e585c27561e
|
7
|
+
data.tar.gz: 2fdee5de43c29cffc204398ca8d751193a7c8ab3fa792c23b2c41a2f4c1b967e19f04ca9128952d8bfce11bd24cc6f58ee448796c6fd53548c988dc883952b88
|
data/doc/PrivateMethods.html
CHANGED
@@ -110,7 +110,7 @@
|
|
110
110
|
|
111
111
|
<div class="method-heading">
|
112
112
|
<span class="method-name">final_outcome</span><span
|
113
|
-
class="method-args">(pl,co)</span>
|
113
|
+
class="method-args">(pl, co)</span>
|
114
114
|
|
115
115
|
<span class="method-click-advice">click to toggle source</span>
|
116
116
|
|
@@ -126,11 +126,11 @@
|
|
126
126
|
|
127
127
|
<div class="method-source-code" id="final_outcome-source">
|
128
128
|
<pre><span class="ruby-comment"># File lib/PrivateMethods.rb, line 26</span>
|
129
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">final_outcome</span>(<span class="ruby-identifier">pl</span
|
130
|
-
<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>
|
129
|
+
<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>)
|
130
|
+
<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>
|
131
131
|
<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>
|
132
|
-
<span class="ruby-
|
133
|
-
<span class="ruby-comment"># there will never be a tie for the final outcome due to the code in the play() method</span>
|
132
|
+
<span class="ruby-comment"># return :TIE if pl = co</span>
|
133
|
+
<span class="ruby-comment"># there will never be a tie for the final outcome due to the code in the `play()` method</span>
|
134
134
|
<span class="ruby-keyword">end</span></pre>
|
135
135
|
</div>
|
136
136
|
|
@@ -166,14 +166,14 @@
|
|
166
166
|
<span class="ruby-identifier">loop</span> <span class="ruby-keyword">do</span>
|
167
167
|
<span class="ruby-identifier">print</span> <span class="ruby-string">"\nChoose: Rock (r), Paper (p), or Scissors (s): "</span>
|
168
168
|
<span class="ruby-identifier">choice</span> = <span class="ruby-identifier">gets</span>.<span class="ruby-identifier">chomp</span>.<span class="ruby-identifier">downcase</span>
|
169
|
-
<span class="ruby-keyword">if</span> <span class="ruby-constant">
|
170
|
-
<span class="ruby-keyword">return</span> <span class="ruby-constant">
|
171
|
-
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">choice</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">
|
169
|
+
<span class="ruby-keyword">if</span> <span class="ruby-constant">ProtectedConstants</span><span class="ruby-operator">::</span><span class="ruby-constant">NTRY_TO_SYM</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">choice</span>)
|
170
|
+
<span class="ruby-keyword">return</span> <span class="ruby-constant">ProtectedConstants</span><span class="ruby-operator">::</span><span class="ruby-constant">NTRY_TO_SYM</span>[<span class="ruby-identifier">choice</span>]
|
171
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">choice</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">ProtectedConstants</span><span class="ruby-operator">::</span><span class="ruby-constant">VALID_ENTRIES</span>
|
172
172
|
<span class="ruby-identifier">puts</span> <span class="ruby-string">"\nThat entry is invalid. Please re-enter.\n"</span>
|
173
173
|
<span class="ruby-keyword">else</span>
|
174
174
|
<span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
|
175
175
|
<span class="ruby-keyword">end</span>
|
176
|
-
<span class="ruby-keyword">end</span>
|
176
|
+
<span class="ruby-keyword">end</span>
|
177
177
|
<span class="ruby-keyword">end</span></pre>
|
178
178
|
</div>
|
179
179
|
|
@@ -206,8 +206,8 @@
|
|
206
206
|
<div class="method-source-code" id="player_outcome-source">
|
207
207
|
<pre><span class="ruby-comment"># File lib/PrivateMethods.rb, line 20</span>
|
208
208
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">player_outcome</span>(<span class="ruby-identifier">plays</span>)
|
209
|
-
<span class="ruby-keyword">return</span> <span class="ruby-value">:WIN</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">
|
210
|
-
<span class="ruby-keyword">return</span> <span class="ruby-value">:LOSE</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">
|
209
|
+
<span class="ruby-keyword">return</span> <span class="ruby-value">:WIN</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">ProtectedConstants</span><span class="ruby-operator">::</span><span class="ruby-constant">WINNERS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">plays</span>)
|
210
|
+
<span class="ruby-keyword">return</span> <span class="ruby-value">:LOSE</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">ProtectedConstants</span><span class="ruby-operator">::</span><span class="ruby-constant">LOSERS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">plays</span>)
|
211
211
|
<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>
|
212
212
|
<span class="ruby-keyword">end</span></pre>
|
213
213
|
</div>
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<head>
|
5
5
|
<meta charset="UTF-8">
|
6
6
|
|
7
|
-
<title>module
|
7
|
+
<title>module ProtectedConstants - RPSG RDocs</title>
|
8
8
|
|
9
9
|
<script type="text/javascript">
|
10
10
|
var rdoc_rel_prefix = "./";
|
@@ -62,9 +62,9 @@
|
|
62
62
|
</div>
|
63
63
|
</nav>
|
64
64
|
|
65
|
-
<main role="main" aria-labelledby="module-
|
66
|
-
<h1 id="module-
|
67
|
-
module
|
65
|
+
<main role="main" aria-labelledby="module-ProtectedConstants">
|
66
|
+
<h1 id="module-ProtectedConstants" class="module">
|
67
|
+
module ProtectedConstants
|
68
68
|
</h1>
|
69
69
|
|
70
70
|
<section class="description">
|
@@ -100,13 +100,14 @@
|
|
100
100
|
|
101
101
|
<dt id="LOSERS">LOSERS
|
102
102
|
|
103
|
-
<dd><p>this will take the original <a
|
104
|
-
array and flip the
|
103
|
+
<dd><p>this will take the original <a
|
104
|
+
href="ProtectedConstants.html#WINNERS">WINNERS</a> array and flip the
|
105
|
+
symbols, thus returning a loss for the user/player</p>
|
105
106
|
|
106
107
|
|
107
108
|
<dt id="NTRY_TO_SYM">NTRY_TO_SYM
|
108
109
|
|
109
|
-
<dd><p>define entry to symbol (key to value)</p>
|
110
|
+
<dd><p>define entry to symbol (key to value) dictionary</p>
|
110
111
|
|
111
112
|
|
112
113
|
<dt id="VALID_ENTRIES">VALID_ENTRIES
|
@@ -135,9 +135,9 @@ scissors</p>
|
|
135
135
|
<div class="method-source-code" id="continue-source">
|
136
136
|
<pre><span class="ruby-comment"># File lib/Main.rb, line 12</span>
|
137
137
|
<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>)
|
138
|
-
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">str1</span>
|
138
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">str1</span>
|
139
139
|
<span class="ruby-identifier">print</span> <span class="ruby-identifier">str2</span>
|
140
|
-
<span class="ruby-identifier">gets</span>
|
140
|
+
<span class="ruby-identifier">gets</span>
|
141
141
|
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">str3</span>
|
142
142
|
<span class="ruby-keyword">end</span></pre>
|
143
143
|
</div>
|
@@ -172,7 +172,7 @@ scissors</p>
|
|
172
172
|
<pre><span class="ruby-comment"># File lib/Main.rb, line 24</span>
|
173
173
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>
|
174
174
|
<span class="ruby-comment"># initialize variables and set all equal to zero</span>
|
175
|
-
<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
|
+
<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>
|
176
176
|
<span class="ruby-keyword">end</span></pre>
|
177
177
|
</div>
|
178
178
|
|
@@ -213,37 +213,37 @@ scissors</p>
|
|
213
213
|
|
214
214
|
<div class="method-source-code" id="play-source">
|
215
215
|
<pre><span class="ruby-comment"># File lib/Main.rb, line 30</span>
|
216
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">play</span>(<span class="ruby-identifier">winning_score</span>)
|
216
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">play</span>(<span class="ruby-identifier">winning_score</span>)
|
217
217
|
<span class="ruby-comment"># make while loop</span>
|
218
|
-
<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>
|
219
|
-
<span class="ruby-identifier">puts</span> <span class="ruby-node">"\nPlayer score: #{@player_score}, "</span> <span class="ruby-operator">+</span>
|
218
|
+
<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>
|
219
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-node">"\nPlayer score: #{@player_score}, "</span> <span class="ruby-operator">+</span>
|
220
220
|
<span class="ruby-node">"Computer score: #{@computer_score}, Ties: #{@ties}.\n"</span>
|
221
|
-
<span class="ruby-identifier">player</span> = <span class="ruby-constant">PrivateMethods</span>.<span class="ruby-identifier">player_choice</span>
|
222
|
-
<span class="ruby-identifier">computer</span> = <span class="ruby-constant">
|
223
|
-
<span class="ruby-identifier">puts</span> <span class="ruby-node">"\nPlayer chooses #{player.to_s.downcase}."</span>
|
224
|
-
<span class="ruby-identifier">puts</span> <span class="ruby-node">"Computer chooses #{computer.to_s.downcase}.\n"</span>
|
225
|
-
<span class="ruby-keyword">case</span> <span class="ruby-constant">PrivateMethods</span>.<span class="ruby-identifier">player_outcome</span> [<span class="ruby-identifier">player</span>, <span class="ruby-identifier">computer</span>]
|
221
|
+
<span class="ruby-identifier">player</span> = <span class="ruby-constant">PrivateMethods</span>.<span class="ruby-identifier">player_choice</span>
|
222
|
+
<span class="ruby-identifier">computer</span> = <span class="ruby-constant">ProtectedConstants</span><span class="ruby-operator">::</span><span class="ruby-constant">COMPUTER_CHOICES</span>.<span class="ruby-identifier">sample</span> <span class="ruby-comment"># chooses a random option</span>
|
223
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-node">"\nPlayer chooses #{player.to_s.downcase}."</span>
|
224
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-node">"Computer chooses #{computer.to_s.downcase}.\n"</span>
|
225
|
+
<span class="ruby-keyword">case</span> <span class="ruby-constant">PrivateMethods</span>.<span class="ruby-identifier">player_outcome</span> [<span class="ruby-identifier">player</span>, <span class="ruby-identifier">computer</span>]
|
226
226
|
<span class="ruby-keyword">when</span> <span class="ruby-value">:WIN</span>
|
227
|
-
<span class="ruby-identifier">puts</span> <span class="ruby-node">"\n#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round.\n"</span>
|
227
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-node">"\n#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round.\n"</span>
|
228
228
|
<span class="ruby-ivar">@player_score</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
229
229
|
<span class="ruby-keyword">when</span> <span class="ruby-value">:LOSE</span>
|
230
|
-
<span class="ruby-identifier">puts</span> <span class="ruby-node">"\n#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round.\n"</span>
|
231
|
-
<span class="ruby-ivar">@computer_score</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
232
|
-
<span class="ruby-keyword">else</span>
|
233
|
-
<span class="ruby-identifier">puts</span> <span class="ruby-string">"\nTie, choose again\n"</span>
|
230
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-node">"\n#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round.\n"</span>
|
231
|
+
<span class="ruby-ivar">@computer_score</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
232
|
+
<span class="ruby-keyword">else</span>
|
233
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-string">"\nTie, choose again\n"</span>
|
234
234
|
<span class="ruby-ivar">@ties</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
235
235
|
<span class="ruby-keyword">end</span>
|
236
236
|
<span class="ruby-keyword">end</span>
|
237
237
|
<span class="ruby-identifier">puts</span> <span class="ruby-node">"\nFinal score: player: #{@player_score}, "</span> <span class="ruby-operator">+</span>
|
238
|
-
<span class="ruby-node">"computer: #{@computer_score} (ties: #{@ties}).\n"</span>
|
238
|
+
<span class="ruby-node">"computer: #{@computer_score} (ties: #{@ties}).\n"</span>
|
239
239
|
<span class="ruby-keyword">case</span> <span class="ruby-constant">PrivateMethods</span>.<span class="ruby-identifier">final_outcome</span>(<span class="ruby-ivar">@player_score</span>, <span class="ruby-ivar">@computer_score</span>)
|
240
|
-
<span class="ruby-keyword">when</span> <span class="ruby-value">:WIN</span>
|
241
|
-
<span class="ruby-identifier">puts</span> <span class="ruby-string">"\nPlayer wins!\n"</span>
|
240
|
+
<span class="ruby-keyword">when</span> <span class="ruby-value">:WIN</span>
|
241
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-string">"\nPlayer wins!\n"</span>
|
242
242
|
<span class="ruby-keyword">when</span> <span class="ruby-value">:LOSE</span>
|
243
|
-
<span class="ruby-identifier">puts</span> <span class="ruby-string">"\nComputer wins!\n"</span>
|
244
|
-
<span class="ruby-keyword">else</span>
|
245
|
-
<span class="ruby-identifier">puts</span> <span class="ruby-string">"\nIt's a tie!\n"</span>
|
246
|
-
<span class="ruby-keyword">end</span>
|
243
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-string">"\nComputer wins!\n"</span>
|
244
|
+
<span class="ruby-keyword">else</span>
|
245
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-string">"\nIt's a tie!\n"</span>
|
246
|
+
<span class="ruby-keyword">end</span>
|
247
247
|
<span class="ruby-identifier">print</span> <span class="ruby-string">"\n[press the enter/return key to exit game]"</span>
|
248
248
|
<span class="ruby-identifier">gets</span>
|
249
249
|
<span class="ruby-keyword">end</span></pre>
|
data/doc/created.rid
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
lib/Constants.rb
|
3
|
-
lib/Main.rb
|
4
|
-
lib/PrivateMethods.rb
|
5
|
-
lib/rpsg/version.rb
|
1
|
+
Sat, 28 Oct 2017 11:30:22 -0700
|
2
|
+
lib/Constants.rb Sat, 28 Oct 2017 11:28:45 -0700
|
3
|
+
lib/Main.rb Sat, 28 Oct 2017 11:29:41 -0700
|
4
|
+
lib/PrivateMethods.rb Sat, 28 Oct 2017 11:29:09 -0700
|
5
|
+
lib/rpsg/version.rb Wed, 25 Oct 2017 12:42:39 -0700
|
data/doc/index.html
CHANGED
@@ -59,10 +59,10 @@
|
|
59
59
|
|
60
60
|
<ul class="link-list">
|
61
61
|
|
62
|
-
<li><a href="./Constants.html">Constants</a>
|
63
|
-
|
64
62
|
<li><a href="./PrivateMethods.html">PrivateMethods</a>
|
65
63
|
|
64
|
+
<li><a href="./ProtectedConstants.html">ProtectedConstants</a>
|
65
|
+
|
66
66
|
<li><a href="./RPSG.html">RPSG</a>
|
67
67
|
|
68
68
|
<li><a href="./RockPaperScissorsGame.html">RockPaperScissorsGame</a>
|
data/doc/js/navigation.js.gz
CHANGED
Binary file
|
data/doc/js/search_index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var search_data = {"index":{"searchIndex":["
|
1
|
+
var search_data = {"index":{"searchIndex":["privatemethods","protectedconstants","rpsg","rockpaperscissorsgame","continue()","final_outcome()","new()","play()","player_choice()","player_outcome()"],"longSearchIndex":["privatemethods","protectedconstants","rpsg","rockpaperscissorsgame","rockpaperscissorsgame::continue()","privatemethods::final_outcome()","rockpaperscissorsgame::new()","rockpaperscissorsgame#play()","privatemethods::player_choice()","privatemethods::player_outcome()"],"info":[["PrivateMethods","","PrivateMethods.html","","<p>add module for private methods for the rpsg calculations\n"],["ProtectedConstants","","ProtectedConstants.html","","<p>create module that holds all contents for this script\n"],["RPSG","","RPSG.html","","<p>specify the version for the rubygem\n"],["RockPaperScissorsGame","","RockPaperScissorsGame.html","","<p>create master class for rpsg\n"],["continue","RockPaperScissorsGame","RockPaperScissorsGame.html#method-c-continue","(str1,str2,str3)","<p>add continue method for asking the user if they want to play rock paper\nscissors\n"],["final_outcome","PrivateMethods","PrivateMethods.html#method-c-final_outcome","(pl, co)","<p>define final outcome that gives the result of who one the whole match\n"],["new","RockPaperScissorsGame","RockPaperScissorsGame.html#method-c-new","()","<p>initialize variables\n"],["play","RockPaperScissorsGame","RockPaperScissorsGame.html#method-i-play","(winning_score)","<p>define play method, this will be the main function for playing rock paper\nscissors\n"],["player_choice","PrivateMethods","PrivateMethods.html#method-c-player_choice","()","<p>make a definition that asks for the players choice\n"],["player_outcome","PrivateMethods","PrivateMethods.html#method-c-player_outcome","(plays)","<p>define outcomes of players choice against cpu\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
@@ -27,10 +27,10 @@
|
|
27
27
|
<h2 id="classes">Classes and Modules</h2>
|
28
28
|
<ul>
|
29
29
|
<li class="module">
|
30
|
-
<a href="
|
30
|
+
<a href="PrivateMethods.html">PrivateMethods</a>
|
31
31
|
</li>
|
32
32
|
<li class="module">
|
33
|
-
<a href="
|
33
|
+
<a href="ProtectedConstants.html">ProtectedConstants</a>
|
34
34
|
</li>
|
35
35
|
<li class="module">
|
36
36
|
<a href="RPSG.html">RPSG</a>
|
data/docs/_pages/code.txt
CHANGED
@@ -36,104 +36,104 @@ class RockPaperScissorsGame
|
|
36
36
|
# specify the version for the rubygem
|
37
37
|
module RPSG
|
38
38
|
# create version constant for the rubygem
|
39
|
-
VERSION = "0.3.
|
39
|
+
VERSION = "0.3.6"
|
40
40
|
end
|
41
41
|
|
42
42
|
# create module that holds all contents for this script
|
43
|
-
module
|
44
|
-
|
43
|
+
module ProtectedConstants
|
44
|
+
|
45
45
|
# create 2d list of choices
|
46
|
-
protected
|
47
|
-
CHOICES = [['r', 'rock'], ['p', 'paper'], ['s', 'scissors']]
|
46
|
+
protected # make protected
|
47
|
+
CHOICES = [['r', 'rock'], ['p', 'paper'], ['s', 'scissors']]
|
48
48
|
|
49
|
-
# define entry to symbol (key to value)
|
50
|
-
protected
|
51
|
-
NTRY_TO_SYM = {
|
49
|
+
# define entry to symbol (key to value) dictionary
|
50
|
+
protected # make protected
|
51
|
+
NTRY_TO_SYM = {
|
52
52
|
CHOICES[0][0] => :ROCK , CHOICES[0][1] => :ROCK ,
|
53
53
|
CHOICES[1][0] => :PAPER , CHOICES[1][1] => :PAPER ,
|
54
54
|
CHOICES[2][0] => :SCISSORS, CHOICES[2][1] => :SCISSORS
|
55
|
-
}
|
55
|
+
}
|
56
56
|
|
57
57
|
# define valid entries
|
58
|
-
protected
|
59
|
-
VALID_ENTRIES = NTRY_TO_SYM.keys
|
58
|
+
protected # make protected
|
59
|
+
VALID_ENTRIES = NTRY_TO_SYM.keys
|
60
60
|
|
61
61
|
# define computer choices
|
62
|
-
protected
|
63
|
-
COMPUTER_CHOICES = NTRY_TO_SYM.values
|
62
|
+
protected # make protected
|
63
|
+
COMPUTER_CHOICES = NTRY_TO_SYM.values
|
64
64
|
|
65
65
|
# create winners 2d list array with format: winning choice, losing choice
|
66
|
-
protected
|
66
|
+
protected # make protected
|
67
67
|
WINNERS = [
|
68
|
-
[:SCISSORS, :PAPER ],
|
69
|
-
[:PAPER , :ROCK ],
|
68
|
+
[:SCISSORS, :PAPER ],
|
69
|
+
[:PAPER , :ROCK ],
|
70
70
|
[:ROCK , :SCISSORS]
|
71
|
-
]
|
71
|
+
]
|
72
72
|
|
73
73
|
# this will take the original WINNERS array and flip the symbols, thus returning a loss for the user/player
|
74
|
-
protected
|
75
|
-
LOSERS = WINNERS.map { |winning_choice,losing_choice| [losing_choice,winning_choice] }
|
74
|
+
protected # make protected
|
75
|
+
LOSERS = WINNERS.map { |winning_choice,losing_choice| [losing_choice,winning_choice] }
|
76
76
|
|
77
77
|
end
|
78
78
|
|
79
|
-
# protected_methods :
|
79
|
+
# protected_methods :ProtectedConstants
|
80
80
|
|
81
81
|
class << self
|
82
82
|
# add continue method for asking the user if they want to play rock paper scissors
|
83
83
|
def continue(str1,str2,str3)
|
84
|
-
puts str1
|
84
|
+
puts str1
|
85
85
|
print str2
|
86
|
-
gets
|
86
|
+
gets
|
87
87
|
puts str3
|
88
|
-
end
|
89
|
-
end
|
88
|
+
end
|
89
|
+
end
|
90
90
|
|
91
91
|
# print out strings
|
92
92
|
continue("\nYou are about to enter a rock-paper-scissors best of 3 match.", "\nPress the return/enter key to continue...", "")
|
93
|
-
|
93
|
+
|
94
94
|
# initialize variables
|
95
95
|
def initialize
|
96
96
|
# initialize variables and set all equal to zero
|
97
|
-
@player_score = @computer_score = @ties = 0
|
97
|
+
@player_score = @computer_score = @ties = 0
|
98
98
|
end
|
99
99
|
|
100
100
|
# define play method, this will be the main function for playing rock paper scissors
|
101
|
-
def play(winning_score)
|
101
|
+
def play(winning_score)
|
102
102
|
# make while loop
|
103
|
-
while @player_score < winning_score && @computer_score < winning_score
|
104
|
-
puts "\nPlayer score: #{@player_score}, " +
|
103
|
+
while @player_score < winning_score && @computer_score < winning_score
|
104
|
+
puts "\nPlayer score: #{@player_score}, " +
|
105
105
|
"Computer score: #{@computer_score}, Ties: #{@ties}.\n"
|
106
|
-
player = PrivateMethods.player_choice
|
107
|
-
computer =
|
108
|
-
puts "\nPlayer chooses #{player.to_s.downcase}."
|
109
|
-
puts "Computer chooses #{computer.to_s.downcase}.\n"
|
110
|
-
case PrivateMethods.player_outcome [player, computer]
|
106
|
+
player = PrivateMethods.player_choice
|
107
|
+
computer = ProtectedConstants::COMPUTER_CHOICES.sample # chooses a random option
|
108
|
+
puts "\nPlayer chooses #{player.to_s.downcase}."
|
109
|
+
puts "Computer chooses #{computer.to_s.downcase}.\n"
|
110
|
+
case PrivateMethods.player_outcome [player, computer]
|
111
111
|
when :WIN
|
112
|
-
puts "\n#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round.\n"
|
112
|
+
puts "\n#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round.\n"
|
113
113
|
@player_score += 1
|
114
114
|
when :LOSE
|
115
|
-
puts "\n#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round.\n"
|
116
|
-
@computer_score += 1
|
117
|
-
else
|
118
|
-
puts "\nTie, choose again\n"
|
115
|
+
puts "\n#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round.\n"
|
116
|
+
@computer_score += 1
|
117
|
+
else
|
118
|
+
puts "\nTie, choose again\n"
|
119
119
|
@ties += 1
|
120
120
|
end
|
121
121
|
end
|
122
122
|
puts "\nFinal score: player: #{@player_score}, " +
|
123
|
-
"computer: #{@computer_score} (ties: #{@ties}).\n"
|
123
|
+
"computer: #{@computer_score} (ties: #{@ties}).\n"
|
124
124
|
case PrivateMethods.final_outcome(@player_score, @computer_score)
|
125
|
-
when :WIN
|
126
|
-
puts "\nPlayer wins!\n"
|
125
|
+
when :WIN
|
126
|
+
puts "\nPlayer wins!\n"
|
127
127
|
when :LOSE
|
128
|
-
puts "\nComputer wins!\n"
|
129
|
-
else
|
130
|
-
puts "\nIt's a tie!\n"
|
131
|
-
end
|
128
|
+
puts "\nComputer wins!\n"
|
129
|
+
else
|
130
|
+
puts "\nIt's a tie!\n"
|
131
|
+
end
|
132
132
|
print "\n[press the enter/return key to exit game]"
|
133
133
|
gets
|
134
134
|
end
|
135
135
|
|
136
|
-
private
|
136
|
+
private # make private
|
137
137
|
# add module for private methods for the rpsg calculations
|
138
138
|
module PrivateMethods
|
139
139
|
class << self
|
@@ -142,37 +142,37 @@ class RockPaperScissorsGame
|
|
142
142
|
loop do
|
143
143
|
print "\nChoose: Rock (r), Paper (p), or Scissors (s): "
|
144
144
|
choice = gets.chomp.downcase
|
145
|
-
if
|
146
|
-
return
|
147
|
-
elsif choice !=
|
145
|
+
if ProtectedConstants::NTRY_TO_SYM.key?(choice)
|
146
|
+
return ProtectedConstants::NTRY_TO_SYM[choice]
|
147
|
+
elsif choice != ProtectedConstants::VALID_ENTRIES
|
148
148
|
puts "\nThat entry is invalid. Please re-enter.\n"
|
149
149
|
else
|
150
150
|
return nil
|
151
151
|
end
|
152
|
-
end
|
153
|
-
end
|
152
|
+
end
|
153
|
+
end
|
154
154
|
# define outcomes of players choice against cpu
|
155
155
|
def player_outcome(plays)
|
156
|
-
return :WIN if
|
157
|
-
return :LOSE if
|
156
|
+
return :WIN if ProtectedConstants::WINNERS.include?(plays)
|
157
|
+
return :LOSE if ProtectedConstants::LOSERS.include?(plays)
|
158
158
|
return :TIE if !:WIN | !:LOSE
|
159
|
-
end
|
159
|
+
end
|
160
160
|
# define final outcome that gives the result of who one the whole match
|
161
|
-
def final_outcome(pl,co)
|
162
|
-
return :WIN if pl > co
|
161
|
+
def final_outcome(pl, co)
|
162
|
+
return :WIN if pl > co
|
163
163
|
return :LOSE if pl < co
|
164
|
-
return :TIE if pl = co
|
165
|
-
# there will never be a tie for the final outcome due to the code in the play() method
|
166
|
-
end
|
164
|
+
# return :TIE if pl = co
|
165
|
+
# there will never be a tie for the final outcome due to the code in the `play()` method
|
166
|
+
end
|
167
167
|
end
|
168
168
|
end
|
169
|
-
public
|
170
|
-
|
169
|
+
public # make public again
|
170
|
+
|
171
171
|
# private_methods :PrivateMethods
|
172
172
|
|
173
|
-
end
|
173
|
+
end
|
174
174
|
|
175
175
|
RockPaperScissorsGame.new.play(2) # best out of 3
|
176
176
|
|
177
177
|
$end
|
178
|
-
~~~
|
178
|
+
~~~
|
data/docs/_site/bundler.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=
|
10
|
+
<link rel="stylesheet" href="/assets/css/style.css?v=79b195a757ede2a8ba73e25b563d20b7367d2e92"/>
|
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=
|
10
|
+
<link rel="stylesheet" href="/assets/css/style.css?v=79b195a757ede2a8ba73e25b563d20b7367d2e92"/>
|
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"/>
|
@@ -74,104 +74,104 @@
|
|
74
74
|
<span class="c1"># specify the version for the rubygem</span>
|
75
75
|
<span class="k">module</span> <span class="nn">RPSG</span>
|
76
76
|
<span class="c1"># create version constant for the rubygem</span>
|
77
|
-
<span class="no">VERSION</span> <span class="o">=</span> <span class="s2">"0.3.
|
77
|
+
<span class="no">VERSION</span> <span class="o">=</span> <span class="s2">"0.3.6"</span>
|
78
78
|
<span class="k">end</span>
|
79
79
|
|
80
80
|
<span class="c1"># create module that holds all contents for this script</span>
|
81
|
-
<span class="k">module</span> <span class="nn">
|
82
|
-
|
81
|
+
<span class="k">module</span> <span class="nn">ProtectedConstants</span>
|
82
|
+
|
83
83
|
<span class="c1"># create 2d list of choices</span>
|
84
|
-
<span class="kp">protected</span>
|
85
|
-
<span class="no">CHOICES</span> <span class="o">=</span> <span class="p">[[</span><span class="s1">'r'</span><span class="p">,</span> <span class="s1">'rock'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'p'</span><span class="p">,</span> <span class="s1">'paper'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'s'</span><span class="p">,</span> <span class="s1">'scissors'</span><span class="p">]]</span>
|
84
|
+
<span class="kp">protected</span> <span class="c1"># make protected</span>
|
85
|
+
<span class="no">CHOICES</span> <span class="o">=</span> <span class="p">[[</span><span class="s1">'r'</span><span class="p">,</span> <span class="s1">'rock'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'p'</span><span class="p">,</span> <span class="s1">'paper'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'s'</span><span class="p">,</span> <span class="s1">'scissors'</span><span class="p">]]</span>
|
86
86
|
|
87
|
-
<span class="c1"># define entry to symbol (key to value)</span>
|
88
|
-
<span class="kp">protected</span>
|
89
|
-
<span class="no">NTRY_TO_SYM</span> <span class="o">=</span> <span class="p">{</span>
|
87
|
+
<span class="c1"># define entry to symbol (key to value) dictionary</span>
|
88
|
+
<span class="kp">protected</span> <span class="c1"># make protected</span>
|
89
|
+
<span class="no">NTRY_TO_SYM</span> <span class="o">=</span> <span class="p">{</span>
|
90
90
|
<span class="no">CHOICES</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=></span> <span class="ss">:ROCK</span> <span class="p">,</span> <span class="no">CHOICES</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=></span> <span class="ss">:ROCK</span> <span class="p">,</span>
|
91
91
|
<span class="no">CHOICES</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=></span> <span class="ss">:PAPER</span> <span class="p">,</span> <span class="no">CHOICES</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=></span> <span class="ss">:PAPER</span> <span class="p">,</span>
|
92
92
|
<span class="no">CHOICES</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=></span> <span class="ss">:SCISSORS</span><span class="p">,</span> <span class="no">CHOICES</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=></span> <span class="ss">:SCISSORS</span>
|
93
|
-
<span class="p">}</span>
|
93
|
+
<span class="p">}</span>
|
94
94
|
|
95
95
|
<span class="c1"># define valid entries</span>
|
96
|
-
<span class="kp">protected</span>
|
97
|
-
<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>
|
96
|
+
<span class="kp">protected</span> <span class="c1"># make protected</span>
|
97
|
+
<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>
|
98
98
|
|
99
99
|
<span class="c1"># define computer choices</span>
|
100
|
-
<span class="kp">protected</span>
|
101
|
-
<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>
|
100
|
+
<span class="kp">protected</span> <span class="c1"># make protected</span>
|
101
|
+
<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>
|
102
102
|
|
103
103
|
<span class="c1"># create winners 2d list array with format: winning choice, losing choice</span>
|
104
|
-
<span class="kp">protected</span>
|
104
|
+
<span class="kp">protected</span> <span class="c1"># make protected</span>
|
105
105
|
<span class="no">WINNERS</span> <span class="o">=</span> <span class="p">[</span>
|
106
|
-
<span class="p">[</span><span class="ss">:SCISSORS</span><span class="p">,</span> <span class="ss">:PAPER</span> <span class="p">],</span>
|
107
|
-
<span class="p">[</span><span class="ss">:PAPER</span> <span class="p">,</span> <span class="ss">:ROCK</span> <span class="p">],</span>
|
106
|
+
<span class="p">[</span><span class="ss">:SCISSORS</span><span class="p">,</span> <span class="ss">:PAPER</span> <span class="p">],</span>
|
107
|
+
<span class="p">[</span><span class="ss">:PAPER</span> <span class="p">,</span> <span class="ss">:ROCK</span> <span class="p">],</span>
|
108
108
|
<span class="p">[</span><span class="ss">:ROCK</span> <span class="p">,</span> <span class="ss">:SCISSORS</span><span class="p">]</span>
|
109
|
-
<span class="p">]</span>
|
109
|
+
<span class="p">]</span>
|
110
110
|
|
111
111
|
<span class="c1"># this will take the original WINNERS array and flip the symbols, thus returning a loss for the user/player</span>
|
112
|
-
<span class="kp">protected</span>
|
113
|
-
<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">winning_choice</span><span class="p">,</span><span class="n">losing_choice</span><span class="o">|</span> <span class="p">[</span><span class="n">losing_choice</span><span class="p">,</span><span class="n">winning_choice</span><span class="p">]</span> <span class="p">}</span>
|
112
|
+
<span class="kp">protected</span> <span class="c1"># make protected</span>
|
113
|
+
<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">winning_choice</span><span class="p">,</span><span class="n">losing_choice</span><span class="o">|</span> <span class="p">[</span><span class="n">losing_choice</span><span class="p">,</span><span class="n">winning_choice</span><span class="p">]</span> <span class="p">}</span>
|
114
114
|
|
115
115
|
<span class="k">end</span>
|
116
116
|
|
117
|
-
<span class="c1"># protected_methods :
|
117
|
+
<span class="c1"># protected_methods :ProtectedConstants</span>
|
118
118
|
|
119
119
|
<span class="k">class</span> <span class="o"><<</span> <span class="nb">self</span>
|
120
120
|
<span class="c1"># add continue method for asking the user if they want to play rock paper scissors</span>
|
121
121
|
<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>
|
122
|
-
<span class="nb">puts</span> <span class="n">str1</span>
|
122
|
+
<span class="nb">puts</span> <span class="n">str1</span>
|
123
123
|
<span class="nb">print</span> <span class="n">str2</span>
|
124
|
-
<span class="nb">gets</span>
|
124
|
+
<span class="nb">gets</span>
|
125
125
|
<span class="nb">puts</span> <span class="n">str3</span>
|
126
|
-
<span class="k">end</span>
|
127
|
-
<span class="k">end</span>
|
126
|
+
<span class="k">end</span>
|
127
|
+
<span class="k">end</span>
|
128
128
|
|
129
129
|
<span class="c1"># print out strings</span>
|
130
130
|
<span class="n">continue</span><span class="p">(</span><span class="s2">"</span><span class="se">\n</span><span class="s2">You are about to enter a rock-paper-scissors best of 3 match."</span><span class="p">,</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">Press the return/enter key to continue..."</span><span class="p">,</span> <span class="s2">""</span><span class="p">)</span>
|
131
|
-
|
131
|
+
|
132
132
|
<span class="c1"># initialize variables</span>
|
133
133
|
<span class="k">def</span> <span class="nf">initialize</span>
|
134
134
|
<span class="c1"># initialize variables and set all equal to zero</span>
|
135
|
-
<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>
|
135
|
+
<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>
|
136
136
|
<span class="k">end</span>
|
137
137
|
|
138
138
|
<span class="c1"># define play method, this will be the main function for playing rock paper scissors</span>
|
139
|
-
<span class="k">def</span> <span class="nf">play</span><span class="p">(</span><span class="n">winning_score</span><span class="p">)</span>
|
139
|
+
<span class="k">def</span> <span class="nf">play</span><span class="p">(</span><span class="n">winning_score</span><span class="p">)</span>
|
140
140
|
<span class="c1"># make while loop</span>
|
141
|
-
<span class="k">while</span> <span class="vi">@player_score</span> <span class="o"><</span> <span class="n">winning_score</span> <span class="o">&&</span> <span class="vi">@computer_score</span> <span class="o"><</span> <span class="n">winning_score</span>
|
142
|
-
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</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>
|
141
|
+
<span class="k">while</span> <span class="vi">@player_score</span> <span class="o"><</span> <span class="n">winning_score</span> <span class="o">&&</span> <span class="vi">@computer_score</span> <span class="o"><</span> <span class="n">winning_score</span>
|
142
|
+
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</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>
|
143
143
|
<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="se">\n</span><span class="s2">"</span>
|
144
|
-
<span class="n">player</span> <span class="o">=</span> <span class="no">PrivateMethods</span><span class="p">.</span><span class="nf">player_choice</span>
|
145
|
-
<span class="n">computer</span> <span class="o">=</span> <span class="no">
|
146
|
-
<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>
|
147
|
-
<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><span class="se">\n</span><span class="s2">"</span>
|
148
|
-
<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>
|
144
|
+
<span class="n">player</span> <span class="o">=</span> <span class="no">PrivateMethods</span><span class="p">.</span><span class="nf">player_choice</span>
|
145
|
+
<span class="n">computer</span> <span class="o">=</span> <span class="no">ProtectedConstants</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>
|
146
|
+
<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>
|
147
|
+
<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><span class="se">\n</span><span class="s2">"</span>
|
148
|
+
<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>
|
149
149
|
<span class="k">when</span> <span class="ss">:WIN</span>
|
150
|
-
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</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="se">\n</span><span class="s2">"</span>
|
150
|
+
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</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="se">\n</span><span class="s2">"</span>
|
151
151
|
<span class="vi">@player_score</span> <span class="o">+=</span> <span class="mi">1</span>
|
152
152
|
<span class="k">when</span> <span class="ss">:LOSE</span>
|
153
|
-
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</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="se">\n</span><span class="s2">"</span>
|
154
|
-
<span class="vi">@computer_score</span> <span class="o">+=</span> <span class="mi">1</span>
|
155
|
-
<span class="k">else</span>
|
156
|
-
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">Tie, choose again</span><span class="se">\n</span><span class="s2">"</span>
|
153
|
+
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</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="se">\n</span><span class="s2">"</span>
|
154
|
+
<span class="vi">@computer_score</span> <span class="o">+=</span> <span class="mi">1</span>
|
155
|
+
<span class="k">else</span>
|
156
|
+
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">Tie, choose again</span><span class="se">\n</span><span class="s2">"</span>
|
157
157
|
<span class="vi">@ties</span> <span class="o">+=</span> <span class="mi">1</span>
|
158
158
|
<span class="k">end</span>
|
159
159
|
<span class="k">end</span>
|
160
160
|
<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>
|
161
|
-
<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="se">\n</span><span class="s2">"</span>
|
161
|
+
<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="se">\n</span><span class="s2">"</span>
|
162
162
|
<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>
|
163
|
-
<span class="k">when</span> <span class="ss">:WIN</span>
|
164
|
-
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">Player wins!</span><span class="se">\n</span><span class="s2">"</span>
|
163
|
+
<span class="k">when</span> <span class="ss">:WIN</span>
|
164
|
+
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">Player wins!</span><span class="se">\n</span><span class="s2">"</span>
|
165
165
|
<span class="k">when</span> <span class="ss">:LOSE</span>
|
166
|
-
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">Computer wins!</span><span class="se">\n</span><span class="s2">"</span>
|
167
|
-
<span class="k">else</span>
|
168
|
-
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">It's a tie!</span><span class="se">\n</span><span class="s2">"</span>
|
169
|
-
<span class="k">end</span>
|
166
|
+
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">Computer wins!</span><span class="se">\n</span><span class="s2">"</span>
|
167
|
+
<span class="k">else</span>
|
168
|
+
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">It's a tie!</span><span class="se">\n</span><span class="s2">"</span>
|
169
|
+
<span class="k">end</span>
|
170
170
|
<span class="nb">print</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">[press the enter/return key to exit game]"</span>
|
171
171
|
<span class="nb">gets</span>
|
172
172
|
<span class="k">end</span>
|
173
173
|
|
174
|
-
<span class="kp">private</span>
|
174
|
+
<span class="kp">private</span> <span class="c1"># make private</span>
|
175
175
|
<span class="c1"># add module for private methods for the rpsg calculations</span>
|
176
176
|
<span class="k">module</span> <span class="nn">PrivateMethods</span>
|
177
177
|
<span class="k">class</span> <span class="o"><<</span> <span class="nb">self</span>
|
@@ -180,35 +180,35 @@
|
|
180
180
|
<span class="kp">loop</span> <span class="k">do</span>
|
181
181
|
<span class="nb">print</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">Choose: Rock (r), Paper (p), or Scissors (s): "</span>
|
182
182
|
<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>
|
183
|
-
<span class="k">if</span> <span class="no">
|
184
|
-
<span class="k">return</span> <span class="no">
|
185
|
-
<span class="k">elsif</span> <span class="n">choice</span> <span class="o">!=</span> <span class="no">
|
183
|
+
<span class="k">if</span> <span class="no">ProtectedConstants</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>
|
184
|
+
<span class="k">return</span> <span class="no">ProtectedConstants</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>
|
185
|
+
<span class="k">elsif</span> <span class="n">choice</span> <span class="o">!=</span> <span class="no">ProtectedConstants</span><span class="o">::</span><span class="no">VALID_ENTRIES</span>
|
186
186
|
<span class="nb">puts</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">That entry is invalid. Please re-enter.</span><span class="se">\n</span><span class="s2">"</span>
|
187
187
|
<span class="k">else</span>
|
188
188
|
<span class="k">return</span> <span class="kp">nil</span>
|
189
189
|
<span class="k">end</span>
|
190
|
-
<span class="k">end</span>
|
191
|
-
<span class="k">end</span>
|
190
|
+
<span class="k">end</span>
|
191
|
+
<span class="k">end</span>
|
192
192
|
<span class="c1"># define outcomes of players choice against cpu</span>
|
193
193
|
<span class="k">def</span> <span class="nf">player_outcome</span><span class="p">(</span><span class="n">plays</span><span class="p">)</span>
|
194
|
-
<span class="k">return</span> <span class="ss">:WIN</span> <span class="k">if</span> <span class="no">
|
195
|
-
<span class="k">return</span> <span class="ss">:LOSE</span> <span class="k">if</span> <span class="no">
|
194
|
+
<span class="k">return</span> <span class="ss">:WIN</span> <span class="k">if</span> <span class="no">ProtectedConstants</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>
|
195
|
+
<span class="k">return</span> <span class="ss">:LOSE</span> <span class="k">if</span> <span class="no">ProtectedConstants</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>
|
196
196
|
<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>
|
197
|
-
<span class="k">end</span>
|
197
|
+
<span class="k">end</span>
|
198
198
|
<span class="c1"># define final outcome that gives the result of who one the whole match</span>
|
199
|
-
<span class="k">def</span> <span class="nf">final_outcome</span><span class="p">(</span><span class="n">pl</span><span class="p">,</span
|
200
|
-
<span class="k">return</span> <span class="ss">:WIN</span> <span class="k">if</span> <span class="n">pl</span> <span class="o">></span> <span class="n">co</span>
|
199
|
+
<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>
|
200
|
+
<span class="k">return</span> <span class="ss">:WIN</span> <span class="k">if</span> <span class="n">pl</span> <span class="o">></span> <span class="n">co</span>
|
201
201
|
<span class="k">return</span> <span class="ss">:LOSE</span> <span class="k">if</span> <span class="n">pl</span> <span class="o"><</span> <span class="n">co</span>
|
202
|
-
<span class="
|
203
|
-
<span class="c1"># there will never be a tie for the final outcome due to the code in the play() method</span>
|
204
|
-
<span class="k">end</span>
|
202
|
+
<span class="c1"># return :TIE if pl = co</span>
|
203
|
+
<span class="c1"># there will never be a tie for the final outcome due to the code in the `play()` method</span>
|
204
|
+
<span class="k">end</span>
|
205
205
|
<span class="k">end</span>
|
206
206
|
<span class="k">end</span>
|
207
|
-
<span class="kp">public</span>
|
208
|
-
|
207
|
+
<span class="kp">public</span> <span class="c1"># make public again</span>
|
208
|
+
|
209
209
|
<span class="c1"># private_methods :PrivateMethods</span>
|
210
210
|
|
211
|
-
<span class="k">end</span>
|
211
|
+
<span class="k">end</span>
|
212
212
|
|
213
213
|
<span class="no">RockPaperScissorsGame</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"># best out of 3</span>
|
214
214
|
|
data/docs/_site/index.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=
|
10
|
+
<link rel="stylesheet" href="/assets/css/style.css?v=79b195a757ede2a8ba73e25b563d20b7367d2e92"/>
|
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/install.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=
|
10
|
+
<link rel="stylesheet" href="/assets/css/style.css?v=79b195a757ede2a8ba73e25b563d20b7367d2e92"/>
|
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/readme.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=
|
10
|
+
<link rel="stylesheet" href="/assets/css/style.css?v=79b195a757ede2a8ba73e25b563d20b7367d2e92"/>
|
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/simple.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=
|
10
|
+
<link rel="stylesheet" href="/assets/css/style.css?v=79b195a757ede2a8ba73e25b563d20b7367d2e92"/>
|
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/test.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=
|
10
|
+
<link rel="stylesheet" href="/assets/css/style.css?v=79b195a757ede2a8ba73e25b563d20b7367d2e92"/>
|
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/uninstall.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=
|
10
|
+
<link rel="stylesheet" href="/assets/css/style.css?v=79b195a757ede2a8ba73e25b563d20b7367d2e92"/>
|
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/update.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=
|
10
|
+
<link rel="stylesheet" href="/assets/css/style.css?v=79b195a757ede2a8ba73e25b563d20b7367d2e92"/>
|
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/lib/Constants.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
1
|
# create module that holds all contents for this script
|
2
|
-
module
|
3
|
-
|
2
|
+
module ProtectedConstants
|
3
|
+
|
4
4
|
# create 2d list of choices
|
5
|
-
protected
|
6
|
-
CHOICES = [['r', 'rock'], ['p', 'paper'], ['s', 'scissors']]
|
5
|
+
protected # make protected
|
6
|
+
CHOICES = [['r', 'rock'], ['p', 'paper'], ['s', 'scissors']]
|
7
7
|
|
8
|
-
# define entry to symbol (key to value)
|
9
|
-
protected
|
10
|
-
NTRY_TO_SYM = {
|
8
|
+
# define entry to symbol (key to value) dictionary
|
9
|
+
protected # make protected
|
10
|
+
NTRY_TO_SYM = {
|
11
11
|
CHOICES[0][0] => :ROCK , CHOICES[0][1] => :ROCK ,
|
12
12
|
CHOICES[1][0] => :PAPER , CHOICES[1][1] => :PAPER ,
|
13
13
|
CHOICES[2][0] => :SCISSORS, CHOICES[2][1] => :SCISSORS
|
14
|
-
}
|
14
|
+
}
|
15
15
|
|
16
16
|
# define valid entries
|
17
|
-
protected
|
18
|
-
VALID_ENTRIES = NTRY_TO_SYM.keys
|
17
|
+
protected # make protected
|
18
|
+
VALID_ENTRIES = NTRY_TO_SYM.keys
|
19
19
|
|
20
20
|
# define computer choices
|
21
|
-
protected
|
22
|
-
COMPUTER_CHOICES = NTRY_TO_SYM.values
|
21
|
+
protected # make protected
|
22
|
+
COMPUTER_CHOICES = NTRY_TO_SYM.values
|
23
23
|
|
24
24
|
# create winners 2d list array with format: winning choice, losing choice
|
25
|
-
protected
|
25
|
+
protected # make protected
|
26
26
|
WINNERS = [
|
27
|
-
[:SCISSORS, :PAPER ],
|
28
|
-
[:PAPER , :ROCK ],
|
27
|
+
[:SCISSORS, :PAPER ],
|
28
|
+
[:PAPER , :ROCK ],
|
29
29
|
[:ROCK , :SCISSORS]
|
30
|
-
]
|
30
|
+
]
|
31
31
|
|
32
32
|
# this will take the original WINNERS array and flip the symbols, thus returning a loss for the user/player
|
33
|
-
protected
|
34
|
-
LOSERS = WINNERS.map { |winning_choice,losing_choice| [losing_choice,winning_choice] }
|
33
|
+
protected # make protected
|
34
|
+
LOSERS = WINNERS.map { |winning_choice,losing_choice| [losing_choice,winning_choice] }
|
35
35
|
|
36
36
|
end
|
data/lib/Main.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# create master class for rpsg
|
2
2
|
class RockPaperScissorsGame
|
3
|
-
|
3
|
+
|
4
4
|
require "rpsg/version.rb"
|
5
5
|
|
6
6
|
require "Constants.rb"
|
@@ -10,64 +10,64 @@ class RockPaperScissorsGame
|
|
10
10
|
class << self
|
11
11
|
# add continue method for asking the user if they want to play rock paper scissors
|
12
12
|
def continue(str1,str2,str3)
|
13
|
-
puts str1
|
13
|
+
puts str1
|
14
14
|
print str2
|
15
|
-
gets
|
15
|
+
gets
|
16
16
|
puts str3
|
17
|
-
end
|
18
|
-
end
|
17
|
+
end
|
18
|
+
end
|
19
19
|
|
20
20
|
# print out strings
|
21
21
|
continue("\nYou are about to enter a rock-paper-scissors best of 3 match.", "\nPress the return/enter key to continue...", "")
|
22
|
-
|
22
|
+
|
23
23
|
# initialize variables
|
24
24
|
def initialize
|
25
25
|
# initialize variables and set all equal to zero
|
26
|
-
@player_score = @computer_score = @ties = 0
|
26
|
+
@player_score = @computer_score = @ties = 0
|
27
27
|
end
|
28
28
|
|
29
29
|
# define play method, this will be the main function for playing rock paper scissors
|
30
|
-
def play(winning_score)
|
30
|
+
def play(winning_score)
|
31
31
|
# make while loop
|
32
|
-
while @player_score < winning_score && @computer_score < winning_score
|
33
|
-
puts "\nPlayer score: #{@player_score}, " +
|
32
|
+
while @player_score < winning_score && @computer_score < winning_score
|
33
|
+
puts "\nPlayer score: #{@player_score}, " +
|
34
34
|
"Computer score: #{@computer_score}, Ties: #{@ties}.\n"
|
35
|
-
player = PrivateMethods.player_choice
|
36
|
-
computer =
|
37
|
-
puts "\nPlayer chooses #{player.to_s.downcase}."
|
38
|
-
puts "Computer chooses #{computer.to_s.downcase}.\n"
|
39
|
-
case PrivateMethods.player_outcome [player, computer]
|
35
|
+
player = PrivateMethods.player_choice
|
36
|
+
computer = ProtectedConstants::COMPUTER_CHOICES.sample # chooses a random option
|
37
|
+
puts "\nPlayer chooses #{player.to_s.downcase}."
|
38
|
+
puts "Computer chooses #{computer.to_s.downcase}.\n"
|
39
|
+
case PrivateMethods.player_outcome [player, computer]
|
40
40
|
when :WIN
|
41
|
-
puts "\n#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round.\n"
|
41
|
+
puts "\n#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round.\n"
|
42
42
|
@player_score += 1
|
43
43
|
when :LOSE
|
44
|
-
puts "\n#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round.\n"
|
45
|
-
@computer_score += 1
|
46
|
-
else
|
47
|
-
puts "\nTie, choose again\n"
|
44
|
+
puts "\n#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round.\n"
|
45
|
+
@computer_score += 1
|
46
|
+
else
|
47
|
+
puts "\nTie, choose again\n"
|
48
48
|
@ties += 1
|
49
49
|
end
|
50
50
|
end
|
51
51
|
puts "\nFinal score: player: #{@player_score}, " +
|
52
|
-
"computer: #{@computer_score} (ties: #{@ties}).\n"
|
52
|
+
"computer: #{@computer_score} (ties: #{@ties}).\n"
|
53
53
|
case PrivateMethods.final_outcome(@player_score, @computer_score)
|
54
|
-
when :WIN
|
55
|
-
puts "\nPlayer wins!\n"
|
54
|
+
when :WIN
|
55
|
+
puts "\nPlayer wins!\n"
|
56
56
|
when :LOSE
|
57
|
-
puts "\nComputer wins!\n"
|
58
|
-
else
|
59
|
-
puts "\nIt's a tie!\n"
|
60
|
-
end
|
57
|
+
puts "\nComputer wins!\n"
|
58
|
+
else
|
59
|
+
puts "\nIt's a tie!\n"
|
60
|
+
end
|
61
61
|
print "\n[press the enter/return key to exit game]"
|
62
62
|
gets
|
63
63
|
end
|
64
64
|
|
65
65
|
require "PrivateMethods.rb"
|
66
|
-
|
66
|
+
|
67
67
|
# private_methods :PrivateMethods
|
68
68
|
|
69
|
-
end
|
69
|
+
end
|
70
70
|
|
71
71
|
RockPaperScissorsGame.new.play(2) # best out of 3
|
72
72
|
|
73
|
-
$end
|
73
|
+
$end
|
data/lib/PrivateMethods.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
private
|
1
|
+
private # make private
|
2
2
|
# add module for private methods for the rpsg calculations
|
3
3
|
module PrivateMethods
|
4
4
|
class << self
|
@@ -7,28 +7,28 @@ module PrivateMethods
|
|
7
7
|
loop do
|
8
8
|
print "\nChoose: Rock (r), Paper (p), or Scissors (s): "
|
9
9
|
choice = gets.chomp.downcase
|
10
|
-
if
|
11
|
-
return
|
12
|
-
elsif choice !=
|
10
|
+
if ProtectedConstants::NTRY_TO_SYM.key?(choice)
|
11
|
+
return ProtectedConstants::NTRY_TO_SYM[choice]
|
12
|
+
elsif choice != ProtectedConstants::VALID_ENTRIES
|
13
13
|
puts "\nThat entry is invalid. Please re-enter.\n"
|
14
14
|
else
|
15
15
|
return nil
|
16
16
|
end
|
17
|
-
end
|
18
|
-
end
|
17
|
+
end
|
18
|
+
end
|
19
19
|
# define outcomes of players choice against cpu
|
20
20
|
def player_outcome(plays)
|
21
|
-
return :WIN if
|
22
|
-
return :LOSE if
|
21
|
+
return :WIN if ProtectedConstants::WINNERS.include?(plays)
|
22
|
+
return :LOSE if ProtectedConstants::LOSERS.include?(plays)
|
23
23
|
return :TIE if !:WIN | !:LOSE
|
24
|
-
end
|
24
|
+
end
|
25
25
|
# define final outcome that gives the result of who one the whole match
|
26
|
-
def final_outcome(pl,co)
|
27
|
-
return :WIN if pl > co
|
26
|
+
def final_outcome(pl, co)
|
27
|
+
return :WIN if pl > co
|
28
28
|
return :LOSE if pl < co
|
29
|
-
return :TIE if pl = co
|
30
|
-
# there will never be a tie for the final outcome due to the code in the play() method
|
31
|
-
end
|
29
|
+
# return :TIE if pl = co
|
30
|
+
# there will never be a tie for the final outcome due to the code in the `play()` method
|
31
|
+
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
public
|
34
|
+
public # make public again
|
data/lib/rpsg/version.rb
CHANGED
data/rpsg.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
Gem::Specification.new do |spec|
|
1
|
+
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "rpsg"
|
3
|
-
spec.version = "0.3.
|
4
|
-
spec.date = "2017-10-
|
3
|
+
spec.version = "0.3.6"
|
4
|
+
spec.date = "2017-10-28" # format: YYYY/MM/DD
|
5
5
|
spec.summary = "A Rock Paper Scissors Game RubyGem"
|
6
|
-
spec.description = <<-EOF
|
7
|
-
A Ruby-programmed rock paper scissors game.
|
6
|
+
spec.description = <<-EOF
|
7
|
+
A Ruby-programmed rock paper scissors game.
|
8
8
|
Now you can play rock paper scissors on your computer whenever you'd like! :)
|
9
9
|
EOF
|
10
10
|
spec.author = "bag3318"
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.require_paths = ["lib"]
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
16
16
|
spec.post_install_message = <<-EOF
|
17
|
-
Thanks for installing my RPSG gem
|
17
|
+
Thanks for installing my RPSG gem!/
|
18
18
|
I hope you will have fun playing rock paper scissors! :)
|
19
19
|
EOF
|
20
20
|
spec.license = "MIT"
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.required_rubygems_version = ">= 2.6.0"
|
23
23
|
spec.extra_rdoc_files = ["README.md"]
|
24
24
|
spec.bindir = "bin"
|
25
|
-
spec.metadata = {
|
25
|
+
spec.metadata = {
|
26
26
|
"issue_tracker" => "https://github.com/bag3318/RPSG/issues",
|
27
27
|
"source_code" => "https://github.com/bag3318/RPSG" ,
|
28
28
|
"website" => "https://bag3318.github.io/RPSG" ,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpsg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bag3318
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,8 +110,9 @@ dependencies:
|
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: 1.11.3.9
|
113
|
-
description:
|
114
|
-
|
113
|
+
description: |2
|
114
|
+
A Ruby-programmed rock paper scissors game.
|
115
|
+
Now you can play rock paper scissors on your computer whenever you'd like! :)
|
115
116
|
email: disclosed
|
116
117
|
executables:
|
117
118
|
- rpsg
|
@@ -125,8 +126,8 @@ files:
|
|
125
126
|
- README.md
|
126
127
|
- Rakefile
|
127
128
|
- bin/rpsg
|
128
|
-
- doc/Constants.html
|
129
129
|
- doc/PrivateMethods.html
|
130
|
+
- doc/ProtectedConstants.html
|
130
131
|
- doc/RPSG.html
|
131
132
|
- doc/RockPaperScissorsGame.html
|
132
133
|
- doc/created.rid
|
@@ -247,8 +248,9 @@ metadata:
|
|
247
248
|
source_code: https://github.com/bag3318/RPSG
|
248
249
|
website: https://bag3318.github.io/RPSG
|
249
250
|
ruby_gems_page: https://rubygems.org/gems/rpsg
|
250
|
-
post_install_message:
|
251
|
-
|
251
|
+
post_install_message: |2
|
252
|
+
Thanks for installing my RPSG gem!/
|
253
|
+
I hope you will have fun playing rock paper scissors! :)
|
252
254
|
rdoc_options: []
|
253
255
|
require_paths:
|
254
256
|
- lib
|