PlayRockPaperScissorsGame 2.2.4 → 2.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c1015020d251332e0b2be0db5ac330a37cc46d9
4
- data.tar.gz: 6dc05775f91dd30253190f37253346dfd4ca761c
3
+ metadata.gz: 4b3fc06f4d65bfd48e21b4426e9eb132c07a149b
4
+ data.tar.gz: ae5db8785077f8f2f894822d246f5abee54ee156
5
5
  SHA512:
6
- metadata.gz: 866311fa990c33a9e77772e9c99db464e690e0c8ed78db3559c0b7b2ef061a004060f71fe87f468e4f6b60b242067225befa3430853a47bf6182e74498e235c0
7
- data.tar.gz: f3986f9fe53c3dc4adf444a664582a704cda75f307cdd3c18a7e01c32f4997808c50770b8c0ab0220e4f620dfee283e27a30bb8e2d2c854cc70d23e047f8cc30
6
+ metadata.gz: 51a2b1dea0d717090474b09721b9df34ab1e8eb55649f75627031e01ed69977b461988c35cdd6238980ec05d20156d52c0634f038f307899262c057505c94b16
7
+ data.tar.gz: d19e73ab940e73cb8b3703f49f844cff8c61cb457e685c1f1823004b3f858519c691aa8ed4068391ad4ee699511f4d036d5021fa0b3f56fa67f4abeda89c33f3
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -4,27 +4,23 @@
4
4
  |====================================|
5
5
  | Req Ruby Ver | Req Ruby Gems Ver |
6
6
  |--------------|---------------------|
7
- | >= v2.0.0 | >= v2.6.10 |
7
+ | >= v2.0.0 | >= v2.6.0 |
8
8
  |====================================|
9
9
  =end
10
10
 
11
11
 
12
- class PlayRockPaperScissorsGame
12
+ class PlayRockPaperScissorsGame
13
+
14
+ require_relative "./../lib/rps/version.rb"
13
15
 
14
16
  # intiate the colorize gem
15
17
  require "colorized_string"
16
18
  ColorizedString.colors
17
19
  ColorizedString.modes
18
20
 
19
- module Constants
20
- protected # make constants protected
21
- NTRY_TO_SYM = { 'p' => :PAPER, 'r' => :ROCK, 's' => :SCISSORS }
22
- VALID_ENTRIES = NTRY_TO_SYM.keys
23
- COMPUTER_CHOICES = NTRY_TO_SYM.values
24
- WINNERS = [[:SCISSORS, :PAPER], [:PAPER, :ROCK], [:ROCK, :SCISSORS]] # format: player choice, computer choice
25
- 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
26
- INIT_STRINGS = ["You are about to enter a rock-paper-scissors best of 3 match.", "Press the return/enter key to continue...", ""]
27
- end
21
+ require_relative "./../lib/Constants.rb"
22
+
23
+ protected_methods :Constants
28
24
 
29
25
  class << self
30
26
  def continue(str1,str2,str3) # pass in 3 parameters
@@ -34,7 +30,9 @@ class PlayRockPaperScissorsGame
34
30
  puts ColorizedString[str3].colorize(:color => :green)
35
31
  end
36
32
  end
33
+
37
34
  continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2])
35
+
38
36
  def initialize
39
37
  @player_score = @computer_score = @ties = 0
40
38
  end
@@ -70,39 +68,11 @@ class PlayRockPaperScissorsGame
70
68
  end
71
69
  gets
72
70
  end
73
- module PrivateMethods
74
- private
75
- class << self
76
- def player_choice
77
- loop do
78
- print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green)
79
- choice = gets.chomp.downcase
80
- if Constants::NTRY_TO_SYM.key?(choice)
81
- return Constants::NTRY_TO_SYM[choice]
82
- elsif choice != Constants::VALID_ENTRIES
83
- puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green)
84
- end
85
- # # one may also do this:
86
- # case
87
- # when Constants::NTRY_TO_SYM.key?(choice)
88
- # return Constants::NTRY_TO_SYM[choice]
89
- # when choice != Constants::VALID_ENTRIES
90
- # puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green)
91
- # end
92
- end
93
- end
94
- def player_outcome(plays)
95
- return :WIN if Constants::WINNERS.include?(plays)
96
- return :LOSE if Constants::LOSERS.include?(plays)
97
- return :TIE if !:WIN | !:LOSE
98
- end
99
- def final_outcome(pl,co)
100
- return :WIN if pl > co
101
- return :LOSE if pl < co
102
- return :TIE if pl = co
103
- end
104
- end
105
- end
71
+
72
+ require_relative "./../lib/PrivateMethods.rb"
73
+
74
+ private_methods :PrivateMethods
75
+
106
76
  end
