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
#initialize(name: "Player1", board: Board.new) ⇒ Game
Returns a new instance of Game.
15 16 17 18 19 |
# File 'lib/mineswiper.rb', line 15 def initialize(name: "Player1", board: Board.new) @board = board @board.prepared_board @player = Player.new(@board) end |
Instance Attribute Details
#board ⇒ Object
Returns the value of attribute board.
13 14 15 |
# File 'lib/mineswiper.rb', line 13 def board @board end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/mineswiper.rb', line 13 def name @name end |
#player ⇒ Object
Returns the value of attribute player.
13 14 15 |
# File 'lib/mineswiper.rb', line 13 def player @player end |
Instance Method Details
#game_over? ⇒ Boolean
39 40 41 |
# File 'lib/mineswiper.rb', line 39 def game_over? board.won? || board.lost? end |
#play ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mineswiper.rb', line 21 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 |