def print_dungeon(dungeon,player_pos1,player_pos2,treasure_pos):
  # Takes in the lists and prints out dungeon
  outline(30)
  print("THE DUNGEON")
  print_new_lines(1)
  temp_row = ""
  for row in range(0,len(dungeon)):
    for col in range(0,len(dungeon[row])):
      if row == player_pos1 and col == player_pos2:
        dungeon[row][col] = 1
         # Uses player_pos and treasure_pos to mark them on the dungeon
        if row == 3 and col == 3:
          temp_row += "[ X ]️🗝️"
        elif row == 3 and col == 4:
          temp_row += " [ X  ☠ ]"
        else:
          temp_row += "[ X ]"
      else:
        if dungeon[row][col] == 0:
          temp_row += "     "
        elif (row,col) in treasure_pos:
          temp_row += "[ 🗝️ ]"
        elif row == 3 and col == 3:
          temp_row += "[ - ]🗝️"
        else:
          temp_row += "[ - ]"
    print(temp_row)
    temp_row = ""
  outline(30)
  print_new_lines(1)
示例#2
0
def active_actions():
  global monster_fight
  global player_input
  global monster_list
  global monster_index
  global boss_list
  global boss_index
  monster = monster_list[monster_index]
  boss = boss_list[boss_index]
  # Executes actions player can make during combat
  read_text(narrator_lines.general[0]) # What to do?
  print_actions(player.activeActions)
  check_invalid_input(player.inactiveActions)
  if player_input == 1: # ATTACK
    deal_attack("PLAYER",player.name,player.attack,player.baseAtk,player.critPercentage)
    if in_monster_fight == True and (player.position1,player.position2) in monster_positions:
      check_currentHP("MONSTER")
      if in_monster_fight == False: #IF MONSTER DIED
        print_victory_message(monster.name,earnedGold,monster.XP)
        # Prevents the player from encountering the same monster once defeated
        remove_events(player.position1,player.position2,monster_positions)
        player_progression(monster.XP)
    elif in_monster_fight == True and (player.position1,player.position2) == boss_position:
      check_currentHP("BOSS")
      if in_monster_fight == False: #IF BOSS DIED
        print_victory_message(boss.name,earnedGold,boss.XP)
        player_progression(boss.XP)
    print_new_lines(1)
  elif player_input == 2: # VIEW INVENTORY
    view_inventory()
示例#3
0
def print_actions(player_action):
  global player_input
  # Prints all actions player can make
  i = 1
  for action in player_action:
    print("[" + str(i) + "] " + action, end = ' ')
    i += 1
  print_new_lines(1)
  player_input = int(input(""))
示例#4
0
def stat_progression():
  player.maxHP += 1
  player.currentHP = player.maxHP
  print_new_lines(2)
  if player.level % 2 == 0 and player.level != 2:
    player.baseAtk += 1
    player.attack = [player.baseAtk-1,player.baseAtk,player.baseAtk+1]
    read_text("Your maxHP grew to "+ str(player.maxHP) +" and your baseAtk increased by one!")
  else:
    read_text("Your maxHP grew to "+ str(player.maxHP) +"!")
  pause(1)
示例#5
0
def view_item(player_item):
  # Views any given item and tells the player what it does
  outline(50)
  print(str(player_item.name))
  print_new_lines(1)
  read_text(str(player_item.description))
  if player_item.buffName == "HEALTH":
    read_text(" Restores +" + str(player_item.buff) + " " + player_item.buffName+" when consumed.")
  elif player_item.buffName == "ATTACK":
    read_text(" Gives +" + str(player_item.buff) + " " + player_item.buffName+" when equipped.")
  outline(50)