107
77
 
108
78
  PlayRockPaperScissorsGame.new.play(2) # best of 3
data/bin/rps CHANGED
@@ -4,36 +4,35 @@
4
4
  |====================================|
5
5
  | Req Ruby Ver | Req Ruby Gems Ver |
6
6
  |--------------|---------------------|
7
- | >= v2.0.0 | >= v2.6.10 |
7
+ | >= v2.0.0 | >= v2.6.0 |
8
8
  |====================================|
9
9
  =end
10
10
 
11
11
 
12
- class PlayRockPaperScissorsGame
12
+ class PlayRockPaperScissorsGame
13
13
 
14
+ require_relative "./../lib/rps/version.rb"
15
+
16
+ # intiate the colorize gem
14
17
  require "colorized_string"
15
18
  ColorizedString.colors
16
19
  ColorizedString.modes
17
20
 
18
- module Constants
19
- protected
20
- NTRY_TO_SYM = { 'p' => :PAPER, 'r' => :ROCK, 's' => :SCISSORS }
21
- VALID_ENTRIES = NTRY_TO_SYM.keys
22
- COMPUTER_CHOICES = NTRY_TO_SYM.values
23
- WINNERS = [[:SCISSORS, :PAPER], [:PAPER, :ROCK], [:ROCK, :SCISSORS]] # format: player choice, computer choice
24
- 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
25
- INIT_STRINGS = ["You are about to enter a rock-paper-scissors best of 3 match.", "Press the return/enter key to continue...", ""]
26
- end
21
+ require_relative "./../lib/Constants.rb"
22
+
23
+ protected_methods :Constants
27
24
 
28
25
  class << self
29
- def continue(str1, str2, str3)
26
+ def continue(str1,str2,str3) # pass in 3 parameters
30
27
  puts ColorizedString[str1].colorize(:color => :green)
31
28
  print ColorizedString[str2].colorize(:color => :green)
32
- gets
29
+ gets # press enter or return to continue
33
30
  puts ColorizedString[str3].colorize(:color => :green)
34
31
  end
35
32
  end
33
+
36
34
  continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2])
35
+
37
36
  def initialize
38
37
  @player_score = @computer_score = @ties = 0
39
38
  end
@@ -42,7 +41,7 @@ class PlayRockPaperScissorsGame
42
41
  puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
43
42
  ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}"].colorize(:blue)
44
43
  player = PrivateMethods.player_choice
45
- computer = Constants::COMPUTER_CHOICES.sample
44
+ computer = Constants::COMPUTER_CHOICES.sample # chooses a random option
46
45
  puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}"].colorize(:blue)
47
46
  puts ColorizedString["Computer chooses #{computer.to_s.downcase}"].colorize(:blue)
48
47
  case PrivateMethods.player_outcome [player, computer]
@@ -69,40 +68,11 @@ class PlayRockPaperScissorsGame
69
68
  end
70
69
  gets
71
70
  end
72
- module PrivateMethods
73
- private
74
- class << self
75
- def player_choice
76
- loop do
77
- print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green)
78
- choice = gets.chomp.downcase
79
- if Constants::NTRY_TO_SYM.key?(choice)
80
- return Constants::NTRY_TO_SYM[choice]
81
- elsif choice != Constants::VALID_ENTRIES
82
- puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green)
83
- end
84
- # # one may also do this:
85
- # case
86
- # when Constants::NTRY_TO_SYM.key?(choice)
87
- # return Constants::NTRY_TO_SYM[choice]
88
- # when choice != Constants::VALID_ENTRIES
89
- # puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green)
90
- # end
91
- end
92
- end
93
- def player_outcome(plays)
94
- return :WIN if Constants::WINNERS.include?(plays)
95
- return :LOSE if Constants::LOSERS.include?(plays)
96
- return :TIE if !:WIN | !:LOSE
97
- end
98
- def final_outcome(pl, co)
99
- return :WIN if pl > co
100
- return :LOSE if pl < co
101
- return :TIE if pl = co
102
- end
103
- end
104
- end
105
- end
106
71
 
