=begin |====================================| | Req Ruby Ver | Req Ruby Gems Ver | |--------------|---------------------| | v2.4.0 | v2.6.11 | |====================================| =end class PlayRockPaperScissorsGame require "colorize"; class RPS require "ref/Constants.rb"; class RockPaperScissors class << self def continue(str1, str2, str3) puts str1.green.bold; print str2.green.bold; gets; 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}, ".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}".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".green.bold; @player_score += 1; when :LOSE puts "#{computer.to_s.capitalize} beats #{player.to_s.downcase}, computer wins the round".green.bold; @computer_score += 1; else puts "Tie, choose again".green.bold; @ties += 1; end; end; 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!".green.bold; when :LOSE puts "Computer wins!".green.bold; else puts "It's a tie!".green.bold; end; gets; end; require "ref/PrivateMethods.rb".green.bold; end; end; end; PlayRockPaperScissorsGame::RPS::RockPaperScissors.new.play(2); # best of 3