Created
December 7, 2015 00:36
-
-
Save jmdeldin/8bff73b25c25164e50c3 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
$grid = Array.new(10, "X").map { |r| Array.new(10, "X") } | |
def $grid.print | |
puts map(&:join) | |
end | |
def $grid.draw(row, col, size: 2) | |
bounds = $grid.length | |
fail "out of bounds #{row}+#{size} > #{bounds}" if row+size > bounds | |
shape = ' ' | |
size.times do |i| | |
$grid[row][col + i] = shape | |
$grid[row + i][col] = shape | |
$grid[row + i][col + i] = shape | |
end | |
end | |
$grid.draw(5, 5) | |
$grid.print |
$grid = Array.new(10, "X").map { |r| Array.new(10, "X") }
def print
puts $grid.map(&:join)
# also could do:
# puts $grid.map { |array| array.join(' ') }
end
def draw(row, col, size: 2)
bounds = $grid.length
fail "out of bounds #{row}+#{size} > #{bounds}" if row+size > bounds
shape = ' '
size.times do |i|
$grid[row][col + i] = shape
$grid[row + i][col] = shape
$grid[row + i][col + i] = shape
end
end
draw(5, 5)
print
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello