PlayRockPaperScissorsGame 1.3.6 → 1.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exec/run.bat +13 -0
- data/rps.gemspec +2 -2
- data/test/test_rps.rb +88 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecbb71593d1668584a0e5b92dd7c7c2418bb28d8
|
4
|
+
data.tar.gz: 27fce25161aa902f91587b685e5fb5d373710ab4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dde318bd51208d856726d60d15ddaa03a07ae15a5e41ac08b68e506085b986631424ed656d156b26dcfc63878b25fba4b5d4a1c64b31de572941fbdf37e433e7
|
7
|
+
data.tar.gz: 30977ff0e0ed9fa362e26f07b6d0cb5997ae5459656f7cf3b85cd6a80efe40554a6032a17142f65773c427665d68ba10b8dd67a8e89dbdd54449c246f4f5acd0
|
data/exec/run.bat
ADDED
data/rps.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "PlayRockPaperScissorsGame"
|
3
|
-
spec.version = "1.3.
|
3
|
+
spec.version = "1.3.7"
|
4
4
|
spec.date = "2017-03-29"
|
5
5
|
spec.summary = "Rock Paper Scissors"
|
6
6
|
spec.description = "A Ruby-programmed rock paper scissors game. "
|
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.email = "" # email is disclosed for privacy reasons
|
9
9
|
spec.platform = Gem::Platform::RUBY
|
10
10
|
spec.require_paths = ["lib", "test", "exec", "bin"]
|
11
|
-
spec.files = ["lib/rps.rb", "lib/ref/PrivateVars.rb", "lib/ref/Constants.rb", "Rakefile", "Gemfile", "test/", "exec/", "exec/rps.bash", "exec/uninstall.sh", "rps.gemspec", "LICENSE"]
|
11
|
+
spec.files = ["lib/rps.rb", "lib/ref/PrivateVars.rb", "lib/ref/Constants.rb", "Rakefile", "Gemfile", "test/test_rps.rb", "exec/run.bat", "exec/rps.bash", "exec/uninstall.sh", "rps.gemspec", "LICENSE"]
|
12
12
|
spec.bindir = "bin"
|
13
13
|
spec.executables << "rps"
|
14
14
|
spec.executables << "PlayRockPaperScissorsGame"
|
data/test/test_rps.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
class Test
|
2
|
+
|
3
|
+
class Rake < Test
|
4
|
+
|
5
|
+
module Constants
|
6
|
+
NTRY_TO_SYM = { 'p' => :PAPER, 'r' => :ROCK, 's' => :SCISSORS };
|
7
|
+
VALID_ENTRIES = NTRY_TO_SYM.keys;
|
8
|
+
COMPUTER_CHOICES = NTRY_TO_SYM.values;
|
9
|
+
WINNERS = [[:SCISSORS, :PAPER], [:PAPER, :ROCK], [:ROCK, :SCISSORS]]; # format: player choice, computer choice
|
10
|
+
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
|
11
|
+
INIT_STRINGS = ["You are about to enter a rock-paper-scissors best of 3 match.", "Press the return/enter key to continue...", ""];
|
12
|
+
end;
|
13
|
+
|
14
|
+
class RockPaperScissorsTest
|
15
|
+
class << self
|
16
|
+
def continue(str1, str2, str3)
|
17
|
+
puts str1;
|
18
|
+
print str2;
|
19
|
+
gets;
|
20
|
+
puts str3;
|
21
|
+
end;
|
22
|
+
end;
|
23
|
+
continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2]);
|
24
|
+
def initialize
|
25
|
+
@player_score = @computer_score = @ties = 0;
|
26
|
+
end;
|
27
|
+
def testPlay(winning_score)
|
28
|
+
while @player_score < winning_score && @computer_score < winning_score
|
29
|
+
puts "Player score: #{@player_score}, " +
|
30
|
+
"Computer score: #{@computer_score}, Ties: #{@ties}";
|
31
|
+
player = PrivateVars.player_choice;
|
32
|
+
computer = Constants::COMPUTER_CHOICES.sample;
|
33
|
+
puts "\nPlayer chooses #{player.to_s.downcase}";
|
34
|
+
puts "Computer chooses #{computer.to_s.downcase}";
|
35
|
+
case PrivateVars.player_outcome [player, computer]
|
36
|
+
when :WIN
|
37
|
+
puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round";
|
38
|
+
@player_score += 1;
|
39
|
+
when :LOSE
|
40
|
+
puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round";
|
41
|
+
@computer_score += 1;
|
42
|
+
else
|
43
|
+
puts "Tie, choose again";
|
44
|
+
@ties += 1;
|
45
|
+
end;
|
46
|
+
end;
|
47
|
+
puts "\nFinal score: player: #{@player_score}, " +
|
48
|
+
"computer: #{@computer_score} (ties: #{@ties})";
|
49
|
+
case PrivateVars.final_outcome(@player_score, @computer_score)
|
50
|
+
when :WIN
|
51
|
+
puts "Player wins!";
|
52
|
+
when :LOSE
|
53
|
+
puts "Computer wins!";
|
54
|
+
else
|
55
|
+
puts "It's a tie!";
|
56
|
+
end;
|
57
|
+
puts "";
|
58
|
+
gets;
|
59
|
+
end;
|
60
|
+
private
|
61
|
+
module PrivateVars
|
62
|
+
class << self
|
63
|
+
def player_choice
|
64
|
+
loop do
|
65
|
+
print "Choose rock (r), paper (p) or scissors (s): ";
|
66
|
+
choice = gets.chomp.downcase;
|
67
|
+
return Constants::NTRY_TO_SYM[choice] if Constants::NTRY_TO_SYM.key?(choice);
|
68
|
+
puts "That entry is invalid. Please re-enter";
|
69
|
+
end;
|
70
|
+
end;
|
71
|
+
def player_outcome(plays)
|
72
|
+
return :WIN if Constants::WINNERS.include?(plays);
|
73
|
+
return :LOSE if Constants::LOSERS.include?(plays);
|
74
|
+
return :TIE if !:WIN | !:LOSE;
|
75
|
+
end;
|
76
|
+
def final_outcome(pl, co)
|
77
|
+
return :WIN if pl > co;
|
78
|
+
return :LOSE if pl < co;
|
79
|
+
return :TIE if pl = co;
|
80
|
+
end;
|
81
|
+
end;
|
82
|
+
end;
|
83
|
+
end;
|
84
|
+
end;
|
85
|
+
end;
|
86
|
+
|
87
|
+
Test::Rake::RockPaperScissorsTest.new.testPlay(3); # best of 3
|
88
|
+
|
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: 1.3.
|
4
|
+
version: 1.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bag3318
|
@@ -68,11 +68,13 @@ files:
|
|
68
68
|
- bin/PlayRockPaperScissorsGame
|
69
69
|
- bin/rps
|
70
70
|
- exec/rps.bash
|
71
|
+
- exec/run.bat
|
71
72
|
- exec/uninstall.sh
|
72
73
|
- lib/ref/Constants.rb
|
73
74
|
- lib/ref/PrivateVars.rb
|
74
75
|
- lib/rps.rb
|
75
76
|
- rps.gemspec
|
77
|
+
- test/test_rps.rb
|
76
78
|
homepage: https://rubygems.org/gems/PlayRockPaperScissorsGame/
|
77
79
|
licenses:
|
78
80
|
- MIT
|