Class: Minesweeper::Game
- Inherits:
-
Object
- Object
- Minesweeper::Game
- Defined in:
- lib/minesweeper/game.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Game
constructor
A new instance of Game.
- #play ⇒ Object
Constructor Details
#initialize(options) ⇒ Game
Returns a new instance of Game.
5 6 7 |
# File 'lib/minesweeper/game.rb', line 5 def initialize() @playfield = Playfield.new(**) end |
Instance Method Details
#play ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/minesweeper/game.rb', line 9 def play @playfield.display loop do puts "Enter position to reveal as: y, x" input = STDIN.gets.strip if input.include? ',' y, x = input.split(',').map &:to_i puts if @playfield.has_mine?(y, x) @playfield.display_with_mines puts "\n\nLose!" exit 1 end @playfield.reveal_square(y, x) if @playfield.all_squares_revealed? @playfield.display_with_mines puts "\n\nThe winner is you!" exit end @playfield.display end end end |