Esempio n. 1
0
def use(player, item=None):
    roomState = db.getRoomStateID(player.roomID)
    if item == None:
        if player.inventory != []:
            print("You can use items below:")
            for item in player.inventory:
                print("\t* {}".format(item))
        else:
            print("There is no items in inventory to use.")

    elif item == "torch" and item in player.inventory and player.roomID == 21:
        db.updateRoomState(player.roomID, 2)
        printRoomStateOrDescription(player)
        npcs = db.getNPCsInRoom(player.roomID)
        keys = []
        for key in npcs.keys():
            keys.append(key)
        for key in keys:
            db.cleanNPCFromRoom(npcs[key])
        db.updateMovements(player,'NULL','NULL',20,22,'NULL','NULL')
        db.updateRoomState(22,6)

    elif item == "sleepingpotion" and item in player.inventory and player.roomID == 33 and roomState==2:
        db.updateRoomState(player.roomID, 3)
        player.inventory.remove(item)
        printRoomStateOrDescription(player)
        npcs = db.getNPCsInRoom(player.roomID)
        keys = []
        for key in npcs.keys():
            keys.append(key)
        for key in keys:
            db.cleanNPCFromRoom(npcs[key])
        raise SystemExit

    elif item == "healthpotion" and item in player.inventory:
        db.modifyhp(15)
        player = db.updatePlayer(player)
        player.inventory.remove(item)
        db.useItem(item)
        print("You drink the health potion. You feel reinvigorated as the "
              "healing potion surges through your body, mending the wounds "
              "and restoring your beaten physique."
              )

    elif item in player.inventory:
        print('''Using item "{}" doesn't make sense.'''.format(item))

    else:
        print('Cannot use item "{}".'.format(item))
Esempio n. 2
0
def fight(player=None, npcs={}, npc=None):
    if npc == None:
        while npcs != {}:
            for i in range(0,len(npcs)):
                npcs = fight(player,npcs,'0')

    elif npcs[npc].NPCName=='Dragon':
        db.updateRoomState(player.roomID, 2)
        printRoomStateOrDescription(player)
        raise SystemExit

    elif npcs[npc].NPCName=='Spider':
        db.updateRoomState(player.roomID, 1)
        printRoomStateOrDescription(player)
        raise SystemExit

    elif npcs[npc].NPCName == "Zhaltrauc":
        shieldIsActive = False
        useShield = input("The gem on Zhaltrauc's crown begins to glow!")
        if useShield.lower() == "use shield" and "shield" in player.inventory:
            shieldIsActive=True
            print("Zhaltrauc shoot's a beam of light from his gem. You lift "
                  "your shield just in time and deflect the shot, blinding "
                  "Zhaltrauc!")
        else:
            print("Blinding light flashes from Zhaltrauc's gem! You are blinded by the light!")

        # Attack turn
        if shieldIsActive:
            attack = action.attack(player, npcs[npc])
            db.modifyNPCHP(attack, npcs[npc])
            npcs[npc] = db.updateNPC(npcs[npc])
            player = db.updatePlayer(player)
            if npcs[npc].HP <= 0:
                print("{} {} died.".format(npcs[npc].NPCName,
                                           npcs[npc].ID))

                db.modifypoints(db.getPointsFromNPC(npcs[npc].ID))
                db.cleanNPCFromRoom(npcs[npc])
                npcs = db.getNPCsInRoom(player.roomID)
                db.updateRoomState(player.roomID,1)
                printRoomStateOrDescription(player)
                raise SystemExit

        # Dodge turn
        if not shieldIsActive:
            if npcs[npc].HP > 0:
                dodge = action.dodge(player, npcs[npc])
                db.modifyhp(dodge)
                npcs[npc] = db.updateNPC(npcs[npc])
                player = db.updatePlayer(player)
                if player.HP <= 0:
                    print("You died.")
                    raise SystemExit

    elif npc in npcs.keys():
        enemyIsAlive = True
        while enemyIsAlive:
            # Attack turn
            attack = action.attack(player, npcs[npc])
            db.modifyNPCHP(attack, npcs[npc])
            npcs[npc] = db.updateNPC(npcs[npc])
            player = db.updatePlayer(player)
            input('Press "Enter"')
            # Dodge turn
            for npc in npcs.keys():
                npcs = db.getNPCsInRoom(player.roomID)
                if npc in npcs.keys():
                    if npcs[npc].HP > 0:
                        dodge = action.dodge(player, npcs[npc])
                        db.modifyhp(dodge)
                        npcs[npc] = db.updateNPC(npcs[npc])
                        player = db.updatePlayer(player)
                        if player.HP <= 0:
                            print("You died.")
                            raise SystemExit

                if npc in npcs.keys():
                    if npcs[npc].HP <= 0:
                        print("{} {} died.".format(npcs[npc].NPCName,
                                                   npcs[npc].ID))

                        db.modifypoints(db.getPointsFromNPC(npcs[npc].ID))
                        db.cleanNPCFromRoom(npcs[npc])
                        npcs = db.getNPCsInRoom(player.roomID)

                        enemyIsAlive = False
                        if player.roomID == 1:
                            db.updateMovements(player,
                                               2, 'NULL', 'NULL', 'NULL',
                                               'NULL', 'NULL')

                        if player.roomID == 6 and npcs == {}:
                            db.updateMovements(player,
                                               'NULL', 'NULL', 5, 'NULL',
                                               'NULL', 'NULL')
                            db.updateRoomState(player.roomID, 1)
                            printRoomStateOrDescription(player)
                            db.updateRoomState(player.roomID, 2)

                        if player.roomID == 10:
                            db.updateRoomState(player.roomID, 2)
                            printRoomStateOrDescription(player)

                        if player.roomID == 12 and npcs == {}:
                            db.updateMovements(player,
                                               'NULL', 10, 13, 'NULL', 'NULL',
                                               'NULL')
                            db.updateRoomState(player.roomID, 1)
                            printRoomStateOrDescription(player)
                            db.updateRoomState(player.roomID, 2)

                input('Press "Enter"')

    else:
        print('Cannot fight with "{}".'.format(npc))

    return npcs
Esempio n. 3
0
        # validate to player that we are in correct context
        prompt = "(main) >>> "
        try:
            # in main menu context we catch only integers as commands
            c = int(input(prompt))
            context = command.doMenu(c)
        except ValueError as e:
            print(e)

    while context == "game":
        # validate to player that we are in correct context
        prompt = "(game) >>> "
        hp=db.gethp()
        points=db.getPointsFromPlayer()
        # update player object and if doesn't exist yet create it
        player = db.updatePlayer(player)

        print("\nYour HP: {}".format(hp) )
        print("Your points: {}".format(points))

        # get directions player can go
        directions = db.getDirections(player.roomID)

        # get items in room player can take
        items = db.getItemsInRoom(player.roomID)

        # get NPCs in room player can action (talk or fight)
        npcs = db.getNPCsInRoom(player.roomID)

        # ask a command from player
        c = input(prompt).lower().split()