Sha256: 004a2472c285ed30ccad6cb1bfadc907669de954a31fd603b9bacdebc01c4c1a

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'falling/map_view'
require 'falling/messages_view'
require 'falling/player'

module Falling
  class Interface
    attr_reader :player

    def initialize(universe:,
                   player: true)
      create_player! if player
      @universe = universe
    end

    def run!
      with_screen do
        loop do
          map_view.refresh
          messages_view.refresh
          Curses.doupdate
          break unless messages_view.step!
        end
      end
    end

    private

    attr_reader :universe

    def map_view
      @map_view ||= MapView.new(universe: universe)
    end

    def messages_view
      @messages_view ||= MessagesView.new(universe: universe)
    end

    def with_screen
      Falling.logger.info "Initializing screen."
      Curses.init_screen
      begin
        Curses.crmode
        Curses.noecho
        yield
      ensure
        Falling.logger.info "Closing screen."
        Curses.close_screen
      end
    end

    def create_player!
      @player = Player.new
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
falling-0.0.1 lib/falling/interface.rb