Sha256: 997ab4d364d856e73d746668a4b7c389ddce7492f97e235331889fa26b5edf37

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

module Gamefic
	
	class User
		attr_reader :state, :character, :story
		def initialize(story)
			@story = story
			@stream = UserStream.new
			@state = UserState.new self
		end
		def stream
			@stream
		end
		def state=(state_class)
			@state = state_class.new self
		end
		def character=(entity)
			@character = entity
			@character.connect self
		end
		def refresh
			# Nothing to do
		end
		def story
			@story
		end
		def quit
			exit
		end
	end
	
	class UserStream
		def initialize
			@queue = Array.new
		end
		def send(data)
			print data
		end
		def select
			print "> "
			@queue.push STDIN.gets
		end
		def recv
			@queue.shift
		end
	end
	
	class UserState
		attr_reader :user
		def initialize(user)
			@user = user
			post_initialize
		end
		def post_initialize
			@user.character = Character.new user.story, :name => 'Player'
		end
		def update
			line = @user.stream.recv
			if line != nil
				@user.character.perform line
			end
		end
	end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gamefic-0.0.4 lib/gamefic/user.rb
gamefic-0.0.3 lib/gamefic/user.rb
gamefic-0.0.2 lib/gamefic/user.rb
gamefic-0.0.1 lib/gamefic/user.rb