bin/PlayRockPaperScissorsGame in PlayRockPaperScissorsGame-1.4.8 vs bin/PlayRockPaperScissorsGame in PlayRockPaperScissorsGame-1.4.9
- old
+ new
@@ -8,10 +8,12 @@
|====================================|
=end
class PlayRockPaperScissorsGame
+ require "colorize";
+
class RPS
protected;
module Constants
NTRY_TO_SYM = { 'p' => :PAPER, 'r' => :ROCK, 's' => :SCISSORS };
@@ -23,60 +25,60 @@
end;
class RockPaperScissors
class << self
def continue(str1, str2, str3)
- puts str1;
- print str2;
+ puts str1.green.bold;
+ print str2.green.bold;
gets;
- puts str3;
+ puts str3.green.bold;
end;
end;
continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2]);
def initialize
@player_score = @computer_score = @ties = 0;
end;
def play(winning_score)
while @player_score < winning_score && @computer_score < winning_score
- puts "Player score: #{@player_score}, " +
- "Computer score: #{@computer_score}, Ties: #{@ties}";
+ puts "Player score: #{@player_score}, ".green.bold +
+ "Computer score: #{@computer_score}, Ties: #{@ties}".green.bold;
player = PrivateMethods.player_choice;
computer = Constants::COMPUTER_CHOICES.sample;
- puts "\nPlayer chooses #{player.to_s.downcase}";
- puts "Computer chooses #{computer.to_s.downcase}";
+ puts "\nPlayer chooses #{player.to_s.downcase}".green.bold;
+ puts "Computer chooses #{computer.to_s.downcase}".green.bold;
case PrivateMethods.player_outcome [player, computer]
when :WIN
- puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round";
+ puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round".green.bold;
@player_score += 1;
when :LOSE
- puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round";
+ puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round".green.bold;
@computer_score += 1;
else
- puts "Tie, choose again";
+ puts "Tie, choose again".green.bold;
@ties += 1;
end;
end;
- puts "\nFinal score: player: #{@player_score}, " +
- "computer: #{@computer_score} (ties: #{@ties})";
+ puts "\nFinal score: player: #{@player_score}, ".green.bold +
+ "computer: #{@computer_score} (ties: #{@ties})".green.bold;
case PrivateMethods.final_outcome(@player_score, @computer_score)
when :WIN
- puts "Player wins!";
+ puts "Player wins!".green.bold;
when :LOSE
- puts "Computer wins!";
+ puts "Computer wins!".green.bold;
else
- puts "It's a tie!";
+ puts "It's a tie!".green.bold;
end;
gets;
end;
private;
module PrivateMethods
class << self
def player_choice
loop do
- print "Choose rock (r), paper (p) or scissors (s): ";
+ print "Choose rock (r), paper (p) or scissors (s): ".green.bold;
choice = gets.chomp.downcase;
return Constants::NTRY_TO_SYM[choice] if Constants::NTRY_TO_SYM.key?(choice);
- puts "That entry is invalid. Please re-enter.";
+ puts "That entry is invalid. Please re-enter.".green.bold;
end;
end;
def player_outcome(plays)
return :WIN if Constants::WINNERS.include?(plays);
return :LOSE if Constants::LOSERS.include?(plays);