class Minehunter::CLI
The main interface to the game
@api public
Constants
- LEVELS
Public Instance Methods
run(argv = ARGV, input: $stdin, output: $stdout, env: {}, color: nil, screen_width: TTY::Screen.width, screen_height: TTY::Screen.height)
click to toggle source
Run the game
@param [Array<String>] argv
the command line parameters
@param [IO] input
the input stream, defaults to stdin
@param [IO] output
the output stream, defaults to stdout
@param [Hash] env
the environment variables
@param [Boolean] color
whether or not to style the game
@param [Integer] screen_width
the terminal screen width
@param [Integer] screen_height
the terminal screen height
@api public
# File lib/minehunter/cli.rb, line 92 def run(argv = ARGV, input: $stdin, output: $stdout, env: {}, color: nil, screen_width: TTY::Screen.width, screen_height: TTY::Screen.height) parse(argv) if params[:help] output.print help exit elsif params[:version] output.puts VERSION exit elsif params.errors.any? output.puts params.errors.summary exit 1 else level = LEVELS[params[:level]] decorator = Pastel.new(enabled: color).method(:decorate) game = Game.new( input: input, output: output, env: env, width: params[:width] || level[:width], height: params[:height] || level[:height], screen_width: screen_width, screen_height: screen_height, mines_limit: params[:mines] || level[:mines], decorator: decorator ) game.run end rescue Minehunter::Error => err output.puts "Error: #{err}" exit 1 end