示例#6
0
def enemy_encounter(nameStr,enemyName,enemyAttack,enemyCurrentHP,enemyMaxHP,enemyBaseAtk,enemyCritPercentage):
  if player.turnsTaken == 0: 
  # Notifies player that they encountered a monster
    read_text("As soon as you walked in, you encountered a " + enemyName + "!!!")
    player.turnsTaken += 1
  else: 
  # The monster attacks
    deal_attack(nameStr,enemyName,enemyAttack,enemyBaseAtk,enemyCritPercentage)
    check_currentHP("PLAYER")
  print_new_lines(1)
  view_stats(enemyName,enemyCurrentHP,enemyMaxHP,enemyBaseAtk,False)
示例#7
0
def play_prologue():
  global player_input
  # Reads player description (name, type, and hometown)
  read_text("Welcome, " + str(player.name) + " you are a " + str(player.type) + " that lives in a small village called " + str(player.hometown) + ". You are about to enter the world of monsters, dragons, and most importantly...")
  pause(1.5)
  print_new_lines(2)
  read_text(narrator_lines.prologue[2])
  player_input = input(" ")
  clear()
  pause(1)
  read(narrator_lines.prologue,3,4)
  pause(2)
示例#8
0
def player_progression(monsterXP):
  player.currentXP += monsterXP
  pause(1.5)
  if player.currentXP >= player.baseXP:
      player.level += 1
      print_new_lines(2)
      read_text("You leveled up! You are now a Lvl "+ str(player.level) +" "+ str(player.type) +"!")
      remainder = player.currentXP - player.baseXP
      player.currentXP = 0 + remainder
      player.baseXP = nextLevel(player.level)
      stat_progression()
  pause(1)
示例#9
0
def unequip_item(player_item):
  # Unequips item from player's hand and removes all its buffs
  global player_equipped
  global player_input
  # Checks if player_item is not in thier hand
  if player_item not in player.hand:
    read_text("This item is not in your hand.")
    print_new_lines(1)
  else:
    # Unequips player_item, removes its buffs, and places it back into the inventory
    player.hand[0].quantity += 1
    player.inventory.append(player.hand[0])
    player.baseAtk += -player.hand[0].buff
    player.attack = [player.baseAtk-1,player.baseAtk,player.baseAtk+1]
    player.hand.remove(player.hand[0])
    player_equipped = False
    read_text("You now unequipped the " + str(player_item.name) + ".")
    print_new_lines(1)
示例#10
0
def ask_for_direction(row,col):
  global player_input
  read_text(narrator_lines.general[2]) # Which way?
  print_actions(player.posDirections)
  check_invalid_input(player.posDirections)
  chosen_direction = player.posDirections[player_input-1]
  print_new_lines(1)
  # Checks if player is at boss gate
  if row == 3 and col == 3 and chosen_direction == "RIGHT" and key not in player.inventory and boss_position in locked_positions:
    read_text("You will need a key to unlock the gate.")
  elif row == 3 and col == 3 and chosen_direction == "RIGHT" and boss_position in locked_positions:
    read_text("Use the key to unlock the gate.")
  elif row == 3 and col == 3 and chosen_direction == "RIGHT" and boss_position not in locked_positions:
    read_text("Get ready...")
    player_movement(chosen_direction)
  else:
    check_invalid_input(player.posDirections)
    player_movement(chosen_direction)
  pause(.8)
示例#11
0
def inventory_actions():
  # Executes all the actions the player can make when they are in their inventoyr
  global in_inventory 
  global player_input
  global player_item
  in_inventory = True
  while in_inventory == True:
    # Goes back to other actions if the inventory is empty
    if len(player.inventory) == 0 and len(player.hand) == 0:
      in_inventory = False
      choose_action()
    else:
      read_text(narrator_lines.general[0]) # What to do?
      print_new_lines(2)
      print_actions(player.inventoryActions)
      check_invalid_input(player.inventoryActions)
      if player_input == 1: # USE ITEM 
        if check_player_inventory(True,False):
          print_items(True,False,False,player.inventory)
          use_item(player_item)
        else:
          read_text("You have no items that can be used.")
          print_new_lines(1)
      elif player_input == 2: # VIEW ITEM 
        print_items(False,False,True,player.inventory)
        view_item(player_item)
      elif player_input == 3: # EQUIP ITEM
        if check_player_inventory(False,True):
          print_items(False,True,False,player.inventory)
          equip_item(player_item)
        else:
          read_text("You have no items that can be equipped.")
          print_new_lines(1)
      elif player_input == 4: # UNEQUIP ITEM
        if len(player.hand) == 1:
          unequip_item(player_item)
        else:
          read_text("You have nothing in your hand.")
          print_new_lines(1)
      elif player_input == 5: # EXIT INVENTORY
        in_inventory = False
        choose_action()
      print_new_lines(1)
