28 lines
547 B
Ruby
28 lines
547 B
Ruby
# Nathan Hinton 1 Oct 2025
|
|
# Create a custom hash class for the universe.
|
|
|
|
require './position'
|
|
|
|
# This will contain the universe hash inside it. It will allow for array type
|
|
# indexing as well as point type indexing
|
|
class UniverseArray < Array
|
|
def initialize
|
|
end
|
|
|
|
def [](index, *rest)
|
|
if index.is_a?(Position)
|
|
return self[index.y_pos][index.x_pos]
|
|
else
|
|
super
|
|
end
|
|
end
|
|
|
|
def []=(index, *rest)
|
|
if index.is_a?(Position)
|
|
return self[index.y_pos][index.x_pos] = rest[0]
|
|
else
|
|
super
|
|
end
|
|
end
|
|
end
|