bin/rps in PlayRockPaperScissorsGame-1.5.4 vs bin/rps in PlayRockPaperScissorsGame-1.5.5
- old
+ new
@@ -22,63 +22,63 @@
WINNERS = [[:SCISSORS, :PAPER], [:PAPER, :ROCK], [:ROCK, :SCISSORS]]; # format: player choice, computer choice
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
INIT_STRINGS = ["You are about to enter a rock-paper-scissors best of 3 match.", "Press the return/enter key to continue...", ""];
end;
- class RockPaperScissors
+ class RockPaperScissors
class << self
def continue(str1, str2, str3)
- puts str1.green.bold;
- print str2.green.bold;
+ puts ColorizedString[str1].colorize(:color => :green);
+ print ColorizedString[str2].colorize(:color => :green);
gets;
- puts str3.green.bold;
+ puts ColorizedString[str3].colorize(:color => :green);
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)
+ def testPlay(winning_score)
while @player_score < winning_score && @computer_score < winning_score
- puts "Player score: #{@player_score}, ".green.bold +
- "Computer score: #{@computer_score}, Ties: #{@ties}".green.bold;
+ puts ColorizedString["Player score: #{@player_score}, "].colorize(:blue) +
+ ColorizedString["Computer score: #{@computer_score}, Ties: #{@ties}"].colorize(:blue);
player = PrivateMethods.player_choice;
computer = Constants::COMPUTER_CHOICES.sample;
- puts "\nPlayer chooses #{player.to_s.downcase}".green.bold;
- puts "Computer chooses #{computer.to_s.downcase}".green.bold;
+ puts ColorizedString["\nPlayer chooses #{player.to_s.downcase}"].colorize(:blue);
+ puts ColorizedString["Computer chooses #{computer.to_s.downcase}"].colorize(:blue);
case PrivateMethods.player_outcome [player, computer]
when :WIN
- puts "#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round".green.bold;
+ puts ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"].colorize(:red);
@player_score += 1;
when :LOSE
- puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round".green.bold;
+ puts ColorizedString["#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round"].colorize(:red);
@computer_score += 1;
else
- puts "Tie, choose again".green.bold;
+ puts ColorizedString["Tie, choose again"].colorize(:red);
@ties += 1;
end;
end;
- puts "\nFinal score: player: #{@player_score}, ".green.bold +
- "computer: #{@computer_score} (ties: #{@ties})".green.bold;
+ puts ColorizedString["\nFinal score: player: #{@player_score}, "].colorize(:blue) +
+ ColorizedString["computer: #{@computer_score} (ties: #{@ties})"].colorize(:blue);
case PrivateMethods.final_outcome(@player_score, @computer_score)
when :WIN
- puts "Player wins!".green.bold;
+ puts ColorizedString["Player wins!"].colorize(:red);
when :LOSE
- puts "Computer wins!".green.bold;
+ puts ColorizedString["Computer wins!"].colorize(:red);
else
- puts "It's a tie!".green.bold;
+ puts ColorizedString["It's a tie!"].colorize(:red);
end;
gets;
end;
private;
module PrivateMethods
class << self
def player_choice
loop do
- print "Choose rock (r), paper (p) or scissors (s): ".green.bold;
+ print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green);
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.".green.bold;
+ puts ColorizedString["That entry is invalid. Please re-enter"].colorize(:green);
end;
end;
def player_outcome(plays)
return :WIN if Constants::WINNERS.include?(plays);
return :LOSE if Constants::LOSERS.include?(plays);