Sha256: e6759cc47d3d5ef75f492ebba9043dc85210acd5019c6d5219789c5de6c8ae13
Contents?: true
Size: 1.62 KB
Versions: 1
Compression:
Stored size: 1.62 KB
Contents
module Gamefic class Character < Entity attr_reader :state, :queue, :user, :last_command attr_accessor :object_of_pronoun def initialize(plot, args = {}) @state = CharacterState.new(self) @queue = Array.new super end def connect(user) @user = user end def disconnect # TODO: We might need some cleanup here. Like, move the character out of the game, or set a timeout to allow dropped users to reconnect... figure it out. @user = nil end def perform(command) #if command != nil # @queue.push command #end @last_command = command if state.busy? == false Director.dispatch(self, command) else @queue.push command end end #def inject(command) # Director.dispatch(self, command) #end def tell(message, refresh = false) if user != nil and message.to_s != '' user.stream.send "#{message}\n" if (refresh == true) user.refresh end end end def state=(new_state) @state = new_state end def destroy if @user != nil @user.quit end super end def update super @state.update end end class CharacterState def initialize(character) @character = character post_initialize end def post_initialize # TODO: Required by subclasses? end def busy? false end def update while (line = @character.queue.shift) @character.perform line if @character.state != self break end end end def prompt "> " end end class GameOverState < CharacterState def prompt "GAME OVER" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gamefic-0.1.1 | lib/gamefic/character.rb |