107
- PlayRockPaperScissorsGame.new.play(2) # best of 3
72
+ require_relative "./../lib/PrivateMethods.rb"
73
+
74
+ private_methods :PrivateMethods
75
+
76
+ end
108
77
 
78
+ PlayRockPaperScissorsGame.new.play(2) # best of 3
@@ -2,7 +2,6 @@ require "colorized_string"
2
2
  ColorizedString.colors
3
3
  ColorizedString.modes
4
4
  module Constants
5
- protected
6
5
  NTRY_TO_SYM = {
7
6
  'p' => :PAPER,
8
7
  'r' => :ROCK,
@@ -2,12 +2,11 @@ require "colorized_string"
2
2
  ColorizedString.colors
3
3
  ColorizedString.modes
4
4
  module PrivateMethods
5
- private
6
5
  class << self
7
6
  def player_choice
8
7
  loop do
9
8
  print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green)
10
- choice = gets.chomp.downcasec
9
+ choice = gets.chomp.downcase
11
10
  if Constants::NTRY_TO_SYM.key?(choice)
12
11
  return Constants::NTRY_TO_SYM[choice]
13
12
  elsif choice != Constants::VALID_ENTRIES
@@ -27,10 +26,10 @@ module PrivateMethods
27
26
  return :LOSE if Constants::LOSERS.include?(plays)
28
27
  return :TIE if !:WIN | !:LOSE
29
28
  end
30
- def final_outcome(pl, co)
29
+ def final_outcome(pl,co)
31
30
  return :WIN if pl > co
32
31
  return :LOSE if pl < co
33
32
  return :TIE if pl = co
34
33
  end
35
34
  end
36
- end
35
+ end
data/lib/rps/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module PlayRockPaperScissorsGame
2
- VERSION = "2.2.4"
1
+ module RockPaperScissors
2
+ VERSION = "2.2.7"
3
3
  end
data/rps.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "PlayRockPaperScissorsGame"
3
- spec.version = "2.2.4"
3
+ spec.version = "2.2.7"
4
4
  spec.date = "2017-04-04"
5
5
  spec.summary = "A Rock Paper Scissors Ruby Gem"
6
6
  spec.description = <<-EOF
data/test/test_rps.rb CHANGED
@@ -2,27 +2,23 @@
2
2
  |====================================|
3
3
  | Req Ruby Ver | Req Ruby Gems Ver |
4
4
  |--------------|---------------------|
5
- | >= v2.0.0 | >= v2.6.10 |
5
+ | >= v2.0.0 | >= v2.6.0 |
6
6
  |====================================|
7
7
  =end
8
8
 
9
9
  class RakeTest # create test
10
10
 
11
+ require_relative "./../lib/rps/version.rb"
12
+
11
13
  require "colorized_string"
12
14
  ColorizedString.colors
13
15
  ColorizedString.modes
14
16
 
15
- module Constants
16
- protected
17
- NTRY_TO_SYM = { 'p' => :PAPER, 'r' => :ROCK, 's' => :SCISSORS }
18
- VALID_ENTRIES = NTRY_TO_SYM.keys
19
- COMPUTER_CHOICES = NTRY_TO_SYM.values
20
- WINNERS = [[:SCISSORS, :PAPER], [:PAPER, :ROCK], [:ROCK, :SCISSORS]] # format: player choice, computer choice
21
- 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
22
- INIT_STRINGS = ["You are about to enter a rock-paper-scissors best of 3 match.", "Press the return/enter key to continue...", ""]
23
- end
17
+ require_relative "./../lib/Constants.rb"
18
+ protected_methods :Constants
19
+
24
20
  class << self
25
- def continue(str1, str2, str3)
21
+ def continue(str1,str2,str3)
26
22
  puts ColorizedString[str1].colorize(:color => :green)
27
23
  print ColorizedString[str2].colorize(:color => :green)
28
24
  gets
@@ -65,39 +61,9 @@ class RakeTest # create test
65
61
  end
66
62
  gets
67
63
  end
