Class: Pacman::Level

Inherits:
Object
  • Object
show all
Defined in:
lib/pacman/level.rb

Overview

main model class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLevel

Returns a new instance of Level.



4
5
6
7
8
9
10
11
# 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

Instance Attribute Details

#cage_objObject

Returns the value of attribute cage_obj.



59
60
61
# File 'lib/pacman/level.rb', line 59

def cage_obj
  @cage_obj
end

#ghostsObject

Returns the value of attribute ghosts.



59
60
61
# File 'lib/pacman/level.rb', line 59

def ghosts
  @ghosts
end

#ghosts_frozenObject

Returns the value of attribute ghosts_frozen.



59
60
61
# File 'lib/pacman/level.rb', line 59

def ghosts_frozen
  @ghosts_frozen
end

#heightObject

Returns the value of attribute height.



59
60
61
# File 'lib/pacman/level.rb', line 59

def height
  @height
end

#pellet_countObject

Returns the value of attribute pellet_count.



59
60
61
# File 'lib/pacman/level.rb', line 59

def pellet_count
  @pellet_count
end

#pellets_leftObject

Returns the value of attribute pellets_left.



59
60
61
# File 'lib/pacman/level.rb', line 59

def pellets_left
  @pellets_left
end

#playerObject

Returns the value of attribute player.



59
60
61
# File 'lib/pacman/level.rb', line 59

def player
  @player
end

#widthObject

Returns the value of attribute width.



59
60
61
# File 'lib/pacman/level.rb', line 59

def width
  @width
end

Instance Method Details

#[](key) ⇒ Object



29
30
31
# File 'lib/pacman/level.rb', line 29

def [](key)
  @rows[key]
end

#[]=(key, value) ⇒ Object



33
34
35
# File 'lib/pacman/level.rb', line 33

def []=(key, value)
  @rows[key] = value
end

#eachObject



41
42
43
44
45
46
# 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_positionObject



51
52
53
54
55
56
57
# 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) ⇒ Object



37
38
39
# File 'lib/pacman/level.rb', line 37

def get(x, y)
  @rows[y][x]
end

#register_player(_player) ⇒ Object



48
49
# File 'lib/pacman/level.rb', line 48

def register_player(_player)
end

#resize(width, height) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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