bin/PlayRockPaperScissorsGame in PlayRockPaperScissorsGame-2.2.3 vs bin/PlayRockPaperScissorsGame in PlayRockPaperScissorsGame-2.2.4

- old
+ new

@@ -9,29 +9,30 @@ =end class PlayRockPaperScissorsGame + # intiate the colorize gem require "colorized_string" ColorizedString.colors ColorizedString.modes module Constants - protected + protected # make constants protected NTRY_TO_SYM = { 'p' => :PAPER, 'r' => :ROCK, 's' => :SCISSORS } VALID_ENTRIES = NTRY_TO_SYM.keys COMPUTER_CHOICES = NTRY_TO_SYM.values 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 << self - def continue(str1, str2, str3) + def continue(str1,str2,str3) # pass in 3 parameters puts ColorizedString[str1].colorize(:color => :green) print ColorizedString[str2].colorize(:color => :green) - gets + gets # press enter or return to continue puts ColorizedString[str3].colorize(:color => :green) end end continue(Constants::INIT_STRINGS[0], Constants::INIT_STRINGS[1], Constants::INIT_STRINGS[2]) def initialize @@ -40,11 +41,11 @@ def play(winning_score) while @player_score < winning_score && @computer_score < winning_score 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 + computer = Constants::COMPUTER_CHOICES.sample # chooses a random option 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 ColorizedString["#{player.to_s.capitalize} beats #{computer.to_s.downcase}, player wins the round"].colorize(:red) @@ -79,9 +80,16 @@ if Constants::NTRY_TO_SYM.key?(choice) return Constants::NTRY_TO_SYM[choice] elsif choice != Constants::VALID_ENTRIES puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green) end + # # one may also do this: + # case + # when Constants::NTRY_TO_SYM.key?(choice) + # return Constants::NTRY_TO_SYM[choice] + # when choice != Constants::VALID_ENTRIES + # puts ColorizedString["That entry is invalid. Please re-enter."].colorize(:green) + # end end end def player_outcome(plays) return :WIN if Constants::WINNERS.include?(plays) return :LOSE if Constants::LOSERS.include?(plays)