doc/RockPaperScissors.html in RPSrb-0.0.9 vs doc/RockPaperScissors.html in RPSrb-0.1.0

- old
+ new

@@ -69,16 +69,20 @@ <div id="method-list-section" class="nav-section"> <h3>Methods</h3> <ul class="link-list" role="directory"> - <li ><a href="#method-c-continue">::continue</a> - <li ><a href="#method-c-new">::new</a> + <li ><a href="#method-i-final_outcome">#final_outcome</a> + <li ><a href="#method-i-play">#play</a> + <li ><a href="#method-i-player_choice">#player_choice</a> + + <li ><a href="#method-i-player_outcome">#player_outcome</a> + </ul> </div> </div> </nav> @@ -107,36 +111,48 @@ </header> <dl> <dt id="CHOICES">CHOICES - <dd><p>make choices constant (2d list)</p> + <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">&para;</a> <a href="#top">&uarr;</a></span></h2> + +<p>this 2d array contains all the options (in string format) the user can use</p> <dt id="COMPUTER_CHOICES">COMPUTER_CHOICES - <dd><p>define possible computer choices</p> + <dd><h2 id="label-Define+possible+computer+choices">Define possible computer choices<span><a href="#label-Define+possible+computer+choices">&para;</a> <a href="#top">&uarr;</a></span></h2> + +<p>grab the values of the hash</p> <dt id="LOSERS">LOSERS - <dd><p>map array for losers</p> + <dd><h2 id="label-Map+array+for+losers">Map array for losers<span><a href="#label-Map+array+for+losers">&para;</a> <a href="#top">&uarr;</a></span></h2> + +<p>this flips the items in the `WINNERS` 2d array</p> <dt id="NTRY_TO_SYM">NTRY_TO_SYM - <dd><p>define an entry to symbol dictionary</p> + <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">&para;</a> <a href="#top">&uarr;</a></span></h2> + +<p>this is a “hash” that contains the keys and values for winning and losing</p> <dt id="VALID_ENTRIES">VALID_ENTRIES - <dd><p>define what our valid entries out</p> + <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">&para;</a> <a href="#top">&uarr;</a></span></h3> + +<p>grab the keys of the hash</p> <dt id="WINNERS">WINNERS - <dd><p>define winners 2d array</p> + <dd><h2 id="label-Define+winners+2d+array">Define winners 2d array<span><a href="#label-Define+winners+2d+array">&para;</a> <a href="#top">&uarr;</a></span></h2> + +<p>defines winners in 2d array/list format</p> </dl> </section> @@ -161,17 +177,17 @@ </div> <div class="method-description"> - <p>define constructor for class</p> + <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">&para;</a> <a href="#top">&uarr;</a></span></h2> <div class="method-source-code" id="new-source"> - <pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 47</span> + <pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 53</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span> <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> <span class="ruby-keyword">end</span></pre> </div> @@ -183,54 +199,10 @@ </div> </section> - <section id="protected-class-5Buntitled-5D-method-details" class="method-section"> - <header> - <h3>Protected Class Methods</h3> - </header> - - - <div id="method-c-continue" class="method-detail "> - - <div class="method-heading"> - <span class="method-name">continue</span><span - class="method-args">(str1,str2,str3)</span> - - <span class="method-click-advice">click to toggle source</span> - - </div> - - - <div class="method-description"> - - <p>define entry point for game</p> - - - - - <div class="method-source-code" id="continue-source"> - <pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 35</span> -<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>) - <span class="ruby-identifier">puts</span> <span class="ruby-identifier">str1</span> - <span class="ruby-identifier">print</span> <span class="ruby-identifier">str2</span> - <span class="ruby-identifier">gets</span> - <span class="ruby-identifier">puts</span> <span class="ruby-identifier">str3</span> -<span class="ruby-keyword">end</span></pre> - </div> - - </div> - - - - - </div> - - - </section> - <section id="public-instance-5Buntitled-5D-method-details" class="method-section"> <header> <h3>Public Instance Methods</h3> </header> @@ -246,17 +218,20 @@ </div> <div class="method-description"> - <p>define play game method</p> + <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">&para;</a> <a href="#top">&uarr;</a></span></h2> + +<p>this method will be public it will also constain most of the “play” +functioonality for this game</p> <div class="method-source-code" id="play-source"> - <pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 53</span> + <pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 61</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">play</span>(<span class="ruby-identifier">winning_score</span>) <span class="ruby-keyword">while</span> <span class="ruby-ivar">@player_score</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">winning_score</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@computer_score</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">winning_score</span> <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;\nPlayer score: #{@player_score}, &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-node">&quot;Computer score: #{@computer_score}, Ties: #{@ties}.\n&quot;</span> <span class="ruby-identifier">player</span> = <span class="ruby-identifier">player_choice</span> @@ -283,9 +258,136 @@ <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;Computer wins!\n&quot;</span> <span class="ruby-keyword">end</span> <span class="ruby-identifier">print</span> <span class="ruby-string">&quot;\n[press the enter/return key to exit game]&quot;</span> <span class="ruby-identifier">gets</span> <span class="ruby-identifier">puts</span> +<span class="ruby-keyword">end</span></pre> + </div> + + </div> + + + + + </div> + + + </section> + + <section id="protected-instance-5Buntitled-5D-method-details" class="method-section"> + <header> + <h3>Protected Instance Methods</h3> + </header> + + + <div id="method-i-final_outcome" class="method-detail "> + + <div class="method-heading"> + <span class="method-name">final_outcome</span><span + class="method-args">(pl, co)</span> + + <span class="method-click-advice">click to toggle source</span> + + </div> + + + <div class="method-description"> + + <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">&para;</a> <a href="#top">&uarr;</a></span></h2> + +<p>this method is protected this will determine who wins the whole match in +the end</p> + + + + + <div class="method-source-code" id="final_outcome-source"> + <pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 125</span> +<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>) + <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">&gt;</span> <span class="ruby-identifier">co</span> + <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">&lt;</span> <span class="ruby-identifier">co</span> +<span class="ruby-keyword">end</span></pre> + </div> + + </div> + + + + + </div> + + + <div id="method-i-player_choice" class="method-detail "> + + <div class="method-heading"> + <span class="method-name">player_choice</span><span + class="method-args">()</span> + + <span class="method-click-advice">click to toggle source</span> + + </div> + + + <div class="method-description"> + + <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">&para;</a> <a href="#top">&uarr;</a></span></h2> + +<p>this method will be protected this will sanity check the user&#39;s choice</p> + + + + + <div class="method-source-code" id="player_choice-source"> + <pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 97</span> +<span class="ruby-keyword">def</span> <span class="ruby-identifier">player_choice</span> + <span class="ruby-identifier">loop</span> <span class="ruby-keyword">do</span> + <span class="ruby-identifier">print</span> <span class="ruby-string">&quot;\nChoose: Rock (r), Paper (p), or Scissors (s): &quot;</span> + <span class="ruby-identifier">choice</span> = <span class="ruby-identifier">gets</span>.<span class="ruby-identifier">chomp</span>.<span class="ruby-identifier">downcase</span> + <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>) + <span class="ruby-keyword">return</span> <span class="ruby-constant">NTRY_TO_SYM</span>[<span class="ruby-identifier">choice</span>] + <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">choice</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">VALID_ENTRIES</span> + <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;\nThat entry is invalid. Please re-enter.\n&quot;</span> + <span class="ruby-keyword">else</span> + <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> + <span class="ruby-keyword">end</span> + <span class="ruby-keyword">end</span> +<span class="ruby-keyword">end</span></pre> + </div> + + </div> + + + + + </div> + + + <div id="method-i-player_outcome" class="method-detail "> + + <div class="method-heading"> + <span class="method-name">player_outcome</span><span + class="method-args">(plays)</span> + + <span class="method-click-advice">click to toggle source</span> + + </div> + + + <div class="method-description"> + + <h2 id="method-i-player_outcome-label-Define+player+outcome">Define player outcome<span><a href="#method-i-player_outcome-label-Define+player+outcome">&para;</a> <a href="#top">&uarr;</a></span></h2> + +<p>this method is protected this defines the round outcome of the game</p> + + + + + <div class="method-source-code" id="player_outcome-source"> + <pre><span class="ruby-comment"># File lib/RockPaperScissors.rb, line 115</span> +<span class="ruby-keyword">def</span> <span class="ruby-identifier">player_outcome</span>(<span class="ruby-identifier">plays</span>) + <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>) + <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>) + <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> <span class="ruby-keyword">end</span></pre> </div> </div>