PlayRockPaperScissorsGame 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +1 -2
- data/lib/rps.rb +0 -117
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dca910f767282b2687ef2570c8d549aaf19d7ed
|
4
|
+
data.tar.gz: 8bd91c0835a20e2adcbeea51b6e443f2253ca240
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c2e2ab1b367c3ab8a3283c20a9fdd1eb4f0f1c81abca6d5ca360d3a124e6e20966ad24a6541a39ab8bfbc1f44c7e1c1623f98e5615e26cd74aca91f94103655
|
7
|
+
data.tar.gz: 88393f96b62c90c11d5f730773efbd02c1b6fc3ccce391ad7604093d72f58b5bee709cdac00349be3a052cd194e4020b53af6936505d808d0ce745741094bcca
|
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.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bag3318
|
@@ -62,7 +62,6 @@ extra_rdoc_files:
|
|
62
62
|
files:
|
63
63
|
- README.md
|
64
64
|
- bin/rps
|
65
|
-
- lib/rps.rb
|
66
65
|
homepage: https://rubygems.org/gems/PlayRockPaperScissorsGame/
|
67
66
|
licenses:
|
68
67
|
- MIT
|
data/lib/rps.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
=begin
|
4
|
-
|=================================|
|
5
|
-
| How to Run |
|
6
|
-
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
|
7
|
-
| Mac |
|
8
|
-
|---------------------------------|
|
9
|
-
| $ ruby ~/Desktop/rps/bin/rps.rb |
|
10
|
-
|*********************************|
|
11
|
-
| Windows |
|
12
|
-
|---------------------------------|
|
13
|
-
| > CD Desktop/rps/bin |
|
14
|
-
| > rps.rb |
|
15
|
-
|_________________________________|
|
16
|
-
=end
|
17
|
-
|
18
|
-
class Master
|
19
|
-
|
20
|
-
class RPS
|
21
|
-
|
22
|
-
module Constants
|
23
|
-
NTRY_TO_SYM = {
|
24
|
-
'p' => :PAPER,
|
25
|
-
'r' => :ROCK,
|
26
|
-
's' => :SCISSORS
|
27
|
-
};
|
28
|
-
VALID_ENTRIES = NTRY_TO_SYM.keys;
|
29
|
-
COMPUTER_CHOICES = NTRY_TO_SYM.values;
|
30
|
-
WINNERS = [
|
31
|
-
[:SCISSORS, :PAPER],
|
32
|
-
[:PAPER, :ROCK],
|
33
|
-
[:ROCK, :SCISSORS]
|
34
|
-
]; # format: player choice, computer choice
|
35
|
-
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
|
36
|
-
INIT_STRINGS = [
|
37
|
-
"You are about to enter a rock-paper-scissors best of 3 match.",
|
38
|
-
"Press the return/enter key to continue...",
|
39
|
-
""
|
40
|
-
];
|
41
|
-
end;
|
42
|
-
|
43
|
-
class RockPaperScissors
|
44
|
-
class << self
|
45
|
-
def continue(str1, str2, str3)
|
46
|
-
puts str1;
|
47
|
-
print str2;
|
48
|
-
gets;
|
49
|
-
puts str3;
|
50
|
-
end;
|
51
|
-
end;
|
52
|
-
continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2]);
|
53
|
-
def initialize
|
54
|
-
@player_score = @computer_score = @ties = 0;
|
55
|
-
end;
|
56
|
-
def play(winning_score)
|
57
|
-
while @player_score < winning_score && @computer_score < winning_score
|
58
|
-
puts "Player score: #{@player_score}, " +
|
59
|
-
"Computer score: #{@computer_score}, Ties: #{@ties}";
|
60
|
-
player = PrivateVars.player_choice;
|
61
|
-
computer = Constants::COMPUTER_CHOICES.sample;
|
62
|
-
puts "\nPlayer chooses #{player.to_s.downcase}";
|
63
|
-
puts "Computer chooses #{computer.to_s.downcase}";
|
64
|
-
case PrivateVars.player_outcome [player, computer]
|
65
|
-
when :WIN
|
66
|
-
puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round";
|
67
|
-
@player_score += 1;
|
68
|
-
when :LOSE
|
69
|
-
puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round";
|
70
|
-
@computer_score += 1;
|
71
|
-
else
|
72
|
-
puts "Tie, choose again";
|
73
|
-
@ties += 1;
|
74
|
-
end;
|
75
|
-
end;
|
76
|
-
puts "\nFinal score: player: #{@player_score}, " +
|
77
|
-
"computer: #{@computer_score} (ties: #{@ties})";
|
78
|
-
case PrivateVars.final_outcome(@player_score, @computer_score)
|
79
|
-
when :WIN
|
80
|
-
puts "Player wins!";
|
81
|
-
when :LOSE
|
82
|
-
puts "Computer wins!";
|
83
|
-
else
|
84
|
-
puts "It's a tie!";
|
85
|
-
end;
|
86
|
-
puts "";
|
87
|
-
gets;
|
88
|
-
end;
|
89
|
-
private
|
90
|
-
module PrivateVars
|
91
|
-
class << self
|
92
|
-
def player_choice
|
93
|
-
loop do
|
94
|
-
print "Choose rock (r), paper (p) or scissors (s): ";
|
95
|
-
choice = gets.chomp.downcase;
|
96
|
-
return Constants::NTRY_TO_SYM[choice] if Constants::NTRY_TO_SYM.key?(choice);
|
97
|
-
puts "That entry is invalid. Please re-enter";
|
98
|
-
end;
|
99
|
-
end;
|
100
|
-
def player_outcome(plays)
|
101
|
-
return :WIN if Constants::WINNERS.include?(plays);
|
102
|
-
return :LOSE if Constants::LOSERS.include?(plays);
|
103
|
-
return :TIE if (!:WIN || !:LOSE);
|
104
|
-
end;
|
105
|
-
def final_outcome(pl, co)
|
106
|
-
return :WIN if pl > co;
|
107
|
-
return :LOSE if pl < co;
|
108
|
-
return :TIE if pl = co;
|
109
|
-
end;
|
110
|
-
end;
|
111
|
-
end;
|
112
|
-
end;
|
113
|
-
end;
|
114
|
-
end;
|
115
|
-
|
116
|
-
Master::RPS::RockPaperScissors.new.play(3); # best of 3
|
117
|
-
|