示例#12
0
def print_items(condition1,condition2,condition3,list1):
  # Prints the player's items and asks for which one to apply an action to (use, view, equip)
  global player_input
  global player_item
  if list1 == player.inventory and len(list1) == 0:
    read_text(narrator_lines.inventory[0])
  else:
    print_new_lines(1)
    read_text("Which item? ")
    i = 1
    for item in list1:
      if item.consumable == condition1 and item.equippable == condition2 or condition3:
        print("[" + str(i) + "] " + str(item.name),end=" ")
        i += 1
        player.posItems.append(item)
  print_new_lines(1)
  player_input = int(input(""))
  check_invalid_input(player.posItems)
  player_item = player.posItems[player_input-1]
  player.posItems = []
示例#13
0
def shop_actions():
  global in_shop
  print_new_lines(1)
  read_text(narrator_lines.general[0])
  print_new_lines(2)
  print_actions(player.shopActions)
  check_invalid_input(player.shopActions)
  if player_input == 1: #BUY ITEM
      print_items(False,False,True,shop_items)
      chosen_item = shop_items[player_input-1]
      if player.gold < chosen_item.value:
        read_text("You can't afford that item.")
      elif chosen_item.shopQuantity <= 0:
        read_text("There are no more of that item.")
      else:
        player.gold += -chosen_item.value
        player.inventory.append(chosen_item)
        chosen_item.quantity += 1
        chosen_item.shopQuantity += -1
        read_text("You bought a "+str(chosen_item.name)+"!")
  elif player_input == 2: # VIEW ITEMS
    print_items(False,False,True,shop_items)
    chosen_item = shop_items[player_input-1]
    view_item(chosen_item)
  elif player_input == 3:
    read_text("The shopkeeper thanked you for your business.")
    print_new_lines(1)
    in_shop = False
示例#14
0
def open_shop():
  global in_shop
  # TODO: Simplify this function
  read_text("What can I get you?")
  while in_shop == True:
    print_new_lines(1)
    outline(40)
    print("THE SHOP")
    print_new_lines(1)
    for item in shop_items:
      if item.shopQuantity <= 0:
        print(str(item.name)+" [SOLD OUT]",end=" ")
      else:  
        print("x"+str(item.shopQuantity)+" "+str(item.name)+" ["+str(item.value)+" GOLD]",end=" ")
      print_new_lines(2)
    if player.gold == 0:
      read_text(narrator_lines.shop[2])
      in_shop = False
    else:
      read_text("You have " + str(player.gold) +" GOLD.")
      outline(40)
      shop_actions()
      pause(2)
      clear()
      pause(2)
