diff --git a/ruby/bin/gosuhunt b/ruby/bin/gosuhunt index 70e8bec..e56dc65 100755 --- a/ruby/bin/gosuhunt +++ b/ruby/bin/gosuhunt @@ -2,12 +2,13 @@ # frozen_string_literal: true require 'gosu' +require 'optparse' require 'minehunt' class GosuHunt < Gosu::Window - def initialize( number_of_mines = 20 ) - @scale = 3 + def initialize( number_of_mines, scale ) + @scale = scale @sprite_size = 6 @number_of_mines = number_of_mines @@ -114,7 +115,20 @@ class GosuHunt < Gosu::Window end end -number_of_mines = 20 -number_of_mines = ARGV.first.to_i if ARGV.length == 1 +options = { number_of_mines: 20, + scale: 3 } +OptionParser.new do |opts| + opts.banner = 'Usage: gosuhunt ' -GosuHunt.new( number_of_mines ).show + opts.on( '-m', '--mines INT' ) do |nb_mines| + options[:number_of_mines] = nb_mines.to_i + end + + opts.on( '-s', '--scale INT' ) do |scale| + options[:scale] = scale.to_i + end +end + .parse! + +GosuHunt.new( options[:number_of_mines], options[:scale] ) + .show diff --git a/ruby/bin/minehunt b/ruby/bin/minehunt index 8421ff6..f2335fe 100755 --- a/ruby/bin/minehunt +++ b/ruby/bin/minehunt @@ -2,6 +2,7 @@ # frozen_string_literal: true require 'curses' +require 'optparse' require 'minehunt' @@ -108,7 +109,14 @@ def ncurses_main( number_of_mines ) exit! end -number_of_mines = 20 -number_of_mines = ARGV.first.to_i if ARGV.length == 1 +options = { number_of_mines: 20 } +OptionParser.new do |opts| + opts.banner = 'Usage: minehunt ' -ncurses_main( number_of_mines ) + opts.on( '-m', '--mines INT' ) do |nb_mines| + options[:number_of_mines] = nb_mines.to_i + end +end + .parse! + +ncurses_main( options[:number_of_mines] )