Class: Budgie::Map

Inherits:
Object
  • Object
show all
Includes:
Index
Defined in:
lib/budgie/map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Index

#from_index, #to_index

Constructor Details

#initialize(max = 0) ⇒ Map

Returns a new instance of Map.



9
10
11
12
# File 'lib/budgie/map.rb', line 9

def initialize(max = 0)
  @max = max
  @data = AutoArray.new { AutoArray.new { Array.new } }
end

Instance Attribute Details

#maxObject

Returns the value of attribute max.



7
8
9
# File 'lib/budgie/map.rb', line 7

def max
  @max
end

Instance Method Details

#[](x, y, z) ⇒ Object



14
15
16
# File 'lib/budgie/map.rb', line 14

def [](x, y, z)
  @data[to_index x][to_index y][to_index z]
end

#[]=(x, y, z, value) ⇒ Object



18
19
20
21
22
23
# File 'lib/budgie/map.rb', line 18

def []=(x, y, z, value)
  self.max = x
  self.max = y
  self.max = z
  @data[to_index x][to_index y][to_index z] = value
end

#each(&block) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/budgie/map.rb', line 25

def each(&block)
  (-@max).upto(@max) do |x|
  (-@max).upto(@max) do |y|
  (-@max).upto(@max) do |z|
    yield x, y, z, self[x, y, z]
  end
  end
  end
end