class Pacman::Level

main model class

Attributes

cage_obj[RW]
ghosts[RW]
ghosts_frozen[RW]
height[RW]
pellet_count[RW]
pellets_left[RW]
player[RW]
width[RW]

Public Class Methods

new() click to toggle source
# File lib/pacman/level.rb, line 4
def initialize
  resize(0, 0)
  @player = nil
  @pellet_count = 0
  @pellets_left = 0
  @ghosts = {}
  @ghosts_frozen = 0
end

Public Instance Methods

[](key) click to toggle source
# File lib/pacman/level.rb, line 29
def [](key)
  @rows[key]
end
[]=(key, value) click to toggle source
# File lib/pacman/level.rb, line 33
def []=(key, value)
  @rows[key] = value
end
each() { |row| ... } click to toggle source
# File lib/pacman/level.rb, line 41
def each
  return @rows.each unless block_given?
  @rows.each do |row|
    yield row
  end
end
each_with_position() { |x, y, col| ... } click to toggle source
# File lib/pacman/level.rb, line 51
def each_with_position
  @rows.each_with_index do |row, y|
    row.each_with_index do |col, x|
      yield x, y, col
    end
  end
end
get(x, y) click to toggle source
# File lib/pacman/level.rb, line 37
def get(x, y)
  @rows[y][x]
end
register_player(_player) click to toggle source
# File lib/pacman/level.rb, line 48
def register_player(_player)
end
resize(width, height) click to toggle source
# File lib/pacman/level.rb, line 13
def resize(width, height)
  @width = width
  @height = height

  # resize array
  @rows = []

  0.upto(height - 1) do
    row = []
    0.upto(width - 1) do
      row << nil
    end
    @rows << row
  end
end