Created
February 18, 2013 19:43
-
-
Save MattRoelle/4980055 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TwoDimensionalArray | |
attr_accessor :map | |
def initialize w, h | |
@w = w | |
@h = h | |
self.map = [] | |
(0...w).each do |x| | |
(0...h).each do |y| | |
map[(x*@w) + y] = nil | |
end | |
end | |
end | |
def set x, y, val | |
self.map[(x*@w) + y] = val | |
end | |
def get x, y | |
self.map[(x*@w) + y] | |
end | |
end | |
test = TwoDimensionalArray.new(10,10) | |
(0...10).each do |x| | |
(0...10).each do |y| | |
test.set x, y, "(#{x},#{y})" | |
end | |
end | |
puts test.map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment