Class: Map
- Inherits:
-
Object
- Object
- Map
- Defined in:
- lib/tetris/map.rb
Instance Method Summary collapse
- #free?(x, y) ⇒ Boolean
-
#initialize(w, h) ⇒ Map
constructor
A new instance of Map.
- #set(x, y, colour) ⇒ Object
- #squares ⇒ Object
- #update ⇒ Object
Constructor Details
Instance Method Details
#free?(x, y) ⇒ Boolean
22 23 24 |
# File 'lib/tetris/map.rb', line 22 def free?(x, y) x >= 0 and x < @w and y >= 0 and y < @h and not @tiles[y][x] end |
#set(x, y, colour) ⇒ Object
8 9 10 |
# File 'lib/tetris/map.rb', line 8 def set(x, y, colour) @tiles[y][x] = colour end |
#squares ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/tetris/map.rb', line 12 def squares Enumerator.new do |yielder| @tiles.each_with_index do |line, y| line.each_with_index do |colour, x| yielder.yield(x, y, colour) if colour end end end end |
#update ⇒ Object
26 27 28 29 30 |
# File 'lib/tetris/map.rb', line 26 def update points = 0 shift_lines! {|line| points += 1 if line.all?} points end |