PlayRockPaperScissorsGame 1.5.4 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/PlayRockPaperScissorsGame +23 -21
- data/bin/rps +19 -19
- data/lib/ref/PrivateMethods.rb +3 -3
- data/lib/rps.rb +17 -17
- data/rps.gemspec +1 -1
- data/test/test_rps.rb +22 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1301ce0bec9cf1a5331bbb4b078448ea21f5d8d8
|
4
|
+
data.tar.gz: c1a98cfcb6d72107abcd4615f8e0d3ee37a314e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6fcc0fb5a7d348558b6920f8fa24443aa01ca19422d4dd7ff4de2389b9f7aa5f665078b9aff2dc0fde50e3170f5bf4b28ce4e56497276d6098f0c743b396c40
|
7
|
+
data.tar.gz: 9240c106ad1a057b3f1aa0f39138d6ebd7efbf9e16c32b1058eb5c627d310a38bbdf46b057bc7f07ebb2707001dbcb026b62b505096e89343585456d8d4bdb22
|
@@ -10,7 +10,9 @@
|
|
10
10
|
|
11
11
|
class PlayRockPaperScissorsGame
|
12
12
|
|
13
|
-
require "
|
13
|
+
require "colorized_string";
|
14
|
+
ColorizedString.colors
|
15
|
+
ColorizedString.modes
|
14
16
|
|
15
17
|
class RPS
|
16
18
|
|
@@ -24,48 +26,48 @@ class PlayRockPaperScissorsGame
|
|
24
26
|
INIT_STRINGS = ["You are about to enter a rock-paper-scissors best of 3 match.", "Press the return/enter key to continue...", ""];
|
25
27
|
end;
|
26
28
|
|
27
|
-
class RockPaperScissors
|
29
|
+
class RockPaperScissors
|
28
30
|
class << self
|
29
31
|
def continue(str1, str2, str3)
|
30
|
-
puts str1.green
|
31
|
-
print str2.green
|
32
|
+
puts ColorizedString[str1].colorize(:color => :green);
|
33
|
+
print ColorizedString[str2].colorize(:color => :green);
|
32
34
|
gets;
|
33
|
-
puts str3.green
|
35
|
+
puts ColorizedString[str3].colorize(:color => :green);
|
34
36
|
end;
|
35
37
|
end;
|
36
38
|
continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2]);
|
37
39
|
def initialize
|
38
40
|
@player_score = @computer_score = @ties = 0;
|
39
41
|
end;
|
40
|
-
def
|
42
|
+
def testPlay(winning_score)
|
41
43
|
while @player_score < winning_score && @computer_score < winning_score
|
42
|
-
puts "Player score: #{@player_score}, ".
|
43
|
-
"Computer score: #{@computer_score}, Ties: #{@ties}".
|
44
|
+
puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
|
45
|
+
ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}"].colorize(:blue);
|
44
46
|
player = PrivateMethods.player_choice;
|
45
47
|
computer = Constants::COMPUTER_CHOICES.sample;
|
46
|
-
puts "\nPlayer chooses #{player.to_s.downcase}".
|
47
|
-
puts "Computer chooses #{computer.to_s.downcase}".
|
48
|
+
puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}"].colorize(:blue);
|
49
|
+
puts ColorizedString["Computer chooses #{computer.to_s.downcase}"].colorize(:blue);
|
48
50
|
case PrivateMethods.player_outcome [player, computer]
|
49
51
|
when :WIN
|
50
|
-
puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round".
|
52
|
+
puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"].colorize(:red);
|
51
53
|
@player_score += 1;
|
52
54
|
when :LOSE
|
53
|
-
puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round".
|
55
|
+
puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round"].colorize(:red);
|
54
56
|
@computer_score += 1;
|
55
57
|
else
|
56
|
-
puts "Tie, choose again".
|
58
|
+
puts ColorizedString["Tie, choose again"].colorize(:red);
|
57
59
|
@ties += 1;
|
58
60
|
end;
|
59
61
|
end;
|
60
|
-
puts "\nFinal score: player: #{@player_score}, ".
|
61
|
-
"computer: #{@computer_score} (ties: #{@ties})".
|
62
|
+
puts ColorizedString["\nFinal score: player: #{@player_score}, "].colorize(:blue) +
|
63
|
+
ColorizedString["computer: #{@computer_score} (ties: #{@ties})"].colorize(:blue);
|
62
64
|
case PrivateMethods.final_outcome(@player_score, @computer_score)
|
63
65
|
when :WIN
|
64
|
-
puts "Player wins!".
|
66
|
+
puts ColorizedString["Player wins!"].colorize(:red);
|
65
67
|
when :LOSE
|
66
|
-
puts "Computer wins!".
|
68
|
+
puts ColorizedString["Computer wins!"].colorize(:red);
|
67
69
|
else
|
68
|
-
puts "It's a tie!".
|
70
|
+
puts ColorizedString["It's a tie!"].colorize(:red);
|
69
71
|
end;
|
70
72
|
gets;
|
71
73
|
end;
|
@@ -74,10 +76,10 @@ class PlayRockPaperScissorsGame
|
|
74
76
|
class << self
|
75
77
|
def player_choice
|
76
78
|
loop do
|
77
|
-
print "Choose rock (r), paper (p) or scissors (s): ".green
|
79
|
+
print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green);
|
78
80
|
choice = gets.chomp.downcase;
|
79
81
|
return Constants::NTRY_TO_SYM[choice] if Constants::NTRY_TO_SYM.key?(choice);
|
80
|
-
puts "That entry is invalid. Please re-enter
|
82
|
+
puts ColorizedString["That entry is invalid. Please re-enter"].colorize(:green);
|
81
83
|
end;
|
82
84
|
end;
|
83
85
|
def player_outcome(plays)
|
@@ -92,7 +94,7 @@ class PlayRockPaperScissorsGame
|
|
92
94
|
end;
|
93
95
|
end;
|
94
96
|
end;
|
95
|
-
end;
|
97
|
+
end;
|
96
98
|
end;
|
97
99
|
end;
|
98
100
|
|
data/bin/rps
CHANGED
@@ -24,48 +24,48 @@ class PlayRockPaperScissorsGame
|
|
24
24
|
INIT_STRINGS = ["You are about to enter a rock-paper-scissors best of 3 match.", "Press the return/enter key to continue...", ""];
|
25
25
|
end;
|
26
26
|
|
27
|
-
class RockPaperScissors
|
27
|
+
class RockPaperScissors
|
28
28
|
class << self
|
29
29
|
def continue(str1, str2, str3)
|
30
|
-
puts str1.green
|
31
|
-
print str2.green
|
30
|
+
puts ColorizedString[str1].colorize(:color => :green);
|
31
|
+
print ColorizedString[str2].colorize(:color => :green);
|
32
32
|
gets;
|
33
|
-
puts str3.green
|
33
|
+
puts ColorizedString[str3].colorize(:color => :green);
|
34
34
|
end;
|
35
35
|
end;
|
36
36
|
continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2]);
|
37
37
|
def initialize
|
38
38
|
@player_score = @computer_score = @ties = 0;
|
39
39
|
end;
|
40
|
-
def
|
40
|
+
def testPlay(winning_score)
|
41
41
|
while @player_score < winning_score && @computer_score < winning_score
|
42
|
-
puts "Player score: #{@player_score}, ".
|
43
|
-
"Computer score: #{@computer_score}, Ties: #{@ties}".
|
42
|
+
puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
|
43
|
+
ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}"].colorize(:blue);
|
44
44
|
player = PrivateMethods.player_choice;
|
45
45
|
computer = Constants::COMPUTER_CHOICES.sample;
|
46
|
-
puts "\nPlayer chooses #{player.to_s.downcase}".
|
47
|
-
puts "Computer chooses #{computer.to_s.downcase}".
|
46
|
+
puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}"].colorize(:blue);
|
47
|
+
puts ColorizedString["Computer chooses #{computer.to_s.downcase}"].colorize(:blue);
|
48
48
|
case PrivateMethods.player_outcome [player, computer]
|
49
49
|
when :WIN
|
50
|
-
puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round".
|
50
|
+
puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"].colorize(:red);
|
51
51
|
@player_score += 1;
|
52
52
|
when :LOSE
|
53
|
-
puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round".
|
53
|
+
puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round"].colorize(:red);
|
54
54
|
@computer_score += 1;
|
55
55
|
else
|
56
|
-
puts "Tie, choose again".
|
56
|
+
puts ColorizedString["Tie, choose again"].colorize(:red);
|
57
57
|
@ties += 1;
|
58
58
|
end;
|
59
59
|
end;
|
60
|
-
puts "\nFinal score: player: #{@player_score}, ".
|
61
|
-
"computer: #{@computer_score} (ties: #{@ties})".
|
60
|
+
puts ColorizedString["\nFinal score: player: #{@player_score}, "].colorize(:blue) +
|
61
|
+
ColorizedString["computer: #{@computer_score} (ties: #{@ties})"].colorize(:blue);
|
62
62
|
case PrivateMethods.final_outcome(@player_score, @computer_score)
|
63
63
|
when :WIN
|
64
|
-
puts "Player wins!".
|
64
|
+
puts ColorizedString["Player wins!"].colorize(:red);
|
65
65
|
when :LOSE
|
66
|
-
puts "Computer wins!".
|
66
|
+
puts ColorizedString["Computer wins!"].colorize(:red);
|
67
67
|
else
|
68
|
-
puts "It's a tie!".
|
68
|
+
puts ColorizedString["It's a tie!"].colorize(:red);
|
69
69
|
end;
|
70
70
|
gets;
|
71
71
|
end;
|
@@ -74,10 +74,10 @@ class PlayRockPaperScissorsGame
|
|
74
74
|
class << self
|
75
75
|
def player_choice
|
76
76
|
loop do
|
77
|
-
print "Choose rock (r), paper (p) or scissors (s): ".green
|
77
|
+
print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green);
|
78
78
|
choice = gets.chomp.downcase;
|
79
79
|
return Constants::NTRY_TO_SYM[choice] if Constants::NTRY_TO_SYM.key?(choice);
|
80
|
-
puts "That entry is invalid. Please re-enter
|
80
|
+
puts ColorizedString["That entry is invalid. Please re-enter"].colorize(:green);
|
81
81
|
end;
|
82
82
|
end;
|
83
83
|
def player_outcome(plays)
|
data/lib/ref/PrivateMethods.rb
CHANGED
@@ -3,16 +3,16 @@ module PrivateMethods
|
|
3
3
|
class << self
|
4
4
|
def player_choice
|
5
5
|
loop do
|
6
|
-
print "Choose rock (r), paper (p) or scissors (s): ".green
|
6
|
+
print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green);
|
7
7
|
choice = gets.chomp.downcase;
|
8
8
|
return Constants::NTRY_TO_SYM[choice] if Constants::NTRY_TO_SYM.key?(choice);
|
9
|
-
puts "That entry is invalid. Please re-enter
|
9
|
+
puts ColorizedString["That entry is invalid. Please re-enter"].colorize(:green);
|
10
10
|
end;
|
11
11
|
end;
|
12
12
|
def player_outcome(plays)
|
13
13
|
return :WIN if Constants::WINNERS.include?(plays);
|
14
14
|
return :LOSE if Constants::LOSERS.include?(plays);
|
15
|
-
return :TIE if !:WIN
|
15
|
+
return :TIE if (!:WIN || !:LOSE);
|
16
16
|
end;
|
17
17
|
def final_outcome(pl, co)
|
18
18
|
return :WIN if pl > co;
|
data/lib/rps.rb
CHANGED
@@ -14,48 +14,48 @@ class PlayRockPaperScissorsGame
|
|
14
14
|
|
15
15
|
require "ref/Constants.rb";
|
16
16
|
|
17
|
-
class RockPaperScissors
|
17
|
+
class RockPaperScissors
|
18
18
|
class << self
|
19
19
|
def continue(str1, str2, str3)
|
20
|
-
puts str1.green
|
21
|
-
print str2.green
|
20
|
+
puts ColorizedString[str1].colorize(:color => :green);
|
21
|
+
print ColorizedString[str2].colorize(:color => :green);
|
22
22
|
gets;
|
23
|
-
puts str3.green
|
23
|
+
puts ColorizedString[str3].colorize(:color => :green);
|
24
24
|
end;
|
25
25
|
end;
|
26
26
|
continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2]);
|
27
27
|
def initialize
|
28
28
|
@player_score = @computer_score = @ties = 0;
|
29
29
|
end;
|
30
|
-
def
|
30
|
+
def testPlay(winning_score)
|
31
31
|
while @player_score < winning_score && @computer_score < winning_score
|
32
|
-
puts "Player score: #{@player_score}, ".
|
33
|
-
"Computer score: #{@computer_score}, Ties: #{@ties}".
|
32
|
+
puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
|
33
|
+
ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}"].colorize(:blue);
|
34
34
|
player = PrivateMethods.player_choice;
|
35
35
|
computer = Constants::COMPUTER_CHOICES.sample;
|
36
|
-
puts "\nPlayer chooses #{player.to_s.downcase}".
|
37
|
-
puts "Computer chooses #{computer.to_s.downcase}".
|
36
|
+
puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}"].colorize(:blue);
|
37
|
+
puts ColorizedString["Computer chooses #{computer.to_s.downcase}"].colorize(:blue);
|
38
38
|
case PrivateMethods.player_outcome [player, computer]
|
39
39
|
when :WIN
|
40
|
-
puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round".
|
40
|
+
puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"].colorize(:red);
|
41
41
|
@player_score += 1;
|
42
42
|
when :LOSE
|
43
|
-
puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round".
|
43
|
+
puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round"].colorize(:red);
|
44
44
|
@computer_score += 1;
|
45
45
|
else
|
46
|
-
puts "Tie, choose again".
|
46
|
+
puts ColorizedString["Tie, choose again"].colorize(:red);
|
47
47
|
@ties += 1;
|
48
48
|
end;
|
49
49
|
end;
|
50
|
-
puts "\nFinal score: player: #{@player_score}, ".
|
51
|
-
"computer: #{@computer_score} (ties: #{@ties})".
|
50
|
+
puts ColorizedString["\nFinal score: player: #{@player_score}, "].colorize(:blue) +
|
51
|
+
ColorizedString["computer: #{@computer_score} (ties: #{@ties})"].colorize(:blue);
|
52
52
|
case PrivateMethods.final_outcome(@player_score, @computer_score)
|
53
53
|
when :WIN
|
54
|
-
puts "Player wins!".
|
54
|
+
puts ColorizedString["Player wins!"].colorize(:red);
|
55
55
|
when :LOSE
|
56
|
-
puts "Computer wins!".
|
56
|
+
puts ColorizedString["Computer wins!"].colorize(:red);
|
57
57
|
else
|
58
|
-
puts "It's a tie!".
|
58
|
+
puts ColorizedString["It's a tie!"].colorize(:red);
|
59
59
|
end;
|
60
60
|
gets;
|
61
61
|
end;
|
data/rps.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "PlayRockPaperScissorsGame"
|
3
|
-
spec.version = "1.5.
|
3
|
+
spec.version = "1.5.5"
|
4
4
|
spec.date = "2017-03-30"
|
5
5
|
spec.summary = "A Rock Paper Scissors Ruby Gem"
|
6
6
|
spec.description = "A Ruby-programmed rock paper scissors game. To install: gem install PlayRockPaperScissorsGame; To run: rps; or: PlayRockPaperScissorsGame"
|
data/test/test_rps.rb
CHANGED
@@ -7,7 +7,11 @@
|
|
7
7
|
=end
|
8
8
|
|
9
9
|
class Test
|
10
|
-
|
10
|
+
|
11
|
+
require "colorized_string";
|
12
|
+
ColorizedString.colors;
|
13
|
+
ColorizedString.modes;
|
14
|
+
|
11
15
|
class Rake < Test
|
12
16
|
protected;
|
13
17
|
module Constants
|
@@ -21,10 +25,10 @@ class Test
|
|
21
25
|
class RockPaperScissorsTest
|
22
26
|
class << self
|
23
27
|
def continue(str1, str2, str3)
|
24
|
-
puts str1.green
|
25
|
-
print str2.green
|
28
|
+
puts ColorizedString[str1].colorize(:color => :green);
|
29
|
+
print ColorizedString[str2].colorize(:color => :green);
|
26
30
|
gets;
|
27
|
-
puts str3.green
|
31
|
+
puts ColorizedString[str3].colorize(:color => :green);
|
28
32
|
end;
|
29
33
|
end;
|
30
34
|
continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2]);
|
@@ -33,33 +37,33 @@ class Test
|
|
33
37
|
end;
|
34
38
|
def testPlay(winning_score)
|
35
39
|
while @player_score < winning_score && @computer_score < winning_score
|
36
|
-
puts "Player score: #{@player_score}, ".
|
37
|
-
"Computer score: #{@computer_score}, Ties: #{@ties}".
|
40
|
+
puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
|
41
|
+
ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}"].colorize(:blue);
|
38
42
|
player = PrivateMethods.player_choice;
|
39
43
|
computer = Constants::COMPUTER_CHOICES.sample;
|
40
|
-
puts "\nPlayer chooses #{player.to_s.downcase}".
|
41
|
-
puts "Computer chooses #{computer.to_s.downcase}".
|
44
|
+
puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}"].colorize(:blue);
|
45
|
+
puts ColorizedString["Computer chooses #{computer.to_s.downcase}"].colorize(:blue);
|
42
46
|
case PrivateMethods.player_outcome [player, computer]
|
43
47
|
when :WIN
|
44
|
-
puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round".
|
48
|
+
puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"].colorize(:red);
|
45
49
|
@player_score += 1;
|
46
50
|
when :LOSE
|
47
|
-
puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round".
|
51
|
+
puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round"].colorize(:red);
|
48
52
|
@computer_score += 1;
|
49
53
|
else
|
50
|
-
puts "Tie, choose again".
|
54
|
+
puts ColorizedString["Tie, choose again"].colorize(:red);
|
51
55
|
@ties += 1;
|
52
56
|
end;
|
53
57
|
end;
|
54
|
-
puts "\nFinal score: player: #{@player_score}, ".
|
55
|
-
"computer: #{@computer_score} (ties: #{@ties})".
|
58
|
+
puts ColorizedString["\nFinal score: player: #{@player_score}, "].colorize(:blue) +
|
59
|
+
ColorizedString["computer: #{@computer_score} (ties: #{@ties})"].colorize(:blue);
|
56
60
|
case PrivateMethods.final_outcome(@player_score, @computer_score)
|
57
61
|
when :WIN
|
58
|
-
puts "Player wins!".
|
62
|
+
puts ColorizedString["Player wins!"].colorize(:red);
|
59
63
|
when :LOSE
|
60
|
-
puts "Computer wins!".
|
64
|
+
puts ColorizedString["Computer wins!"].colorize(:red);
|
61
65
|
else
|
62
|
-
puts "It's a tie!".
|
66
|
+
puts ColorizedString["It's a tie!"].colorize(:red);
|
63
67
|
end;
|
64
68
|
gets;
|
65
69
|
end;
|
@@ -68,10 +72,10 @@ class Test
|
|
68
72
|
class << self
|
69
73
|
def player_choice
|
70
74
|
loop do
|
71
|
-
print "Choose rock (r), paper (p) or scissors (s): ".green
|
75
|
+
print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green);
|
72
76
|
choice = gets.chomp.downcase;
|
73
77
|
return Constants::NTRY_TO_SYM[choice] if Constants::NTRY_TO_SYM.key?(choice);
|
74
|
-
puts "That entry is invalid. Please re-enter".green
|
78
|
+
puts ColorizedString["That entry is invalid. Please re-enter"].colorize(:green);
|
75
79
|
end;
|
76
80
|
end;
|
77
81
|
def player_outcome(plays)
|