示例#15
0
def get_directions(row,col):
  # Takes in player's positions and prints out possible directions
  # Checks where player can go and prevents them from going out of bounds
  UP = player.directions[0]
  DOWN = player.directions[1]
  LEFT = player.directions[2]
  RIGHT = player.directions[3]
  print_new_lines(1)
  player.posDirections = []
  player.posDirectionKeys = []
  if row == 4 and col == 0:
    #SPAWN POINT (UP)
    append_posDirections(UP)
  elif row == 3 and col == 3:
    #GATE TO BOSS ROOM (UP,LEFT,RIGHT)
    append_posDirections(UP,LEFT,RIGHT)
  elif row == 0 and col == 0:
    #TOP LEFT CORNER (DOWN, RIGHT)
    append_posDirections(DOWN,RIGHT) 
  elif row == 0 and col == 3:
    #TOP RIGHT CORNER (DOWN, LEFT)
    append_posDirections(DOWN,LEFT)
  elif row != 0 and row != 4 and col == 0:
    #LEFT SIDE (UP,DOWN,RIGHT)
    append_posDirections(UP,DOWN,RIGHT)
  elif row == 0 and col in [1,2]:
    #TOP SIDE (DOWN, LEFT, RIGHT)
    append_posDirections(DOWN,LEFT,RIGHT)
  elif row == 3 and col in [1,2,3]:
    #BOTTOM SIDE (UP,LEFT, RIGHT)
    append_posDirections(UP,LEFT,RIGHT)
  elif row != 0 and row != 3 and col in [3]:
    #RIGHT SIDE (UP, DOWN, LEFT)
    append_posDirections(UP,DOWN,LEFT)
  else:
    #IN THE MIDDLE
    append_posDirections(UP,DOWN,LEFT,RIGHT)
  for i in range(0,len(player.posDirections)-1):
      player.posDirectionKeys.append(i+1)
  ask_for_direction(row,col)
示例#16
0
def equip_item(player_item):
  # Equips a given item and applies it buff until player unquips it
  global player_equipped
  global player_input
  print_new_lines(1)
  # Checks if the player already has an item in their hand
  if player_equipped == True:
    read_text("This will unequip the " +str(player.hand[0].name)+ " you currently have on your hand.")
    print_new_lines(1)
    read_text("Are you sure you want to equip " + str(player_item.name)+"?")
    print_actions(player.choices)
    if player_input == 1: # Player equips player_item and removes thier hand
      # Removes the item and their buffs from player's hand
      player.baseAtk += -player.hand[0].buff
      player.inventory.append(player.hand[0])
      player.hand[0].quantity += 1
      # Removes item from inventory if they're not the same item
      if player_item.id != player.hand[0].id:
        player.inventory.remove(player_item)
      player_item.quantity += -1
      player.hand.remove(player.hand[0])
      # Equips player_item, applies its buff and removes it from inventory
      player.hand.append(player_item)
      player.baseAtk += player_item.buff
      player.attack = [player.baseAtk-1,player.baseAtk,player.baseAtk+1]
      player_equipped = True
    else:
      inventory_actions()
    # Equips the player_item if the player has nothing in their hand
  elif player_equipped == False: 
    # Equips player_item, applies its buff and removes it from inventory
    player_item.quantity += -1
    player.hand.append(player_item)
    player.inventory.remove(player_item)
    player.baseAtk += player_item.buff
    player.attack = [player.baseAtk-1,player.baseAtk,player.baseAtk+1]
    player_equipped = True
    read_text("You are now equipped with a " + str(player_item.name) + ". It granted you + " + str(player_item.buff) +" "+ str(player_item.buffName)+"!")
    print_new_lines(1)
示例#17
0
def print_victory_message(name,value,XP):
  # Prints a victory message after player defeats a monster or boss
  print_new_lines(2)
  read_text("Great job! You defeated the " + str(name) + " and gained "+ str(XP) +" XP! You also gained " +  str(value) + " GOLD!!")
