class Minesweeper::Game

Public Class Methods

new(options) click to toggle source
# File lib/minesweeper/game.rb, line 5
def initialize(options)
  @playfield = Playfield.new(options)
end

Public Instance Methods

play() click to toggle source
# 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

      next unless @playfield.within_boundaries?(y, x)

      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