class MineSweeper::Game
Public Class Methods
new()
click to toggle source
# File lib/mine-sweeper.rb, line 9 def initialize @mines = Minefield.new intro loop do print_game_board take_a_turn check_for_game_end end end
Private Instance Methods
check_for_game_end()
click to toggle source
# File lib/mine-sweeper/game_helper.rb, line 23 def check_for_game_end game_over_sequence if @mines.game_over? end
game_over_sequence()
click to toggle source
# File lib/mine-sweeper/game_helper.rb, line 27 def game_over_sequence if @mines.won? winning_sequence else losing_sequence end exit end
intro()
click to toggle source
# File lib/mine-sweeper/game_helper.rb, line 9 def intro print "welcome to\nMINESWEEPER\n\nCOMMANDS:\n'C' to clear\n'A' to auto-clear\n'F' to flag\n'U' to un-flag\nThe ⚑ shows you how many flags are left" end
losing_sequence()
click to toggle source
# File lib/mine-sweeper/game_helper.rb, line 42 def losing_sequence @mines.blow_up_board print_game_board puts "BOOM! YOU LOST." end
print_game_board()
click to toggle source
# File lib/mine-sweeper/game_helper.rb, line 13 def print_game_board puts "⚑ #{@mines.unflagged_mines}" @mines.render end
take_a_turn()
click to toggle source
# File lib/mine-sweeper/game_helper.rb, line 18 def take_a_turn turn = Turn.new @mines.take_turn(turn.message) end
winning_sequence()
click to toggle source
# File lib/mine-sweeper/game_helper.rb, line 36 def winning_sequence @mines.flag_remaining_mines print_game_board puts "CONGRATULATIONS!" end