PlayRockPaperScissorsGame 2.2.8 → 2.2.9
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 +1 -4
- data/.gitignore +1 -0
- data/bin/PlayRockPaperScissorsGame +7 -8
- data/bin/rps +1 -1
- data/lib/Constants.rb +4 -3
- data/lib/PrivateMethods.rb +1 -1
- data/lib/rps/version.rb +1 -1
- data/rps.gemspec +1 -1
- data.tar.gz.sig +0 -0
- metadata +1 -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: c55b786ac8edef96c4a2eeb17aba34b5d94df509
|
4
|
+
data.tar.gz: 9deeacd39145b469bcd0748ab92b1aec14a41762
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 465a65325bcf84289192e51980d10ee1310c0b26dd4164a69c45d1ba43137934b9cc4caa7fa793bcb4c77399660bdb37713f2bbc51f51e2dc2ae9cd8f03aebf1
|
7
|
+
data.tar.gz: 1ae6a4d92bb7808cfe4e2ad6ab5f019c076ee54c36597dfd671409282dcf607d84c034de0bd3b1b1ee1b2a1ec92a09d5badd99719a3087f57bb8772e81452f42
|
checksums.yaml.gz.sig
CHANGED
@@ -1,4 +1 @@
|
|
1
|
-
|
2
|
-
�L'��I���x<�Su�����_�k������i�����5fF������ؐ��3��\E���L�
|
3
|
-
�c�fy� ��9�.Di������)<*���-��7�qm/���/6�Dw>�5Dr�G��{*���_:
|
4
|
-
f}���ۺ���+��1��G'm{���1��OޟR��2�H��ѳ���J=:1<.��>�ʥ�r:)]��b��;v�
|
1
|
+
L<͒yǢk�0ўR<�-�n�sm��~���;��R�� xŦxt�M�ZK�m8��`��X�ߚ�1�����V�F����1���8m�r�j��a��r�/�Pj��dB;���תf�_�93��6:�#~Aekw߄�%,�[���P�d��t��ي�%8�b{�tD��1�����g`�R�M$9���A���0�f�'j���Y���9���R���'+�R𐋁>d�6�1 �Y|3�I�uN���Vn�sit�
|
data/.gitignore
CHANGED
@@ -12,7 +12,6 @@
|
|
12
12
|
class PlayRockPaperScissorsGame
|
13
13
|
|
14
14
|
require_relative "./../lib/rps/version.rb"
|
15
|
-
|
16
15
|
# intiate the colorize gem
|
17
16
|
require "colorized_string"
|
18
17
|
ColorizedString.colors
|
@@ -22,29 +21,29 @@ class PlayRockPaperScissorsGame
|
|
22
21
|
|
23
22
|
protected_methods :Constants
|
24
23
|
|
25
|
-
class << self
|
24
|
+
class << self # make continue a self calling method
|
26
25
|
def continue(str1,str2,str3) # pass in 3 parameters
|
27
|
-
puts ColorizedString[str1].colorize(:color => :green)
|
26
|
+
puts ColorizedString[str1].colorize(:color => :green) # make string output green text
|
28
27
|
print ColorizedString[str2].colorize(:color => :green)
|
29
28
|
gets # press enter or return to continue
|
30
29
|
puts ColorizedString[str3].colorize(:color => :green)
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
|
-
continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2])
|
33
|
+
continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2]) # define passed in parameters
|
35
34
|
|
36
35
|
def initialize
|
37
|
-
@player_score = @computer_score = @ties = 0
|
36
|
+
@player_score = @computer_score = @ties = 0 # intialize variables
|
38
37
|
end
|
39
38
|
def play(winning_score)
|
40
|
-
while @player_score < winning_score && @computer_score < winning_score
|
39
|
+
while @player_score < winning_score && @computer_score < winning_score # both the player's and the computer's score have to be less than 3
|
41
40
|
puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
|
42
41
|
ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}"].colorize(:blue)
|
43
42
|
player = PrivateMethods.player_choice
|
44
|
-
computer = Constants::COMPUTER_CHOICES.sample # chooses a random option
|
43
|
+
computer = Constants::COMPUTER_CHOICES.sample # chooses a random option for the computer
|
45
44
|
puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}"].colorize(:blue)
|
46
45
|
puts ColorizedString["Computer chooses #{computer.to_s.downcase}"].colorize(:blue)
|
47
|
-
case PrivateMethods.player_outcome [player, computer]
|
46
|
+
case PrivateMethods.player_outcome [player, computer] # pass in player and computer for the contants arrays
|
48
47
|
when :WIN
|
49
48
|
puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"].colorize(:red)
|
50
49
|
@player_score += 1
|
data/bin/rps
CHANGED
data/lib/Constants.rb
CHANGED
@@ -7,13 +7,14 @@ module Constants
|
|
7
7
|
'r' => :ROCK,
|
8
8
|
's' => :SCISSORS
|
9
9
|
}
|
10
|
-
VALID_ENTRIES = NTRY_TO_SYM.keys
|
11
|
-
COMPUTER_CHOICES = NTRY_TO_SYM.values
|
10
|
+
VALID_ENTRIES = NTRY_TO_SYM.keys # create valid entries
|
11
|
+
COMPUTER_CHOICES = NTRY_TO_SYM.values # define computer choices
|
12
12
|
WINNERS = [
|
13
|
+
# format: player choice, computer choice
|
13
14
|
[:SCISSORS, :PAPER],
|
14
15
|
[:PAPER, :ROCK],
|
15
16
|
[:ROCK, :SCISSORS]
|
16
|
-
]
|
17
|
+
]
|
17
18
|
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
|
18
19
|
INIT_STRINGS = [
|
19
20
|
ColorizedString["You are about to enter a rock-paper-scissors best of 3 match."].colorize(:green),
|
data/lib/PrivateMethods.rb
CHANGED
@@ -10,7 +10,7 @@ module PrivateMethods
|
|
10
10
|
if Constants::NTRY_TO_SYM.key?(choice)
|
11
11
|
return Constants::NTRY_TO_SYM[choice]
|
12
12
|
elsif choice != Constants::VALID_ENTRIES
|
13
|
-
puts ColorizedString["That entry is invalid. Please re-enter"].colorize(:
|
13
|
+
puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:red)
|
14
14
|
end
|
15
15
|
# # one may also do this:
|
16
16
|
# case
|
data/lib/rps/version.rb
CHANGED
data/rps.gemspec
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|