class RSokoban::Level
Attributes
boxes[RW]
goals[RW]
player[RW]
walls[RW]
Public Class Methods
load(filename)
click to toggle source
# File lib/level.rb, line 63 def self.load(filename) self.parse(File.open(filename).read) end
new(data)
click to toggle source
# 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
parse(string)
click to toggle source
# File lib/level.rb, line 57 def self.parse(string) LevelData.parse(string).map do |level| Level.new level end end
Public Instance Methods
draw(window)
click to toggle source
# 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