Class: Termfront::Game
- Inherits:
-
Object
- Object
- Termfront::Game
- Defined in:
- lib/termfront/game.rb
Instance Method Summary collapse
-
#initialize ⇒ Game
constructor
A new instance of Game.
- #start ⇒ Object
Constructor Details
#initialize ⇒ Game
Returns a new instance of Game.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/termfront/game.rb', line 5 def initialize @stdout = AsyncWriter.new(STDOUT) @audio = AudioManager.new @renderer = Renderer.new(@stdout) @input = Input.new @scene_player = ScenePlayer.new(@stdout, audio: @audio) @demo_player = DemoPlayer.new(@stdout, @renderer) @difficulty = nil Signal.trap("WINCH") { @renderer.invalidate_size_cache! } end |
Instance Method Details
#start ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/termfront/game.rb', line 16 def start enter_alt_screen loop do reset_title_screen_state @input.clear title = TitleScreen.new(@stdout) @audio.play_bgm(:title) choice = title.show @audio.stop_bgm case choice when :singleplayer then run_singleplayer when :wavesfight then run_wavesfight when :campaign then run_campaign when :pvp then Network::Client.new(@stdout).run when :quit then break end end rescue Interrupt # normal exit rescue StandardError => e @crash = e ensure @audio.close @stdout.close if @stdout.respond_to?(:close) && !@stdout.equal?(STDOUT) leave_alt_screen if @crash warn "#{@crash.class}: #{@crash.}" @crash.backtrace.first(10).each { |l| warn " #{l}" } end end |