Пример #1
0
 def DoObject(self, target, game):
     object = target.value
     m, reward, result = "", 0, Response.IllegalCommand
     if target.IsObject() and\
             (type(object.placement) == InventoryPlacement or object.placement.location == game.state.location):
         m = None
         if not object.moveable:
             m = "I CAN'T CARRY THAT!"
         elif game.state.inventory.Has(object):
             m = "I ALREADY HAVE IT."
             result = Response.Success
         elif game.state.inventory.capacity == len(
                 game.state.inventory.Get(game.world)):
             m = "I CAN'T CARRY ANYMORE."
         elif object.moveable:
             if Response.HasResponse(object.responses, self):
                 m, reward, result = Response.Respond(
                     object.responses, self, game)
             game.state.inventory.Add(object)
             if m is None:
                 m = ""
             if m != "":
                 m = '\n' + m
             m = "O.K." + m
             result = Response.MightBeUseful
     else:
         m = "I DON'T SEE THAT HERE."
     return m, reward, result
Пример #2
0
    def DoObject(self, target, game):
        m, reward, result = "", 0, Response.IllegalCommand

        # Process responses from the verb
        if Response.HasResponse(self.responses, self):
            m, reward, result = Response.Respond(
                self.responses, self, game, target.value
                if target is not None and target.IsObject() else None)
            if m is not None and m != "":
                return m, reward, result

        # Process responses from the object
        if target is not None and target.IsObject() and Response.HasResponse(
                target.value.responses, self):
            m, reward, result = Response.Respond(target.value.responses, self,
                                                 game)
            if m is None or m == "":
                m = self.didntWorkMessage
                result = Response.IllegalCommand
        elif self.notApplicableMessage is not None:
            m = self.notApplicableMessage
            result = Response.IllegalCommand
        return m, reward, result
Пример #3
0
 def DoObject(self, target, game):
     if target.IsObject() and game.state.inventory.Remove(target.value):
         game.CreateHere(target.value)
         m = ""
         if target.IsObject() and Response.HasResponse(
                 target.value.responses, self):
             m, reward, result = Response.Respond(target.value.responses,
                                                  self, game)
         if m == "":
             return "O.K. I DROPPED IT.", 0, Response.Success
         else:
             return m, reward, result
     else:
         return "I DON'T SEEM TO BE CARRYING IT.", 0, Response.IllegalCommand
Пример #4
0
 def Do(self, target, game):
     m, reward, result = "", 0, Response.IllegalCommand
     cant = "I CAN'T GO THAT WAY AT THE MOMENT."
     if target.IsDirection():
         move = game.state.location.moves[target.value.d]
         if move == 0:
             return cant, 0, Response.IllegalCommand
         game.state.location = game.world.locations[move]
         m = ""
         result = Response.Success
     elif target.IsObject():
         object = target.value
         if game.state.location == object.placement.location:
             if Response.HasResponse(object.responses, self):
                 m, reward, result = Response.Respond(
                     object.responses, self, game)
                 if not Response.IsSuccessfulResult(result) and (
                         m is None or m == ""):
                     return cant, 0, Response.IllegalCommand
             else:
                 return cant, 0, Response.IllegalCommand
         else:
             return "I DON'T SEE THAT HERE.", 0, Response.IllegalCommand
     return m, reward, result