68
- module PrivateMethods
69
- private
70
- class << self
71
- def player_choice
72
- loop do
73
- print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green)
74
- choice = gets.chomp.downcase
75
- if Constants::NTRY_TO_SYM.key?(choice)
76
- return Constants::NTRY_TO_SYM[choice]
77
- elsif choice != Constants::VALID_ENTRIES
78
- puts ColorizedString["That entry is invalid. Please re-enter"].colorize(:green)
79
- end
80
- # # one may also do this:
81
- # case
82
- # when Constants::NTRY_TO_SYM.key?(choice)
83
- # return Constants::NTRY_TO_SYM[choice]
84
- # when choice != Constants::VALID_ENTRIES
85
- # puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green)
86
- # end
87
- end
88
- end
89
- def player_outcome(plays)
90
- return :WIN if Constants::WINNERS.include?(plays)
91
- return :LOSE if Constants::LOSERS.include?(plays)
92
- return :TIE if !:WIN | !:LOSE
93
- end
94
- def final_outcome(pl, co)
95
- return :WIN if pl > co
96
- return :LOSE if pl < co
97
- return :TIE if pl = co
98
- end
99
- end
100
- end
64
+ require_relative "./../lib/PrivateMethods.rb"
65
+ private_methods :PrivateMethods
66
+
101
67
  end
102
68
 
103
69
  RakeTest.new.testPlay(2) # best of 3
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.2.4
4
+ version: 2.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - bag3318
@@ -153,9 +153,8 @@ files:
153
153
  - exec/rps.bash
154
154
  - exec/run.bat
155
155
  - exec/uninstall.sh
156
- - lib/ref/Constants.rb
157
- - lib/ref/PrivateMethods.rb
158
- - lib/rps.rb
156
+ - lib/Constants.rb
157
+ - lib/PrivateMethods.rb
159
158
  - lib/rps/version.rb
160
159
  - rps.gemspec
161
160
  - test/test_rps.rb
metadata.gz.sig CHANGED
Binary file
data/lib/rps.rb DELETED
@@ -1,66 +0,0 @@
1
- =begin
2
- |====================================|
3
- | Req Ruby Ver | Req Ruby Gems Ver |
4
- |--------------|---------------------|
5
- | >= v2.0.0 | >= v2.6.10 |
6
- |====================================|
7
- =end
8
-
9
- class PlayRockPaperScissorsGame
10
-
11
- require "colorized_string"
12
- ColorizedString.colors
13
- ColorizedString.modes
14
-
15
- require "ref/Constants.rb"
16
-
17
- class << self
18
- def continue(str1, str2, str3)
19
- puts ColorizedString[str1].colorize(:color => :green)
20
- print ColorizedString[str2].colorize(:color => :green)
21
- gets
22
- puts ColorizedString[str3].colorize(:color => :green)
23
- end
24
- end
25
- continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2])
26
- def initialize
27
- @player_score = @computer_score = @ties = 0
28
- end
29
- def play(winning_score)
30
- while @player_score < winning_score && @computer_score < winning_score
31
- puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
32
- ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}"].colorize(:blue)
33
- player = PrivateMethods.player_choice
34
- computer = Constants::COMPUTER_CHOICES.sample
35
- puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}"].colorize(:blue)
36
- puts ColorizedString["Computer chooses #{computer.to_s.downcase}"].colorize(:blue)
37
- case PrivateMethods.player_outcome [player, computer]
38
- when :WIN
39
- puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"].colorize(:red)
40
- @player_score += 1
41
- when :LOSE
42
- puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round"].colorize(:red)
43
- @computer_score += 1
44
- else
45
- puts ColorizedString["Tie, choose again"].colorize(:red)
46
- @ties += 1
47
- end
48
- end
49
- puts ColorizedString["\nFinal score: player: #{@player_score}, "].colorize(:blue) +
50
- ColorizedString["computer: #{@computer_score} (ties: #{@ties})"].colorize(:blue)
51
- case PrivateMethods.final_outcome(@player_score, @computer_score)
52
- when :WIN
53
- puts ColorizedString["Player wins!"].colorize(:red)
54
- when :LOSE
55
- puts ColorizedString["Computer wins!"].colorize(:red)
56
- else
57
- puts ColorizedString["It's a tie!"].colorize(:red)
58
- end
59
- gets
60
- end
61
- require "ref/PrivateMethods.rb"
62
- end
63
-
64
-
65
- PlayRockPaperScissorsGame.new.play(2) # best of 3
66
-