class Rochambeau::Cli
Public Class Methods
get_players(count)
click to toggle source
# File lib/rochambeau/cli.rb, line 60 def self.get_players(count) case count when 1 return [Player::UnnamedHuman.new, Player::Robot.new] when 2 return [ Player::NamedHuman.new('Player 1'), Player::NamedHuman.new('Player 2'), ] end raise ArgumentError, "Unexpected player count: #{count}" end
Public Instance Methods
play()
click to toggle source
# File lib/rochambeau/cli.rb, line 30 def play system 'clear' game_mode = options.advanced ? GameMode::ADVANCED : GameMode::BASIC p1, p2 = Cli.get_players(options.players) puts game_mode.options.map(&:label).join(' ยท ') p1_choice = p1.choose_option(game_mode.options) p2_choice = p2.choose_option(game_mode.options) puts <<~CHOICES ------ #{p1.name}: #{p1_choice} #{p2.name}: #{p2_choice} ------ CHOICES puts Option.explain(p1_choice, p2_choice) unless p1_choice == p2_choice case p1_choice <=> p2_choice when 1 then puts p1.victory_message when -1 then puts p2.victory_message else puts 'Match draw.' end end
version()
click to toggle source
# File lib/rochambeau/cli.rb, line 10 def version puts <<~VERSION Rochambeau #{Rochambeau::VERSION} GitHub: https://github.com/jigarius/rochambeau VERSION end