Sha256: 73169eed57602bf26e18a1e927ecda781c17204f8806cf94743a27eb6618034b
Contents?: true
Size: 1.19 KB
Versions: 9
Compression:
Stored size: 1.19 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) else # do nothing 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
9 entries across 9 versions & 1 rubygems