configurable number of mines, display it
This commit is contained in:
parent
d9f070c92e
commit
798fb16227
2 changed files with 15 additions and 6 deletions
|
@ -19,7 +19,7 @@ def display_curses( field, state = { dead: false, victory: false } )
|
|||
elsif state[:victory]
|
||||
Curses.addstr 'You won!! :) '
|
||||
else
|
||||
Curses.addstr "nearby: #{field.count_nearby_mines} "
|
||||
Curses.addstr "#{field.number_of_mines} mines, #{field.count_nearby_mines} nearby"
|
||||
end
|
||||
|
||||
field.height.times do |y|
|
||||
|
@ -40,8 +40,8 @@ def display_curses( field, state = { dead: false, victory: false } )
|
|||
Curses.refresh
|
||||
end
|
||||
|
||||
def ncurses_main
|
||||
field = MyHunt::Board.new
|
||||
def ncurses_main( number_of_mines )
|
||||
field = MyHunt::Board.new( number_of_mines )
|
||||
finished = false
|
||||
|
||||
Curses.init_screen
|
||||
|
@ -64,7 +64,7 @@ def ncurses_main
|
|||
begin
|
||||
case ch
|
||||
when 'r'
|
||||
field = MyHunt::Board.new
|
||||
field = MyHunt::Board.new( number_of_mines )
|
||||
finished = false
|
||||
else
|
||||
break
|
||||
|
@ -107,4 +107,7 @@ def ncurses_main
|
|||
exit!
|
||||
end
|
||||
|
||||
ncurses_main
|
||||
number_of_mines = 20
|
||||
number_of_mines = ARGV.first.to_i if ARGV.length == 1
|
||||
|
||||
ncurses_main( number_of_mines )
|
||||
|
|
|
@ -22,6 +22,7 @@ module MyHunt
|
|||
attr_reader :width,
|
||||
:height,
|
||||
:field,
|
||||
:number_of_mines,
|
||||
:explorer_x,
|
||||
:explorer_y
|
||||
|
||||
|
@ -31,6 +32,11 @@ module MyHunt
|
|||
@explorer_x = 0
|
||||
@explorer_y = 0
|
||||
@field = {}
|
||||
@number_of_mines = if number_of_mines.negative? && number_of_mines > ((@height * @width) - 2)
|
||||
20
|
||||
else
|
||||
number_of_mines
|
||||
end
|
||||
|
||||
@width.times do |x|
|
||||
@height.times do |y|
|
||||
|
@ -39,7 +45,7 @@ module MyHunt
|
|||
end
|
||||
|
||||
placed_mines = 0
|
||||
while placed_mines < number_of_mines
|
||||
while placed_mines < @number_of_mines
|
||||
coordinates = [rand( @width ), rand( @height )]
|
||||
next if coordinates == [0, 0]
|
||||
next if @field[ coordinates ].mine
|
||||
|
|
Loading…
Reference in a new issue