Class: Mineswiper::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/mineswiper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: "Player1", board: Board.new) ⇒ Game

Returns a new instance of Game.



14
15
16
17
18
# File 'lib/mineswiper.rb', line 14

def initialize(name: "Player1", board: Board.new)
  @board = board
  @board.prepared_board
  @player = Player.new(@board)
end

Instance Attribute Details

#boardObject

Returns the value of attribute board.



12
13
14
# File 'lib/mineswiper.rb', line 12

def board
  @board
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/mineswiper.rb', line 12

def name
  @name
end

#playerObject

Returns the value of attribute player.



12
13
14
# File 'lib/mineswiper.rb', line 12

def player
  @player
end

Instance Method Details

#game_over?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/mineswiper.rb', line 38

def game_over?
  board.won? || board.lost?
end

#playObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mineswiper.rb', line 20

def play
  until game_over?
    # binding.pry
    board.parse_input(player.move)
  end

  if board.lost?
    board.all_indices.each do |idx|
      x, y = idx
      board.grid[x][y].hidden = false
    end
    player.display.render
    puts "You lose! BOOOM"
  else
    puts "You win"
  end
end