class Life::UI

Constants

DELAY

Public Class Methods

execute() click to toggle source
# File lib/life/ui.rb, line 5
def self.execute
  ui = new(load_board("life/glider.txt"))

  loop do
    ui.render()
    sleep(DELAY)
    ui.update()
  end
rescue Interrupt, IRB::Abort
  return
ensure
  ui.close()
end
load_board(relative_path) click to toggle source
# File lib/life/ui.rb, line 19
def self.load_board(relative_path)
  path = File.join(LIB_PATH, relative_path)
  Life::Board.from_text(File.read(path))
end
new(board) click to toggle source
# File lib/life/ui.rb, line 24
def initialize(board)
  Curses.init_screen()
  Curses.curs_set(0)
  @window = Curses::Window.new(0, 0, 0, 0)

  @board = board
end

Public Instance Methods

close() click to toggle source
# File lib/life/ui.rb, line 47
def close
  Curses::close_screen()
end
render() click to toggle source
# File lib/life/ui.rb, line 32
def render
  @window.clear()

  @board.each do |x, y, alive|
    @window.setpos(y, x)
    @window.addstr(alive ? "#" : " ")
  end

  @window.refresh()
end
update() click to toggle source
# File lib/life/ui.rb, line 43
def update
  @board.tick()
end