Sha256: 0fb8857ecab25cd33b83bf0c1adbd3b1f295113650d924aa15bb3b89e28c9c91

Contents?: true

Size: 1.16 KB

Versions: 34

Compression:

Stored size: 1.16 KB

Contents

require "colorized_string"
ColorizedString.colors   
ColorizedString.modes  
module PrivateMethods
  class << self
    def player_choice
      loop do
        print ColorizedString["Choose rock (r), paper (p) or scissors (s): "].colorize(:green)
        choice = gets.chomp.downcase
        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(:red) 
        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)
      return :TIE  if !:WIN | !:LOSE
    end 
    def final_outcome(pl,co) 
      return :WIN  if pl > co 
      return :LOSE if pl < co
      return :TIE  if pl = co 
    end 
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
PlayRockPaperScissorsGame-2.6.2 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.6.1 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.6.0 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.5.9 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.5.8 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.5.7 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.5.6 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.5.5 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.5.4 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.5.3 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.5.2 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.5.1 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.5.0 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.4.9 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.4.8 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.4.7 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.4.6 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.4.5 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.4.4 lib/PrivateMethods.rb
PlayRockPaperScissorsGame-2.4.3 lib/PrivateMethods.rb