Class: RSokoban::Level
- Inherits:
-
Object
- Object
- RSokoban::Level
- Defined in:
- lib/level.rb
Instance Attribute Summary collapse
-
#boxes ⇒ Object
Returns the value of attribute boxes.
-
#goals ⇒ Object
Returns the value of attribute goals.
-
#player ⇒ Object
Returns the value of attribute player.
-
#walls ⇒ Object
Returns the value of attribute walls.
Class Method Summary collapse
Instance Method Summary collapse
- #draw(window) ⇒ Object
-
#initialize(data) ⇒ Level
constructor
A new instance of Level.
Constructor Details
#initialize(data) ⇒ Level
Returns a new instance of Level.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/level.rb', line 23 def initialize(data) @walls = {} @boxes = {} @player = {} @goals = {} data.lines.each_with_index do |line, row| line.split(//).each_with_index do |char, col| case char when '#' @walls[[row, col]] = true when '$' @boxes[[row, col]] = true when '.' @goals[[row, col]] = true when '@' @player = {row: row, col: col} end end end end |
Instance Attribute Details
#boxes ⇒ Object
Returns the value of attribute boxes.
19 20 21 |
# File 'lib/level.rb', line 19 def boxes @boxes end |
#goals ⇒ Object
Returns the value of attribute goals.
21 22 23 |
# File 'lib/level.rb', line 21 def goals @goals end |
#player ⇒ Object
Returns the value of attribute player.
20 21 22 |
# File 'lib/level.rb', line 20 def player @player end |
#walls ⇒ Object
Returns the value of attribute walls.
18 19 20 |
# File 'lib/level.rb', line 18 def walls @walls end |
Class Method Details
.load(filename) ⇒ Object
63 64 65 |
# File 'lib/level.rb', line 63 def self.load(filename) self.parse(File.open(filename).read) end |
Instance Method Details
#draw(window) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/level.rb', line 45 def draw(window) @walls.keys.each do |k| window.move k[0], k[1] window.addstr '#' end @goals.keys.each do |k| window.move k[0], k[1] window.addstr '.' end end |