Class: Mineswiper::Game
- Inherits:
-
Object
- Object
- Mineswiper::Game
- Defined in:
- lib/mineswiper.rb
Instance Attribute Summary collapse
-
#board ⇒ Object
Returns the value of attribute board.
-
#name ⇒ Object
Returns the value of attribute name.
-
#player ⇒ Object
Returns the value of attribute player.
Instance Method Summary collapse
- #game_over? ⇒ Boolean
-
#initialize(name: "Player1", board: Board.new) ⇒ Game
constructor
A new instance of Game.
- #play ⇒ Object
Constructor Details
Instance Attribute Details
#board ⇒ Object
Returns the value of attribute board.
12 13 14 |
# File 'lib/mineswiper.rb', line 12 def board @board end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/mineswiper.rb', line 12 def name @name end |
#player ⇒ Object
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
38 39 40 |
# File 'lib/mineswiper.rb', line 38 def game_over? board.won? || board.lost? end |
#play ⇒ Object
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 |