PlayRockPaperScissorsGame 2.2.9 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/bin/PlayRockPaperScissorsGame +1 -1
- data/bin/rps +1 -1
- data/docs/CODE_OF_CONDUCT.md +1 -1
- data/docs/CONTRIBUTING.md +1 -1
- data/docs/Code.md +156 -0
- data/docs/How_to_Build.md +1 -1
- data/docs/Testing.md +1 -1
- data/docs/_site/CODE_OF_CONDUCT.html +2 -1
- data/docs/_site/CONTRIBUTING.html +2 -1
- data/docs/_site/Code.html +211 -0
- data/docs/_site/How_to_Build.html +2 -1
- data/docs/_site/Testing.html +2 -1
- data/docs/_site/index.html +2 -1
- data/docs/index.md +1 -1
- data/lib/rps/version.rb +1 -1
- data/rps.gemspec +1 -1
- data/test/test_rps.rb +1 -1
- metadata +3 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba28f40c34fc5d76d0a1ea14e5be6a0e3d8dba96
|
4
|
+
data.tar.gz: 91b0527f02814723ef61a386f19769ce9dafcb81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec53391745cd73d9899800e03a5e9b0e8407e92579b51f9e3fbbc30210425debaa3963a0280ca8ea7345633a4832c93df10e496bde45005ca78743de05f202a1
|
7
|
+
data.tar.gz: 36d768cff336f64a1b881c397d892715df039c271aea568d0da5bfe264a93f8d9b3960bd0e8ade1d7e72b1a6117f9cc5f8d896e18095f397104e2fe118657e43
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -26,7 +26,7 @@ class PlayRockPaperScissorsGame
|
|
26
26
|
puts ColorizedString[str1].colorize(:color => :green) # make string output green text
|
27
27
|
print ColorizedString[str2].colorize(:color => :green)
|
28
28
|
gets # press enter or return to continue
|
29
|
-
puts
|
29
|
+
puts str3
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
data/bin/rps
CHANGED
@@ -27,7 +27,7 @@ class PlayRockPaperScissorsGame
|
|
27
27
|
puts ColorizedString[str1].colorize(:color => :green)
|
28
28
|
print ColorizedString[str2].colorize(:color => :green)
|
29
29
|
gets # press enter or return to continue
|
30
|
-
puts
|
30
|
+
puts str3
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
data/docs/CODE_OF_CONDUCT.md
CHANGED
@@ -82,4 +82,4 @@ available at [http://contributor-covenant.org/version/1/4][version]
|
|
82
82
|
|
83
83
|
## Site Nav
|
84
84
|
|
85
|
-
[Home](./) | [How to Build](How_to_Build) | [Contributing](CONTRIBUTING) | [How to Test](Testing)
|
85
|
+
[Home](./) | [How to Build](How_to_Build) | [Master Code](Code) | [Contributing](CONTRIBUTING) | [How to Test](Testing)
|
data/docs/CONTRIBUTING.md
CHANGED
@@ -41,4 +41,4 @@ Here are a few things you can do that will increase the likelihood of your pull
|
|
41
41
|
|
42
42
|
## Site Nav
|
43
43
|
|
44
|
-
[Home](./) | [How to Build](How_to_Build) | [Code of Conduct](CODE_OF_CONDUCT) | [How to Test](Testing.md)
|
44
|
+
[Home](./) | [How to Build](How_to_Build) | [Master Code](Code) | [Code of Conduct](CODE_OF_CONDUCT) | [How to Test](Testing.md)
|
data/docs/Code.md
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
---
|
2
|
+
layout: default
|
3
|
+
title: Master Code - Play Rock Paper Scissors Game
|
4
|
+
---
|
5
|
+
|
6
|
+
[//]: # (begin markdown)
|
7
|
+
|
8
|
+
# Master Code
|
9
|
+
|
10
|
+
**The master code will look like this when compiled:**
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
#!/usr/bin/env ruby
|
14
|
+
|
15
|
+
=begin
|
16
|
+
|====================================|
|
17
|
+
| Req Ruby Ver | Req Ruby Gems Ver |
|
18
|
+
|--------------|---------------------|
|
19
|
+
| >= v2.0.0 | >= v2.6.0 |
|
20
|
+
|====================================|
|
21
|
+
=end
|
22
|
+
|
23
|
+
|
24
|
+
class PlayRockPaperScissorsGame
|
25
|
+
|
26
|
+
module RockPaperScissors
|
27
|
+
VERSION = "2.3.0" # define version constant
|
28
|
+
end
|
29
|
+
|
30
|
+
# intiate the colorize gem
|
31
|
+
require "colorized_string"
|
32
|
+
ColorizedString.colors
|
33
|
+
ColorizedString.modes
|
34
|
+
|
35
|
+
module Constants
|
36
|
+
NTRY_TO_SYM = { # define constants from an entry to a symbol class
|
37
|
+
'p' => :PAPER,
|
38
|
+
'r' => :ROCK,
|
39
|
+
's' => :SCISSORS
|
40
|
+
}
|
41
|
+
VALID_ENTRIES = NTRY_TO_SYM.keys # create valid entries
|
42
|
+
COMPUTER_CHOICES = NTRY_TO_SYM.values # define computer choices
|
43
|
+
WINNERS = [ # define winners
|
44
|
+
# format: player choice, computer choice
|
45
|
+
[:SCISSORS, :PAPER],
|
46
|
+
[:PAPER, :ROCK],
|
47
|
+
[:ROCK, :SCISSORS]
|
48
|
+
]
|
49
|
+
LOSERS = WINNERS.map { |i,j| [j,i] } # this will take the original WINNERS array and flip the symbols, thus returning a loss for the user/player
|
50
|
+
INIT_STRINGS = [
|
51
|
+
ColorizedString["You are about to enter a rock-paper-scissors best of 3 match."].colorize(:green),
|
52
|
+
ColorizedString["Press the return/enter key to continue..."].colorize(:green),
|
53
|
+
""
|
54
|
+
]
|
55
|
+
end
|
56
|
+
|
57
|
+
protected_methods :Constants # make the constants module protected
|
58
|
+
|
59
|
+
class << self # define a self calling method in the parent class
|
60
|
+
def continue(str1,str2,str3) # pass in 3 parameters
|
61
|
+
puts ColorizedString[str1].colorize(:color => :green)
|
62
|
+
print ColorizedString[str2].colorize(:color => :green)
|
63
|
+
gets # press enter or return to continue
|
64
|
+
puts str3
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2]) # call continue class
|
69
|
+
|
70
|
+
def initialize # initialize variables
|
71
|
+
@player_score = @computer_score = @ties = 0
|
72
|
+
end
|
73
|
+
def play(winning_score)
|
74
|
+
while @player_score < winning_score && @computer_score < winning_score # both the computer's score and the player's score have to be less than the value passed in for the winning score at the end
|
75
|
+
puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
|
76
|
+
ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}"].colorize(:blue)
|
77
|
+
player = PrivateMethods.player_choice
|
78
|
+
computer = Constants::COMPUTER_CHOICES.sample # chooses a random option
|
79
|
+
puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}"].colorize(:blue)
|
80
|
+
puts ColorizedString["Computer chooses #{computer.to_s.downcase}"].colorize(:blue)
|
81
|
+
case PrivateMethods.player_outcome [player, computer] # define a reference call for player and computer for the arrays called in the player_outcome method
|
82
|
+
when :WIN
|
83
|
+
puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"].colorize(:red)
|
84
|
+
@player_score += 1 # @player_score = @player_score + 1
|
85
|
+
when :LOSE
|
86
|
+
puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round"].colorize(:red)
|
87
|
+
@computer_score += 1
|
88
|
+
else # since there is only 1 option left, there is no need to define when :TIE
|
89
|
+
puts ColorizedString["Tie, choose again"].colorize(:red)
|
90
|
+
@ties += 1
|
91
|
+
# since tie is not in the original pass-in argument for the while loop, it will not be affected by the winning score
|
92
|
+
end
|
93
|
+
end
|
94
|
+
puts ColorizedString["\nFinal score: player: #{@player_score}, "].colorize(:blue) +
|
95
|
+
ColorizedString["computer: #{@computer_score} (ties: #{@ties})"].colorize(:blue)
|
96
|
+
# define a case for the final outcomes
|
97
|
+
case PrivateMethods.final_outcome(@player_score, @computer_score)
|
98
|
+
when :WIN
|
99
|
+
puts ColorizedString["Player wins!"].colorize(:red)
|
100
|
+
when :LOSE
|
101
|
+
puts ColorizedString["Computer wins!"].colorize(:red)
|
102
|
+
else
|
103
|
+
puts ColorizedString["It's a tie!"].colorize(:red)
|
104
|
+
end
|
105
|
+
gets
|
106
|
+
end
|
107
|
+
|
108
|
+
module PrivateMethods
|
109
|
+
class << self # make all methods below self calling methods of this class (PlayRockPaperScissorsGame) so that the other methods will not to call their parents of these methods
|
110
|
+
def player_choice
|
111
|
+
loop do # for loop with no arguments passed in
|
112
|
+
print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green)
|
113
|
+
choice = gets.chomp.downcase # read user input and convert all to lower case
|
114
|
+
# define valid and invalid entries by using an if else-if statement(s)
|
115
|
+
if Constants::NTRY_TO_SYM.key?(choice) # if the NTRY_TO_SYM array's key is one of the keys defined in the original array
|
116
|
+
return Constants::NTRY_TO_SYM[choice] # return the users choice
|
117
|
+
elsif choice != Constants::VALID_ENTRIES # else if it is not one of the valid entries...
|
118
|
+
puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:red) # return an error message
|
119
|
+
end
|
120
|
+
# # one may also do this (albeit more useless):
|
121
|
+
# case
|
122
|
+
# when Constants::NTRY_TO_SYM.key?(choice)
|
123
|
+
# return Constants::NTRY_TO_SYM[choice]
|
124
|
+
# when choice != Constants::VALID_ENTRIES
|
125
|
+
# puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green)
|
126
|
+
# end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
def player_outcome(plays) # define method for the player's outcome while passing in a parameter of type array
|
130
|
+
return :WIN if Constants::WINNERS.include?(plays) # return a win if the one of the sub-arrays in the winners array is called
|
131
|
+
return :LOSE if Constants::LOSERS.include?(plays) # return a loss if any of the mapped sub-arrays in the losers constant is present
|
132
|
+
return :TIE if !:WIN | !:LOSE
|
133
|
+
end
|
134
|
+
def final_outcome(pl,co) # define final outcome method
|
135
|
+
return :WIN if pl > co
|
136
|
+
return :LOSE if pl < co
|
137
|
+
return :TIE if pl = co # this can never happen due to the code in the play method, but it is worth noting
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
private_methods :PrivateMethods
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
PlayRockPaperScissorsGame.new.play(2) # call the play method and pass in 3 for the winning score
|
147
|
+
|
148
|
+
```
|
149
|
+
|
150
|
+
---------
|
151
|
+
|
152
|
+
## Site Nav
|
153
|
+
|
154
|
+
[Home](./) | [How to Test](Testing) | [How to Build](How_to_Build) | [Contributing](CONTRIBUTING) | [Code of Conduct](CODE_OF_CONDUCT)
|
155
|
+
|
156
|
+
[//]: # (end markdown)
|
data/docs/How_to_Build.md
CHANGED
@@ -25,4 +25,4 @@ title: How to Build - Play Rock Paper Scissors Game
|
|
25
25
|
|
26
26
|
## Site Nav
|
27
27
|
|
28
|
-
[Home](./) | [How to Test](Testing) | [Contributing](CONTRIBUTING) | [Code of Conduct](CODE_OF_CONDUCT)
|
28
|
+
[Home](./) | [How to Test](Testing) | [Master Code](Code) | [Contributing](CONTRIBUTING) | [Code of Conduct](CODE_OF_CONDUCT)
|
data/docs/Testing.md
CHANGED
@@ -22,4 +22,4 @@ What you will need
|
|
22
22
|
|
23
23
|
## Site Nav
|
24
24
|
|
25
|
-
[Home](./) | [How to Build](How_to_Build) | [Contributing](CONTRIBUTING) | [Code of Conduct](CODE_OF_CONDUCT)
|
25
|
+
[Home](./) | [How to Build](How_to_Build) | [Master Code](Code) | [Contributing](CONTRIBUTING) | [Code of Conduct](CODE_OF_CONDUCT)
|
@@ -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=fdf5bfb64c72c2294f4da917f2a41ea4c0c76b04">
|
11
11
|
</head>
|
12
12
|
<body>
|
13
13
|
<section class="page-header">
|
@@ -113,6 +113,7 @@ available at <a href="http://contributor-covenant.org/version/1/4/">http://contr
|
|
113
113
|
<tr>
|
114
114
|
<td><a href="./">Home</a></td>
|
115
115
|
<td><a href="How_to_Build">How to Build</a></td>
|
116
|
+
<td><a href="Code">Master Code</a></td>
|
116
117
|
<td><a href="CONTRIBUTING">Contributing</a></td>
|
117
118
|
<td><a href="Testing">How to Test</a></td>
|
118
119
|
</tr>
|
@@ -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=fdf5bfb64c72c2294f4da917f2a41ea4c0c76b04">
|
11
11
|
</head>
|
12
12
|
<body>
|
13
13
|
<section class="page-header">
|
@@ -72,6 +72,7 @@
|
|
72
72
|
<tr>
|
73
73
|
<td><a href="./">Home</a></td>
|
74
74
|
<td><a href="How_to_Build">How to Build</a></td>
|
75
|
+
<td><a href="Code">Master Code</a></td>
|
75
76
|
<td><a href="CODE_OF_CONDUCT">Code of Conduct</a></td>
|
76
77
|
<td><a href="/Testing.html">How to Test</a></td>
|
77
78
|
</tr>
|
@@ -0,0 +1,211 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en-us">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<title>Master Code - Play Rock Paper Scissors Game</title>
|
6
|
+
<meta name="description" content="A Ruby Programmed Rock Paper Scissors Game"/>
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
8
|
+
<meta name="theme-color" content="#157878">
|
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=fdf5bfb64c72c2294f4da917f2a41ea4c0c76b04">
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
<section class="page-header">
|
14
|
+
<h1 class="project-name">Play Rock Paper Scissors Game</h1>
|
15
|
+
<h2 class="project-tagline">A Ruby Programmed Rock Paper Scissors Game</h2>
|
16
|
+
|
17
|
+
<a href="http://github.com/bag3318/RockPaperScissors" class="btn">View on GitHub</a>
|
18
|
+
<a href="http://github.com/bag3318/RockPaperScissors/issues" class="btn">Report a Bug</a>
|
19
|
+
|
20
|
+
|
21
|
+
<a href="http://github.com/bag3318/RockPaperScissors/zipball/gh-pages" class="btn">Download .zip</a>
|
22
|
+
<a href="http://github.com/bag3318/RockPaperScissors/tarball/gh-pages" class="btn">Download .tar.gz</a>
|
23
|
+
|
24
|
+
<br/>
|
25
|
+
|
26
|
+
<a href="#site-nav" class="btn">Site Nav</a>
|
27
|
+
|
28
|
+
</section>
|
29
|
+
|
30
|
+
<section class="main-content">
|
31
|
+
|
32
|
+
<h1 id="master-code">Master Code</h1>
|
33
|
+
|
34
|
+
<p><strong>The master code will look like this when compiled:</strong></p>
|
35
|
+
|
36
|
+
<div class="language-ruby highlighter-rouge"><pre class="highlight"><code><span class="c1">#!/usr/bin/env ruby</span>
|
37
|
+
|
38
|
+
<span class="cm">=begin
|
39
|
+
|====================================|
|
40
|
+
| Req Ruby Ver | Req Ruby Gems Ver |
|
41
|
+
|--------------|---------------------|
|
42
|
+
| >= v2.0.0 | >= v2.6.0 |
|
43
|
+
|====================================|
|
44
|
+
=end</span>
|
45
|
+
|
46
|
+
|
47
|
+
<span class="k">class</span> <span class="nc">PlayRockPaperScissorsGame</span>
|
48
|
+
|
49
|
+
<span class="k">module</span> <span class="nn">RockPaperScissors</span>
|
50
|
+
<span class="no">VERSION</span> <span class="o">=</span> <span class="s2">"2.3.0"</span> <span class="c1"># define version constant</span>
|
51
|
+
<span class="k">end</span>
|
52
|
+
|
53
|
+
<span class="c1"># intiate the colorize gem</span>
|
54
|
+
<span class="nb">require</span> <span class="s2">"colorized_string"</span>
|
55
|
+
<span class="no">ColorizedString</span><span class="p">.</span><span class="nf">colors</span>
|
56
|
+
<span class="no">ColorizedString</span><span class="p">.</span><span class="nf">modes</span>
|
57
|
+
|
58
|
+
<span class="k">module</span> <span class="nn">Constants</span>
|
59
|
+
<span class="no">NTRY_TO_SYM</span> <span class="o">=</span> <span class="p">{</span> <span class="c1"># define constants from an entry to a symbol class</span>
|
60
|
+
<span class="s1">'p'</span> <span class="o">=></span> <span class="ss">:PAPER</span><span class="p">,</span>
|
61
|
+
<span class="s1">'r'</span> <span class="o">=></span> <span class="ss">:ROCK</span><span class="p">,</span>
|
62
|
+
<span class="s1">'s'</span> <span class="o">=></span> <span class="ss">:SCISSORS</span>
|
63
|
+
<span class="p">}</span>
|
64
|
+
<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> <span class="c1"># create valid entries</span>
|
65
|
+
<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> <span class="c1"># define computer choices</span>
|
66
|
+
<span class="no">WINNERS</span> <span class="o">=</span> <span class="p">[</span> <span class="c1"># define winners</span>
|
67
|
+
<span class="c1"># format: player choice, computer choice</span>
|
68
|
+
<span class="p">[</span><span class="ss">:SCISSORS</span><span class="p">,</span> <span class="ss">:PAPER</span><span class="p">],</span>
|
69
|
+
<span class="p">[</span><span class="ss">:PAPER</span><span class="p">,</span> <span class="ss">:ROCK</span><span class="p">],</span>
|
70
|
+
<span class="p">[</span><span class="ss">:ROCK</span><span class="p">,</span> <span class="ss">:SCISSORS</span><span class="p">]</span>
|
71
|
+
<span class="p">]</span>
|
72
|
+
<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">i</span><span class="p">,</span><span class="n">j</span><span class="o">|</span> <span class="p">[</span><span class="n">j</span><span class="p">,</span><span class="n">i</span><span class="p">]</span> <span class="p">}</span> <span class="c1"># this will take the original WINNERS array and flip the symbols, thus returning a loss for the user/player</span>
|
73
|
+
<span class="no">INIT_STRINGS</span> <span class="o">=</span> <span class="p">[</span>
|
74
|
+
<span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"You are about to enter a rock-paper-scissors best of 3 match."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:green</span><span class="p">),</span>
|
75
|
+
<span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Press the return/enter key to continue..."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:green</span><span class="p">),</span>
|
76
|
+
<span class="s2">""</span>
|
77
|
+
<span class="p">]</span>
|
78
|
+
<span class="k">end</span>
|
79
|
+
|
80
|
+
<span class="nb">protected_methods</span> <span class="ss">:Constants</span> <span class="c1"># make the constants module protected</span>
|
81
|
+
|
82
|
+
<span class="k">class</span> <span class="o"><<</span> <span class="nb">self</span> <span class="c1"># define a self calling method in the parent class</span>
|
83
|
+
<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> <span class="c1"># pass in 3 parameters</span>
|
84
|
+
<span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="n">str1</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:color</span> <span class="o">=></span> <span class="ss">:green</span><span class="p">)</span>
|
85
|
+
<span class="nb">print</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="n">str2</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:color</span> <span class="o">=></span> <span class="ss">:green</span><span class="p">)</span>
|
86
|
+
<span class="nb">gets</span> <span class="c1"># press enter or return to continue</span>
|
87
|
+
<span class="nb">puts</span> <span class="n">str3</span>
|
88
|
+
<span class="k">end</span>
|
89
|
+
<span class="k">end</span>
|
90
|
+
|
91
|
+
<span class="n">continue</span><span class="p">(</span><span class="no">Constants</span><span class="o">::</span><span class="no">INIT_STRINGS</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="no">Constants</span><span class="o">::</span><span class="no">INIT_STRINGS</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="no">Constants</span><span class="o">::</span><span class="no">INIT_STRINGS</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="c1"># call continue class</span>
|
92
|
+
|
93
|
+
<span class="k">def</span> <span class="nf">initialize</span> <span class="c1"># initialize variables</span>
|
94
|
+
<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>
|
95
|
+
<span class="k">end</span>
|
96
|
+
<span class="k">def</span> <span class="nf">play</span><span class="p">(</span><span class="n">winning_score</span><span class="p">)</span>
|
97
|
+
<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> <span class="c1"># both the computer's score and the player's score have to be less than the value passed in for the winning score at the end</span>
|
98
|
+
<span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Player score: </span><span class="si">#{</span><span class="vi">@player_score</span><span class="si">}</span><span class="s2">, "</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span> <span class="o">+</span>
|
99
|
+
<span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Computer score: </span><span class="si">#{</span><span class="vi">@computer_score</span><span class="si">}</span><span class="s2">, Ties: </span><span class="si">#{</span><span class="vi">@ties</span><span class="si">}</span><span class="s2">"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
|
100
|
+
<span class="n">player</span> <span class="o">=</span> <span class="no">PrivateMethods</span><span class="p">.</span><span class="nf">player_choice</span>
|
101
|
+
<span class="n">computer</span> <span class="o">=</span> <span class="no">Constants</span><span class="o">::</span><span class="no">COMPUTER_CHOICES</span><span class="p">.</span><span class="nf">sample</span> <span class="c1"># chooses a random option</span>
|
102
|
+
<span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Player chooses </span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
|
103
|
+
<span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Computer chooses </span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
|
104
|
+
<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> <span class="c1"># define a reference call for player and computer for the arrays called in the player_outcome method</span>
|
105
|
+
<span class="k">when</span> <span class="ss">:WIN</span>
|
106
|
+
<span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">capitalize</span><span class="si">}</span><span class="s2"> beats </span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">, player wins the round"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
|
107
|
+
<span class="vi">@player_score</span> <span class="o">+=</span> <span class="mi">1</span> <span class="c1"># @player_score = @player_score + 1</span>
|
108
|
+
<span class="k">when</span> <span class="ss">:LOSE</span>
|
109
|
+
<span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="si">#{</span><span class="n">computer</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">capitalize</span><span class="si">}</span><span class="s2"> beats </span><span class="si">#{</span><span class="n">player</span><span class="p">.</span><span class="nf">to_s</span><span class="p">.</span><span class="nf">downcase</span><span class="si">}</span><span class="s2">, computer wins the round"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
|
110
|
+
<span class="vi">@computer_score</span> <span class="o">+=</span> <span class="mi">1</span>
|
111
|
+
<span class="k">else</span> <span class="c1"># since there is only 1 option left, there is no need to define when :TIE</span>
|
112
|
+
<span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Tie, choose again"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
|
113
|
+
<span class="vi">@ties</span> <span class="o">+=</span> <span class="mi">1</span>
|
114
|
+
<span class="c1"># since tie is not in the original pass-in argument for the while loop, it will not be affected by the winning score</span>
|
115
|
+
<span class="k">end</span>
|
116
|
+
<span class="k">end</span>
|
117
|
+
<span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Final score: player: </span><span class="si">#{</span><span class="vi">@player_score</span><span class="si">}</span><span class="s2">, "</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span> <span class="o">+</span>
|
118
|
+
<span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"computer: </span><span class="si">#{</span><span class="vi">@computer_score</span><span class="si">}</span><span class="s2"> (ties: </span><span class="si">#{</span><span class="vi">@ties</span><span class="si">}</span><span class="s2">)"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:blue</span><span class="p">)</span>
|
119
|
+
<span class="c1"># define a case for the final outcomes </span>
|
120
|
+
<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>
|
121
|
+
<span class="k">when</span> <span class="ss">:WIN</span>
|
122
|
+
<span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Player wins!"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
|
123
|
+
<span class="k">when</span> <span class="ss">:LOSE</span>
|
124
|
+
<span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Computer wins!"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
|
125
|
+
<span class="k">else</span>
|
126
|
+
<span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"It's a tie!"</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span>
|
127
|
+
<span class="k">end</span>
|
128
|
+
<span class="nb">gets</span>
|
129
|
+
<span class="k">end</span>
|
130
|
+
|
131
|
+
<span class="k">module</span> <span class="nn">PrivateMethods</span>
|
132
|
+
<span class="k">class</span> <span class="o"><<</span> <span class="nb">self</span> <span class="c1"># make all methods below self calling methods of this class (PlayRockPaperScissorsGame) so that the other methods will not to call their parents of these methods</span>
|
133
|
+
<span class="k">def</span> <span class="nf">player_choice</span>
|
134
|
+
<span class="kp">loop</span> <span class="k">do</span> <span class="c1"># for loop with no arguments passed in</span>
|
135
|
+
<span class="nb">print</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"Choose rock (r), paper (p) or scissors (s): "</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:green</span><span class="p">)</span>
|
136
|
+
<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> <span class="c1"># read user input and convert all to lower case</span>
|
137
|
+
<span class="c1"># define valid and invalid entries by using an if else-if statement(s)</span>
|
138
|
+
<span class="k">if</span> <span class="no">Constants</span><span class="o">::</span><span class="no">NTRY_TO_SYM</span><span class="p">.</span><span class="nf">key?</span><span class="p">(</span><span class="n">choice</span><span class="p">)</span> <span class="c1"># if the NTRY_TO_SYM array's key is one of the keys defined in the original array</span>
|
139
|
+
<span class="k">return</span> <span class="no">Constants</span><span class="o">::</span><span class="no">NTRY_TO_SYM</span><span class="p">[</span><span class="n">choice</span><span class="p">]</span> <span class="c1"># return the users choice</span>
|
140
|
+
<span class="k">elsif</span> <span class="n">choice</span> <span class="o">!=</span> <span class="no">Constants</span><span class="o">::</span><span class="no">VALID_ENTRIES</span> <span class="c1"># else if it is not one of the valid entries...</span>
|
141
|
+
<span class="nb">puts</span> <span class="no">ColorizedString</span><span class="p">[</span><span class="s2">"That entry is invalid. Please re-enter."</span><span class="p">].</span><span class="nf">colorize</span><span class="p">(</span><span class="ss">:red</span><span class="p">)</span> <span class="c1"># return an error message</span>
|
142
|
+
<span class="k">end</span>
|
143
|
+
<span class="c1"># # one may also do this (albeit more useless):</span>
|
144
|
+
<span class="c1"># case</span>
|
145
|
+
<span class="c1"># when Constants::NTRY_TO_SYM.key?(choice)</span>
|
146
|
+
<span class="c1"># return Constants::NTRY_TO_SYM[choice]</span>
|
147
|
+
<span class="c1"># when choice != Constants::VALID_ENTRIES</span>
|
148
|
+
<span class="c1"># puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green) </span>
|
149
|
+
<span class="c1"># end</span>
|
150
|
+
<span class="k">end</span>
|
151
|
+
<span class="k">end</span>
|
152
|
+
<span class="k">def</span> <span class="nf">player_outcome</span><span class="p">(</span><span class="n">plays</span><span class="p">)</span> <span class="c1"># define method for the player's outcome while passing in a parameter of type array</span>
|
153
|
+
<span class="k">return</span> <span class="ss">:WIN</span> <span class="k">if</span> <span class="no">Constants</span><span class="o">::</span><span class="no">WINNERS</span><span class="p">.</span><span class="nf">include?</span><span class="p">(</span><span class="n">plays</span><span class="p">)</span> <span class="c1"># return a win if the one of the sub-arrays in the winners array is called</span>
|
154
|
+
<span class="k">return</span> <span class="ss">:LOSE</span> <span class="k">if</span> <span class="no">Constants</span><span class="o">::</span><span class="no">LOSERS</span><span class="p">.</span><span class="nf">include?</span><span class="p">(</span><span class="n">plays</span><span class="p">)</span> <span class="c1"># return a loss if any of the mapped sub-arrays in the losers constant is present</span>
|
155
|
+
<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>
|
156
|
+
<span class="k">end</span>
|
157
|
+
<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> <span class="c1"># define final outcome method</span>
|
158
|
+
<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>
|
159
|
+
<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>
|
160
|
+
<span class="k">return</span> <span class="ss">:TIE</span> <span class="k">if</span> <span class="n">pl</span> <span class="o">=</span> <span class="n">co</span> <span class="c1"># this can never happen due to the code in the play method, but it is worth noting</span>
|
161
|
+
<span class="k">end</span>
|
162
|
+
<span class="k">end</span>
|
163
|
+
<span class="k">end</span>
|
164
|
+
|
165
|
+
<span class="nb">private_methods</span> <span class="ss">:PrivateMethods</span>
|
166
|
+
|
167
|
+
<span class="k">end</span>
|
168
|
+
|
169
|
+
<span class="no">PlayRockPaperScissorsGame</span><span class="p">.</span><span class="nf">new</span><span class="p">.</span><span class="nf">play</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="c1"># call the play method and pass in 3 for the winning score</span>
|
170
|
+
|
171
|
+
</code></pre>
|
172
|
+
</div>
|
173
|
+
|
174
|
+
<hr />
|
175
|
+
|
176
|
+
<h2 id="site-nav">Site Nav</h2>
|
177
|
+
|
178
|
+
<table>
|
179
|
+
<tbody>
|
180
|
+
<tr>
|
181
|
+
<td><a href="./">Home</a></td>
|
182
|
+
<td><a href="Testing">How to Test</a></td>
|
183
|
+
<td><a href="How_to_Build">How to Build</a></td>
|
184
|
+
<td><a href="CONTRIBUTING">Contributing</a></td>
|
185
|
+
<td><a href="CODE_OF_CONDUCT">Code of Conduct</a></td>
|
186
|
+
</tr>
|
187
|
+
</tbody>
|
188
|
+
</table>
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
<footer class="site-footer">
|
193
|
+
|
194
|
+
<span class="site-footer-owner"><a href="http://github.com/bag3318/RockPaperScissors">RockPaperScissors</a> is maintained by <a href="http://github.com/bag3318">bag3318</a>.</span>
|
195
|
+
|
196
|
+
</footer>
|
197
|
+
</section>
|
198
|
+
|
199
|
+
|
200
|
+
<script type="text/javascript">
|
201
|
+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
202
|
+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
203
|
+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
204
|
+
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
205
|
+
|
206
|
+
ga('create', 'true', 'auto');
|
207
|
+
ga('send', 'pageview');
|
208
|
+
</script>
|
209
|
+
|
210
|
+
</body>
|
211
|
+
</html>
|
@@ -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=fdf5bfb64c72c2294f4da917f2a41ea4c0c76b04">
|
11
11
|
</head>
|
12
12
|
<body>
|
13
13
|
<section class="page-header">
|
@@ -62,6 +62,7 @@
|
|
62
62
|
<tr>
|
63
63
|
<td><a href="./">Home</a></td>
|
64
64
|
<td><a href="Testing">How to Test</a></td>
|
65
|
+
<td><a href="Code">Master Code</a></td>
|
65
66
|
<td><a href="CONTRIBUTING">Contributing</a></td>
|
66
67
|
<td><a href="CODE_OF_CONDUCT">Code of Conduct</a></td>
|
67
68
|
</tr>
|
data/docs/_site/Testing.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=fdf5bfb64c72c2294f4da917f2a41ea4c0c76b04">
|
11
11
|
</head>
|
12
12
|
<body>
|
13
13
|
<section class="page-header">
|
@@ -54,6 +54,7 @@
|
|
54
54
|
<tr>
|
55
55
|
<td><a href="./">Home</a></td>
|
56
56
|
<td><a href="How_to_Build">How to Build</a></td>
|
57
|
+
<td><a href="Code">Master Code</a></td>
|
57
58
|
<td><a href="CONTRIBUTING">Contributing</a></td>
|
58
59
|
<td><a href="CODE_OF_CONDUCT">Code of Conduct</a></td>
|
59
60
|
</tr>
|
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=fdf5bfb64c72c2294f4da917f2a41ea4c0c76b04">
|
11
11
|
</head>
|
12
12
|
<body>
|
13
13
|
<section class="page-header">
|
@@ -112,6 +112,7 @@
|
|
112
112
|
<tr>
|
113
113
|
<td><a href="Testing">How to Test</a></td>
|
114
114
|
<td><a href="How_to_Build">How to Build</a></td>
|
115
|
+
<td><a href="Code">Master Code</a></td>
|
115
116
|
<td><a href="CONTRIBUTING">Contributing</a></td>
|
116
117
|
<td><a href="CODE_OF_CONDUCT">Code of Conduct</a></td>
|
117
118
|
</tr>
|
data/docs/index.md
CHANGED
@@ -55,6 +55,6 @@ How to Run and Install
|
|
55
55
|
|
56
56
|
## Site Nav
|
57
57
|
|
58
|
-
[How to Test](Testing) | [How to Build](How_to_Build) | [Contributing](CONTRIBUTING) | [Code of Conduct](CODE_OF_CONDUCT)
|
58
|
+
[How to Test](Testing) | [How to Build](How_to_Build) | [Master Code](Code) | [Contributing](CONTRIBUTING) | [Code of Conduct](CODE_OF_CONDUCT)
|
59
59
|
|
60
60
|
[//]: # (end)
|
data/lib/rps/version.rb
CHANGED
data/rps.gemspec
CHANGED
data/test/test_rps.rb
CHANGED
@@ -22,7 +22,7 @@ class RakeTest # create test
|
|
22
22
|
puts ColorizedString[str1].colorize(:color => :green)
|
23
23
|
print ColorizedString[str2].colorize(:color => :green)
|
24
24
|
gets
|
25
|
-
puts
|
25
|
+
puts str3
|
26
26
|
end
|
27
27
|
end
|
28
28
|
continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: PlayRockPaperScissorsGame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bag3318
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- certs/gem-public_cert.pem
|
123
123
|
- docs/CODE_OF_CONDUCT.md
|
124
124
|
- docs/CONTRIBUTING.md
|
125
|
+
- docs/Code.md
|
125
126
|
- docs/Gemfile
|
126
127
|
- docs/How_to_Build.md
|
127
128
|
- docs/LICENSE
|
@@ -134,6 +135,7 @@ files:
|
|
134
135
|
- docs/_sass/variables.scss
|
135
136
|
- docs/_site/CODE_OF_CONDUCT.html
|
136
137
|
- docs/_site/CONTRIBUTING.html
|
138
|
+
- docs/_site/Code.html
|
137
139
|
- docs/_site/How_to_Build.html
|
138
140
|
- docs/_site/Testing.html
|
139
141
|
- docs/_site/assets/css/style.css
|
metadata.gz.sig
CHANGED
Binary file
|