Skip to content

Instantly share code, notes, and snippets.

@iGhost
Last active April 17, 2020 07:43
Show Gist options
  • Save iGhost/aab2f839f85cad9462ea81d251ec1e4a to your computer and use it in GitHub Desktop.
Save iGhost/aab2f839f85cad9462ea81d251ec1e4a to your computer and use it in GitHub Desktop.
WIDTH = 80
HEIGHT = 25
def show_map(map)
map.each do |row|
row.each do |cell|
print cell
end
puts ''
end
end
def fill_map(map)
map.each_with_index do |row, i|
row.each_with_index do |f, j|
roll = rand(100)
if roll > 65
cell = '▩' # Wall
elsif roll < 2
cell = '!' # Quest
elsif roll < 7
cell = '@' # Enemy
else
cell = ' '
end
map[i][j] = cell #"#{cell}"
end
end
map[0][0] = '%'
map[HEIGHT-1][WIDTH-1] = '*'
end
map = Array.new(HEIGHT) { Array.new(WIDTH) { '.' } }
fill_map(map)
show_map(map)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment