Class: Pacman::Level
- Inherits:
-
Object
- Object
- Pacman::Level
- Defined in:
- lib/pacman/level.rb
Overview
main model class
Instance Attribute Summary collapse
-
#cage_obj ⇒ Object
Returns the value of attribute cage_obj.
-
#ghosts ⇒ Object
Returns the value of attribute ghosts.
-
#ghosts_frozen ⇒ Object
Returns the value of attribute ghosts_frozen.
-
#height ⇒ Object
Returns the value of attribute height.
-
#pellet_count ⇒ Object
Returns the value of attribute pellet_count.
-
#pellets_left ⇒ Object
Returns the value of attribute pellets_left.
-
#player ⇒ Object
Returns the value of attribute player.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #each ⇒ Object
- #each_with_position ⇒ Object
- #get(x, y) ⇒ Object
-
#initialize ⇒ Level
constructor
A new instance of Level.
- #register_player(_player) ⇒ Object
- #resize(width, height) ⇒ Object
Constructor Details
#initialize ⇒ Level
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_obj ⇒ Object
Returns the value of attribute cage_obj.
59 60 61 |
# File 'lib/pacman/level.rb', line 59 def cage_obj @cage_obj end |
#ghosts ⇒ Object
Returns the value of attribute ghosts.
59 60 61 |
# File 'lib/pacman/level.rb', line 59 def ghosts @ghosts end |
#ghosts_frozen ⇒ Object
Returns the value of attribute ghosts_frozen.
59 60 61 |
# File 'lib/pacman/level.rb', line 59 def ghosts_frozen @ghosts_frozen end |
#height ⇒ Object
Returns the value of attribute height.
59 60 61 |
# File 'lib/pacman/level.rb', line 59 def height @height end |
#pellet_count ⇒ Object
Returns the value of attribute pellet_count.
59 60 61 |
# File 'lib/pacman/level.rb', line 59 def pellet_count @pellet_count end |
#pellets_left ⇒ Object
Returns the value of attribute pellets_left.
59 60 61 |
# File 'lib/pacman/level.rb', line 59 def pellets_left @pellets_left end |
#player ⇒ Object
Returns the value of attribute player.
59 60 61 |
# File 'lib/pacman/level.rb', line 59 def player @player end |
#width ⇒ Object
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 |
#each ⇒ Object
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_position ⇒ Object
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 |