PlayRockPaperScissorsGame 1.1.7 → 1.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rps.rb +2 -43
- 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: dcbed2914ae83f83bf3ff3df9d329cd3f8b85912
|
4
|
+
data.tar.gz: 5ff38e5a8aeee5e52e76e39ddcda1bc28955eba4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 435fd7b3f237a9db0728df53b60d0805c7f8ff98408e54e090138f7054053f6a2d6fc76afc02bbac6d0b70a6faf2c2e6c14fb4cef83ac9e264a97f06f8b7b08c
|
7
|
+
data.tar.gz: 85fea18fea7e5036e20cc22b052d2ad39929d673f1f9215bc1983864c89654cad7ab7a85f82ccb88bd6594f42f9e2f8e72bda4753e7d5959386fffca5f8fca74
|
data/lib/rps.rb
CHANGED
@@ -2,26 +2,7 @@ class PlayRockPaperScissorsGame
|
|
2
2
|
|
3
3
|
class RPS
|
4
4
|
|
5
|
-
|
6
|
-
NTRY_TO_SYM = {
|
7
|
-
'p' => :PAPER,
|
8
|
-
'r' => :ROCK,
|
9
|
-
's' => :SCISSORS
|
10
|
-
};
|
11
|
-
VALID_ENTRIES = NTRY_TO_SYM.keys;
|
12
|
-
COMPUTER_CHOICES = NTRY_TO_SYM.values;
|
13
|
-
WINNERS = [
|
14
|
-
[:SCISSORS, :PAPER],
|
15
|
-
[:PAPER, :ROCK],
|
16
|
-
[:ROCK, :SCISSORS]
|
17
|
-
]; # format: player choice, computer choice
|
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
|
19
|
-
INIT_STRINGS = [
|
20
|
-
"You are about to enter a rock-paper-scissors best of 3 match.",
|
21
|
-
"Press the return/enter key to continue...",
|
22
|
-
""
|
23
|
-
];
|
24
|
-
end;
|
5
|
+
require "ref/Constants.rb";
|
25
6
|
|
26
7
|
class RockPaperScissors
|
27
8
|
class << self
|
@@ -69,29 +50,7 @@ class PlayRockPaperScissorsGame
|
|
69
50
|
puts "";
|
70
51
|
gets;
|
71
52
|
end;
|
72
|
-
|
73
|
-
module PrivateVars
|
74
|
-
class << self
|
75
|
-
def player_choice
|
76
|
-
loop do
|
77
|
-
print "Choose rock (r), paper (p) or scissors (s): ";
|
78
|
-
choice = gets.chomp.downcase;
|
79
|
-
return Constants::NTRY_TO_SYM[choice] if Constants::NTRY_TO_SYM.key?(choice);
|
80
|
-
puts "That entry is invalid. Please re-enter";
|
81
|
-
end;
|
82
|
-
end;
|
83
|
-
def player_outcome(plays)
|
84
|
-
return :WIN if Constants::WINNERS.include?(plays);
|
85
|
-
return :LOSE if Constants::LOSERS.include?(plays);
|
86
|
-
return :TIE if !:WIN | !:LOSE;
|
87
|
-
end;
|
88
|
-
def final_outcome(pl, co)
|
89
|
-
return :WIN if pl > co;
|
90
|
-
return :LOSE if pl < co;
|
91
|
-
return :TIE if pl = co;
|
92
|
-
end;
|
93
|
-
end;
|
94
|
-
end;
|
53
|
+
require "ref/PrivateVars.rb";
|
95
54
|
end;
|
96
55
|
end;
|
97
56
|
end;
|