Class: GamesAndRpgParadise::Minesweeper::Terminal::CLI
- Inherits:
-
Object
- Object
- GamesAndRpgParadise::Minesweeper::Terminal::CLI
- Includes:
- TTY::Option
- Defined in:
- lib/games_and_rpg_paradise/games/minesweeper/terminal/cli.rb
Overview
GamesAndRpgParadise::Minesweeper::Terminal::CLI
Constant Summary collapse
- LEVELS =
#
GamesAndRpgParadise::Minesweeper::Terminal::CLI::LEVELS
#
{ 'easy' => { width: 9, height: 9, mines: 10 }, 'medium' => { width: 16, height: 16, mines: 40 }, 'hard' => { width: 30, height: 16, mines: 99 } }
Class Method Summary collapse
-
.run ⇒ Object
# === GamesAndRpgParadise::Minesweeper::Terminal::CLI.run.
Instance Method Summary collapse
Class Method Details
Instance Method Details
#run(argv = ARGV, input: $stdin, output: $stdout, env: {}, color: nil, screen_width: TTY::Screen.width, screen_height: TTY::Screen.height) ⇒ Object
#
run
Run the game
#
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/games_and_rpg_paradise/games/minesweeper/terminal/cli.rb', line 106 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 GamesAndRpgParadise::Minesweeper::Terminal::Error => err output.puts "Error: #{err}" exit 1 end |