Class: GamesParadise::Minesweeper::Terminal::CLI
- Inherits:
-
Object
- Object
- GamesParadise::Minesweeper::Terminal::CLI
- Includes:
- TTY::Option
- Defined in:
- lib/games_paradise/minesweeper/terminal/cli.rb
Overview
GamesParadise::Minesweeper::Terminal::CLI
Constant Summary collapse
- LEVELS =
#
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
# === GamesParadise::Minesweeper::Terminal::CLI.run.
Instance Method Summary collapse
Class Method Details
.run ⇒ Object
#
GamesParadise::Minesweeper::Terminal::CLI.run
Start the game.
#
147 148 149 |
# File 'lib/games_paradise/minesweeper/terminal/cli.rb', line 147 def self.run CLI.new.run end |
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 |
# File 'lib/games_paradise/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 GamesParadise::Minesweeper::Terminal::Error => err output.puts "Error: #{err}" exit 1 end |