示例#18
0
def view_inventory():
  global item_list
  global player_input
  # Prints out player inventory
  outline(50)
  # Checks if player has nothing
  if len(player.inventory) == 0 and player.gold == 0 and len(player.hand) == 0:
    read_text(narrator_lines.inventory[0]) # You have nothing.
  else:
    # Lists out all the items the player has
    read_text(narrator_lines.inventory[1]) # You have
    print_new_lines(1)
    read_text(str(player.gold) + " GOLD") 
    print_new_lines(1)
    if len(player.inventory) == 0:
      pause(1.5)
      print_new_lines(1)
      read_text(narrator_lines.inventory[2]) # But, you have nothing else in your inventory
    else:
      for item in player.inventory:
        print_new_lines(1)
        read_text("x"+str(item.quantity)+" "+str(item.name))
        print_new_lines(1)
    print_new_lines(1)
    if player_equipped == True:
      # Prints out what player has equipped in their hand
      read_text("You are equipped with a " + str(player.hand[0].name) + ".")
    else:
      read_text(narrator_lines.inventory[3]) # You have nothing equipped in your hand
  outline(50)
  print_new_lines(1)
  if len(player.inventory) == 0 and len(player.hand) == 0:
    # If there is nothing in their inventory, print other actions, else print out specific actions in the inventory
    choose_action()
  else:
    inventory_actions()
示例#19
0
def use_item(player_item):
  global player_position_tuple
  global locked_positions
  # Uses given item and applies the buffs to the player
  # Currently the player can use items that will give them restored health
  if player_item.buffName == "HEALTH":
    player_item.quantity += -1
    if player_item.quantity == 0:
      player.inventory.remove(player_item)
    player.currentHP += player_item.buff
    print_new_lines(1)
    read_text("You feel better and restored " + str(player_item.buff) + " health!")
    print_new_lines(1)
    # Caps the player's health at max 
    if player.currentHP > player.maxHP:
      player.currentHP = player.maxHP 
  elif player_item.buffName == "OTHER": #KEY
    # Note: There is only one locked position in the game
    # This checks if player is on (3,3)
    # This function converts the tuple to (3,4)
    if (player.position1,player.position2+1) in locked_positions:
      remove_events(player.position1,player.position2,locked_positions)
      print_new_lines(1)
      read_text("You succussfully unlocked the gate!")
      player_item.quantity += -1
      if player_item.quantity == 0:
        player.inventory.remove(player_item)
      print_new_lines(1)
    elif (player.position1,player.position2) in treasure_positions:
      # Generates what's inside chest
      earnedGold = random.randint(20,80)
      treasure_positions.remove((player.position1,player.position2))
      print_new_lines(1)
      read_text("You succussfully unlocked the treasure chest! You found " + str(earnedGold) + " GOLD!")
      item_drop()
      if has_dropped_item == True and flg1 == True:
        print_dropped_items("CHEST")
        print_new_lines(1)
      player.gold += earnedGold
      player_item.quantity += -1
    else:
      read_text("You need to have something to unlock to use the key.")
示例#20
0
## MAIN LOOP ##



# Runs game until player has died
while game_state == True and player_died == False:
  dungeon = generate_dungeon()
  monster_positions = generate_events(5,monster_positions)
  treasure_positions = generate_events(2,treasure_positions)
  trap_positions = generate_events(2,trap_positions)
  if player.dungeonsCleared == 0 and skip_story == False:
    read(narrator_lines.story,0,7)
  print_hand(player.hand)
  flg1 = True
  print_new_lines(1)
  while in_dungeon == True and player_died == False:
    print_dungeon(dungeon,player.position1,player.position2,treasure_positions)
    if in_monster_fight == True and (player.position1,player.position2) in monster_positions:
      monster = monster_list[monster_index]
      enemy_encounter("MONSTER",monster.name,monster.attack,monster.currentHP,monster.maxHP,monster.baseAtk,monster.critPercentage)
      remove_events(player.position1,player.position2,trap_positions)
    elif in_monster_fight == True and (player.position1,player.position2) == boss_position:
      boss = boss_list[boss_index]
      enemy_encounter("BOSS",boss.name,boss.attack,boss.currentHP,boss.maxHP,boss.baseAtk,boss.critPercentage)
    elif player.position1 == 3 and player.position2 == 3:
      # Prints dropped items if monster happens to be at the boss gate
      if has_dropped_item == True and flg1 == True:
        print_dropped_items(monster.name)
        remove_events(player.position1,player.position2,treasure_positions)
        print_new_lines(2)