 		initialize @
 		@renderer = new Renderer @
 
+		@events.on 'key.c', (ch, key) =>
+			@quit() if key.ctrl
+
+		@events.on 'state.enter.game', =>
+			@initGame()
+
+	initGame: ->
+		@random = new Random(new MersenneTwister)
+		@timeManager = new TimeManager
 		@currentMap = new Map @, 50, 15
 
 		@entities = [

async = require 'async'
{EventEmitter2: EventEmitter} = require 'eventemitter2'

TimeManager = require './time-manager'
{Map} = require './map'

{initialize, deinitialize, Renderer} = require './io/tty'

{Dummy, FastDummy, Player} = require './creatures'

class Game
	constructor: ->
		# console.error 'Starting game...'
		@state = 'main menu'

		@timeManager = new TimeManager
		@events = new EventEmitter
			wildcard: yes
			# newListener: yes


		@timeManager.targets.push @entities...

	quit: ->
		deinitialize @
		process.exit 0

	goState: (state) ->
		@events.emit "state.exit.#{@state}", 'exit', @state
		@state = state
		@events.emit "state.enter.#{@state}", 'enter', @state

		@renderer.invalidate()

	main: ->
		async.whilst (-> true),
			(next) =>
				switch @state
					when 'main-menu'
						@events.once 'key.s', =>
							@goState 'game'
							next()
