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))
def go(command, directions, player): if command[0] == "go" and len(command) == 1: if directions != {}: print("You can go: ") for direction in directions.keys(): print("\t* {}".format(direction)) else: print("You can't go anywhere, try to do something else.") elif command[0] == "go" and len(command) == 2: # cheat for testing game roomID = [] for i in range(1, 35): roomID.append(str(i)) if command[1] in directions: player.roomID = directions[command[1]] db.setPlayerRoomID(player.roomID) npcs = db.getNPCsInRoom(player.roomID) db.modifypoints(db.getPointsFromRoom(player.roomID)) if player.roomID == 2 and 'torch' in player.inventory: for i in (2, 3, 5): db.updateRoomState(i, 1) printRoomStateOrDescription(player) elif player.roomID in (3, 5) and 'torch' not in player.inventory: print(db.getRoomState(player.roomID)) raise SystemExit elif player.roomID == 6 and npcs != {}: printRoomStateOrDescription(player) fight(player,npcs) elif player.roomID == 7: if db.getRoomStateID(player.roomID) != 3: success = action.throwIntelligence(player) if success == 2: db.updateRoomState(player.roomID, 0) printRoomStateOrDescription(player) db.updateRoomState(player.roomID, 3) elif success == 1: db.updateRoomState(player.roomID, 1) printRoomStateOrDescription(player) db.modifyhp(-2) db.updateRoomState(player.roomID, 3) else: db.updateRoomState(player.roomID, 2) printRoomStateOrDescription(player) db.modifyhp(-10) db.updateRoomState(player.roomID, 3) else: printRoomStateOrDescription(player) elif player.roomID == 8: success = action.throwIntelligence(player) if success in (1, 2): db.updateRoomState(player.roomID, 0) printRoomStateOrDescription(player) db.updateMovements(player, 15, 7, 'NULL', 14, 'NULL', 'NULL') else: db.updateRoomState(player.roomID, 1) printRoomStateOrDescription(player) elif player.roomID == 11: printRoomStateOrDescription(player) items = db.getItemsInRoom(player.roomID) if "sword" in items: take(items, player, "sword") elif player.roomID == 12: printRoomStateOrDescription(player) fight(player,npcs) elif player.roomID == 13: printRoomStateOrDescription(player) if npcs != {}: for key, character in npcs.items(): if character.ID == 7: npc = npcs[key] quest = conversation.talk(npc) db.dropNPCItem(npc,"carddeck") db.cleanNPCFromRoom(npc) npcs = db.getNPCsInRoom(player.roomID) if quest == 1: fight(player, npcs) db.updateRoomState(player.roomID, 3) printRoomStateOrDescription(player) items = db.getItemsInRoom(player.roomID) if "carddeck" in items: take(items, player, "carddeck") db.updateRoomState(player.roomID, 1) printRoomStateOrDescription(player) if quest == 0: db.updateRoomState(player.roomID, 2) printRoomStateOrDescription(player) elif player.roomID == 15: if db.getRoomStateID(player.roomID) != 3: success = action.throwIntelligence(player) if success == 2: db.updateRoomState(player.roomID, 0) printRoomStateOrDescription(player) db.updateRoomState(player.roomID, 3) elif success == 1: db.updateRoomState(player.roomID, 1) printRoomStateOrDescription(player) db.modifyhp(-8) db.updateRoomState(player.roomID, 3) else: db.updateRoomState(player.roomID, 2) print(db.getRoomState(player.roomID)) raise SystemExit else: printRoomStateOrDescription(player) elif player.roomID == 17: printRoomStateOrDescription(player) if npcs != {}: for key, character in npcs.items(): if character.ID == 8: npc = npcs[key] quest = conversation.talk(npc) if quest == 1: db.dropNPCItem(npc,"healthpotion") db.cleanNPCFromRoom(npc) npcs = db.getNPCsInRoom(player.roomID) fight(player, npcs) db.updateRoomState(player.roomID, 4) printRoomStateOrDescription(player) items = db.getItemsInRoom(player.roomID) if "healthpotion" in items: take(items, player, "healthpotion") db.updateRoomState(player.roomID, 3) printRoomStateOrDescription(player) elif quest == 0: keys = [] for key, npc in npcs.items(): keys.append(key) for key in keys: db.cleanNPCFromRoom(npcs[key]) db.updateRoomState(player.roomID, 3) printRoomStateOrDescription(player) elif player.roomID == 19 \ and command[1] == "south" \ and "torch" in player.inventory: roomstate = db.getRoomStateID(18) if roomstate == 0: player.roomID = 18 db.setPlayerRoomID(player.roomID) db.updateRoomState(player.roomID,2) for i in (23,24): db.bringNPCToRoom(player.roomID,i) npcs = db.getNPCsInRoom(player.roomID) printRoomStateOrDescription(player) fight(player,npcs) db.updateRoomState(player.roomID,3) printRoomStateOrDescription(player) else: printRoomStateOrDescription(player) elif player.roomID == 21 \ and command[1] == "west" \ and player.playerClass == "barbarian": player.roomID = 20 db.setPlayerRoomID(player.roomID) db.updateRoomState(player.roomID,1) db.updateMovements(player,19,'NULL','NULL','NULL','NULL','NULL') printRoomStateOrDescription(player) db.updateRoomState(player.roomID,0) printRoomStateOrDescription(player) elif player.roomID == 21 \ and command[1] == "east" \ and player.playerClass == "barbarian": player.roomID = 22 db.setPlayerRoomID(player.roomID) db.updateMovements(player,23,'NULL','NULL','NULL','NULL',25) printRoomStateOrDescription(player) elif player.roomID == 22 \ and npcs != {} \ and "armor" in player.inventory \ and "carddeck" in player.inventory: if db.getRoomStateID(player.roomID) != 7: db.updateRoomState(22, 2) printRoomStateOrDescription(player) db.updateRoomState(22, 3) printRoomStateOrDescription(player) db.updateRoomState(22, 7) items = db.getItemsInRoom(player.roomID) if "gold" in items: take(items, player, "gold") print("You now have a huge pile of gold in your inventory") else: printRoomStateOrDescription(player) elif player.roomID == 22 \ and npcs != {} \ and "armor" in player.inventory: if db.getRoomStateID(player.roomID) not in (6,7): db.updateRoomState(22, 2) printRoomStateOrDescription(player) success = action.throwIntelligence(player) if success == 2: db.updateRoomState(player.roomID, 3) printRoomStateOrDescription(player) db.updateRoomState(22, 7) items = db.getItemsInRoom(player.roomID) if "gold" in items: take(items, player, "gold") print("You now have a huge pile of gold in your inventory") elif success != 2: db.updateRoomState(player.roomID, 4) printRoomStateOrDescription(player) fight(player,npcs) db.updateRoomState(player.roomID, 5) printRoomStateOrDescription(player) db.updateRoomState(22, 7) items = db.getItemsInRoom(player.roomID) if "gold" in items: take(items, player, "gold") print("You now have a huge pile of gold in your inventory") else: printRoomStateOrDescription(player) elif player.roomID == 22 and npcs != {}: if db.getRoomStateID(player.roomID) not in (6,7): db.updateRoomState(22, 0) printRoomStateOrDescription(player) fight(player,npcs) db.updateRoomState(player.roomID, 5) printRoomStateOrDescription(player) db.updateRoomState(22, 7) items = db.getItemsInRoom(player.roomID) if "gold" in items: take(items, player, "gold") print("You now have a huge pile of gold in your inventory") else: printRoomStateOrDescription(player) elif player.roomID == 22 and npcs =={}: db.updateRoomState(22, 7) printRoomStateOrDescription(player) elif player.roomID == 23 and 'armor' in player.inventory: db.updateRoomState(player.roomID, 2) printRoomStateOrDescription(player) elif player.roomID == 24: success = action.throwIntelligence(player) if success == 2: db.updateRoomState(player.roomID, 0) printRoomStateOrDescription(player) elif success == 1: db.updateRoomState(player.roomID, 1) printRoomStateOrDescription(player) db.modifyhp(-5) else: db.updateRoomState(player.roomID, 2) printRoomStateOrDescription(player) db.modifyhp(-10) elif player.roomID == 28: printRoomStateOrDescription(player) npcs = db.getNPCsInRoom(player.roomID) if npcs != {}: fight(player,npcs) db.updateRoomState(player.roomID, 1) elif player.roomID == 32 \ and command[1] == "east" \ and player.playerClass == "barbarian": player.roomID = 31 db.setPlayerRoomID(player.roomID) db.updateRoomState(player.roomID,1) db.updateMovements(player,'NULL',34,'NULL',27,'NULL','NULL') printRoomStateOrDescription(player) db.updateRoomState(player.roomID,0) printRoomStateOrDescription(player) elif player.roomID == 33 \ and command[1] == "south" \ and player.playerClass == "thief": db.updateRoomState(player.roomID, 2) printRoomStateOrDescription(player) elif player.roomID == 33 and npcs != {}: printRoomStateOrDescription(player) npcs = db.getNPCsInRoom(player.roomID) fight(player,npcs) else: # print room state after room is actually changed printRoomStateOrDescription(player) # cheat for testing game elif command[1] in roomID: player.roomID = int(command[1]) db.setPlayerRoomID(player.roomID) printRoomStateOrDescription(player) else: print( "Invalid direction. You can use " "only directions in list below:" ) for direction in directions.keys(): print("\t* {}".format(direction))