當前位置: 首頁>>代碼示例>>Python>>正文


Python Plan.checkForAndExecutePlanEntry方法代碼示例

本文整理匯總了Python中plan.Plan.checkForAndExecutePlanEntry方法的典型用法代碼示例。如果您正苦於以下問題:Python Plan.checkForAndExecutePlanEntry方法的具體用法?Python Plan.checkForAndExecutePlanEntry怎麽用?Python Plan.checkForAndExecutePlanEntry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在plan.Plan的用法示例。


在下文中一共展示了Plan.checkForAndExecutePlanEntry方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: NPC

# 需要導入模塊: from plan import Plan [as 別名]
# 或者: from plan.Plan import checkForAndExecutePlanEntry [as 別名]
class NPC(Entity):
    """Super class for all NPCs"""
    def __init__(self, game, y, x):
        """Initialise the player object"""
        super(NPC, self).__init__(game)
        self.y = y
        self.x = x
        self.colour = Constants.COLOUR_WHITE
        self.path = []
        self.square = None
        self.plan = Plan(self)
        self.currentBehaviour = DefaultBehaviour(self)
        self.alive = True
        self.killer = False

        self.dialogue = dialogue.Dialogue(self)
        standardDialogueChoice1 = dialogue.DialogueChoice("Hello!", 
                                                          "Hello to you too!")
        standardDialogueChoice2 = dialogue.DialogueChoice("My name is Kate!", 
                                                          "Fascinating.")
        def responseFunction3(npc, response):
            npc.game.player.notebook.addToKnownNpcs(self)
            actualResponse = "My name is " + npc.firstName + " " + npc.lastName
            actualResponse += ". I live in house number " + str(npc.square.house.number)
            actualResponse += "."
            return actualResponse
        standardDialogueChoice3 = dialogue.DialogueChoice("Who are you?", 
                                                          "",
                                                          responseFunction3)

        standardDialogueChoice4 = dialogue.DialogueChoice("No, hello to YOU!", 
                                                          "We're done talking, freakshow.")
        secondNode = dialogue.DialogueNode()
        secondNode.addChoice(standardDialogueChoice4)

        choicePredicate3 = lambda: not self.game.player.notebook.isNpcKnown(self)
        dialogueRoot = dialogue.DialogueNode()
        dialogueRoot.addChoice(standardDialogueChoice1, None, secondNode)
        dialogueRoot.addChoice(standardDialogueChoice2)
        dialogueRoot.addChoice(standardDialogueChoice3, choicePredicate3)
        self.dialogue.setRootNode(dialogueRoot)

        # Fluffy, plot stuff
        self.gender = random.choice([Gender.MALE, Gender.FEMALE])
        self.firstName = "Dave"
        if self.gender == Gender.MALE:
            self.firstName = names.getMaleFirstName()
        else:
            self.firstName = names.getFemaleFirstName()
        self.lastName = names.getLastName()

        self.eyeColour = random.choice(["green", "blue", "brown"])
        self.hairColour = random.choice(["brown", "red", "blonde"])
        self.description = "They have " + self.eyeColour + " eyes and " + self.hairColour + " hair."

        # Emotions and states
        # TODO: Something with this?
        self.scared = False
        self.answeringDoor = False

    def die(self):
        self.alive = False
        self.character = '%'
        self.currentBehaviour = Dead(self)

    def beginConversation(self):
        self.dialogue.beginConversation()

    def isAtHome(self):
        # If we need to know that the NPC is at home, regardless of their
        # plan
        if self.square:
            isInX = (self.x > self.square.houseXOffset and
                     self.x < self.square.houseXOffset + self.square.house.width)
            isInY = (self.y > self.square.houseYOffset and
                     self.y < self.square.houseYOffset + self.square.house.height)
            return isInX and isInY

    def update(self):
        """If the NPC is alive, carry out their Plan and Behavaiour"""
        if self.alive:
            # Move randomly, or sometimes actually pick a place to go and go there!
            # If we have a plan and we're not otherwise occupied (to do), execute it
            self.plan.checkForAndExecutePlanEntry()

            # Once we've decided on a plan (or have no plan), the NPC should first
            # go to anywhere they're planning on being before performing their 
            # status action.

            if self.path and self.alive:
                (nextY, nextX) = self.path[0]
                # The algorithm will have avoided walls and fences,
                # so the only obstructions will be the player, doors and NPCs
                blockedByEntity = False
                blockedByDoor = False
                # Check for player..
                if (self.game.player.y, self.game.player.x) == (nextY, nextX):
                    blockedByEntity = True
                # Check for NPC..
                if Constants.NPC_ON_NPC_COLLISIONS:
#.........這裏部分代碼省略.........
開發者ID:mjdarby,項目名稱:RogueDetective,代碼行數:103,代碼來源:entity.py


注:本文中的plan.Plan.checkForAndExecutePlanEntry方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。