Beispiel #1
0
    def useCard(self, card_id):
        """
        Use a card (asking the player for required information).

        card_id - the ID (CARD_1, CARD_2, etc.) of the card to be used.
        
        Returns the action decided upon.
        """

        if card_id == -1 or card_id >= len(self.deck.hand):
            return action.DoNothing()
        else:
            card_to_use = self.deck.hand[card_id]

# If the card is directional, get the direction to use it in.
            if card_to_use.is_directional:
                direction_of_target_square = kb.direction_question(
                    self.currentLevel.messages,
                    "In which direction would you like to use the %s card?"
                    % card_to_use.ability_name)
                if direction_of_target_square is None:
                    self.currentLevel.messages.say("Never mind.")
                    return action.DoNothing()
            if card_to_use.is_melee:
                target_square = coordinates.add(
                    self.coords, direction_of_target_square)
                if target_square in self.currentLevel.dudeLayer:
                    del self.deck.hand[card_id]
                    return action.SpecialMelee(self,
                        self.currentLevel.dudeLayer[target_square],
                        card_to_use.action_code)
                else:
                    self.currentLevel.messages.say("You whiff completely!")
                    del self.deck.hand[card_id]
                    return action.Wait(self)
            else:
                if card_to_use.action_code == "GRENTHROW":
                    target_square = coordinates.add(self.coords, 
                        coordinates.multiply(direction_of_target_square, 2))
                    if self.currentLevel.isEmpty(target_square):
# Note that the player can, in fact, throw grenades on top of monsters.
                        del self.deck.hand[card_id]
                        return action.ThrowGrenade(self, target_square)
                    else:
                        self.currentLevel.messages.say(
                            "There's something in the way!")
                        return action.DoNothing()
                elif card_to_use.action_code == "ARROW":
                    del self.deck.hand[card_id]
                    return action.FireArrow(
                        self, direction_of_target_square, 12)
                elif card_to_use.action_code == "POUNCE":
                    del self.deck.hand[card_id]
                    return action.Pounce(self, direction_of_target_square, 12)
                elif card_to_use.action_code == "HASTE":
                    del self.deck.hand[card_id]
                    return action.HasteMonster(self, self, 12)
                elif card_to_use.action_code == "HASTEALL":
                    del self.deck.hand[card_id]
                    return action.HasteAll(self, 8, True, True)
                assert False
            assert False
Beispiel #2
0
    def getAction(self):
        while 1:
            key = kb.getKey()
# If the key is the quit key, quit.
            if key == kp.QUIT:
                sys.exit(0)
# If the key is the save key, ask if the player wants to save, and do so.
            elif key == kp.SAVE:
                if self.currentLevel.elements[self.coords] == level.UPSTAIRS_GLYPH:
                    decision = kb.boolean_question(self.currentLevel.messages,
                        "Do you really want to save and quit the game?")
                    if decision:
                        raise exc.SavingLevelChange()
                    else:
                        self.currentLevel.messages.say("Never mind, then.")
                        return action.DoNothing()
                else:
                    self.currentLevel.messages.say("You can only save when on the stairs (<).")
# If the key is the wait key, wait.
            elif key == kp.WAIT:
                return action.Wait(self)
# If the key is a movement key, move or attack, as is appropriate.
            elif key in config.DIRECTION_SWITCH:
                target = coordinates.add(self.coords,
                                         config.DIRECTION_SWITCH[key])
                if target in self.currentLevel.dudeLayer:
                    return action.Attack(self, 
                                         self.currentLevel.dudeLayer[target])
                elif self.canMove(target):
 # If the player is stuck, he cannot move!
                    if self.hasCondition("stuck"):
                        self.currentLevel.messages.append("You are stuck and cannot move!")
                        return action.DoNothing()
                    else:
                        return action.Move(self, config.DIRECTION_SWITCH[key])
                else:
# A move is illegal!
                    return action.DoNothing()
            elif key in config.RUN_DIRECTION_SWITCH:
                direction = config.RUN_DIRECTION_SWITCH[key]
                target = coordinates.add(self.coords, direction)
                if len(self.fov.dudes) != 0:
                    self.currentLevel.messages.append("Not with enemies in view!")
                    return action.DoNothing()
                elif self.canMove(target):
# If the player is stuck, he cannot move.
                    if self.hasCondition("stuck"):
                        self.currentLevel.messages.append("You are stuck and cannot move!")
                        return action.DoNothing()
                    else:
                        self.giveCondition(cond.Running(direction))
                        return action.Move(self, direction)
# If the key is a card key, use the card.
            elif key in kb.card_values:
                card_id = kb.card_values[key]
                
                if card_id >= len(self.deck.hand):
                    return action.DoNothing()
                card_to_use = self.deck.hand[card_id]

# If the card is directional, get the direction to use it in.
                if card_to_use.is_directional:
                    direction_of_target_square = kb.direction_question(
                        self.currentLevel.messages,
                        "In which direction would you like to use the %s card?"
                        % card_to_use.ability_name)
                if card_to_use.is_melee:
                    target_square = coordinates.add(self.coords, direction_of_target_square)
                    if target_square in self.currentLevel.dudeLayer:
                        del self.deck.hand[card_id]
                        return action.SpecialMelee(self,
                            self.currentLevel.dudeLayer[target_square],
                            card_to_use.action_code)
                    else:
                        self.currentLevel.messages.say("You whiff completely!")
                        del self.deck.hand[card_id]
                        return action.Wait(self)
                else:
                    if card_to_use.action_code == "GRENTHROW":
                        target_square = coordinates.add(self.coords, coordinates.multiply(direction_of_target_square, 2))
                        if self.currentLevel.isEmpty(target_square) and (not events.is_grenade_at_coords(target_square, self.currentLevel)):
                            del self.deck.hand[card_id]
                            return action.ThrowGrenade(self, target_square)
                        else:
                            self.currentLevel.messages.say("There's something in the way!")
                            return action.DoNothing()
                    elif card_to_use.action_code == "ARROW":
                        del self.deck.hand[card_id]
                        return action.FireArrow(self, direction_of_target_square, 12)
                    elif card_to_use.action_code == "HASTE":
                        del self.deck.hand[card_id]
                        return action.HasteMonster(self, self, 12)
                    elif card_to_use.action_code == "HASTEALL":
                        del self.deck.hand[card_id]
                        return action.HasteAll(self, 8)
                    assert False
                assert False
            elif key == kp.REST:
# Give the player the "rest" status, so she waits until healed fully.
                self.giveCondition(cond.Resting())
                return action.Wait(self)
# If the key is the "go upstairs" key, try to go up a level.
            elif key == kp.UP:
                if self.currentLevel.elements[self.coords] == level.UPSTAIRS_GLYPH:
        	        return action.Up()