Skip to content

Instantly share code, notes, and snippets.

@jmdeldin
Created December 7, 2015 00:36
Show Gist options
  • Save jmdeldin/8bff73b25c25164e50c3 to your computer and use it in GitHub Desktop.
Save jmdeldin/8bff73b25c25164e50c3 to your computer and use it in GitHub Desktop.
$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
@TheAnonymousNut
Copy link

hello

@jmdeldin
Copy link
Author

jmdeldin commented Dec 7, 2015

$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