Skip to content

Instantly share code, notes, and snippets.

@takai
Created June 2, 2012 05:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takai/2856693 to your computer and use it in GitHub Desktop.
Save takai/2856693 to your computer and use it in GitHub Desktop.
module Amida
class App
START_CHAR = 65
def header(column)
chars = (START_CHAR...(START_CHAR + column)).map(&:chr)
chars.join(' ') + "\n" +
bar_row_string(column)
end
def row(column)
bar = rand(column - 1)
(0...column).each_with_object("") do |i, r|
r << if i == bar
"|--"
else
"| "
end
end
end
def footer(column)
win_rows = ([" "] * column).tap { |r| r[rand(column)] = "*" }
win_row_string = win_rows.join(' ')
"#{bar_row_string(column)}\n#{win_row_string}"
end
def run
num = 10
column = 5
puts header(column)
num.times do
puts row(column)
end
puts footer(column)
end
private
def bar_row_string(column)
(["|"] * column).join(' ')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment