Beispiel #1
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()
Beispiel #2
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
Beispiel #3
0
def trigger_trap():
  i = random.randint(0,len(narrator_lines.trap)-1)
  damage = random.randint(1,4)
  read_text("As soon as you walked in, "+narrator_lines.trap[i]+" ")
  read_text("You got hurt and dealt "+ str(damage)+"!") 
  player.currentHP += -damage
  trap_positions.remove((player.position1,player.position2))
  check_currentHP("PLAYER")
Beispiel #4
0
def print_narrator_verdict():
  # Prints how well the player did after they died 
  if player.dungeonsCleared <= 20:
    #YOU DID WELL FOR A BEGINNER
    read_text(narrator_lines.dead[1])
  elif player.dungeonsCleared > 20: 
    #YOU DID WELL AS A PRO
    read(narrator_lines.dead,1,2)
Beispiel #5
0
def get_player_info():
  # Asks for player name and hometown
  for i in range(0,2):
    read_text(narrator_lines.prologue[i])
    if i == 0:
      player.name = input(" ").upper()
    elif i == 1:
      player.hometown = input(" ").upper()
    clear()
    pause(1)
Beispiel #6
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)
Beispiel #7
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)
Beispiel #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)
Beispiel #9
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)
Beispiel #10
0
def inactive_actions():
  global in_monster_fight
  global player_input
  global monster_positions
  global player_input
  # Executes actions player can make during exploring a dungeon
  read_text(narrator_lines.general[0]) # What to do?
  print_actions(player.inactiveActions)
  check_invalid_input(player.inactiveActions)
  if player_input == 1: #MOVE
    get_directions(player.position1,player.position2)  
      # Checks if player positions is equal to a monster position in a list, which will trigger 
    if (player.position1,player.position2) in monster_positions:
      in_monster_fight = True
    elif (player.position1,player.position2) == boss_position:
      in_monster_fight = True
  elif player_input == 2: #VIEW INVENTORY
    view_inventory()
Beispiel #11
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)
Beispiel #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 = []
Beispiel #13
0
def print_dropped_items(name):
  global drop_list
  global has_dropped_item
  global flg1
  # Prints out the dropped items once
  if name == "CHEST":
    read_text(" You also found ")
  else:
    read_text("The " + str(name) + " dropped ")
  for i in range(0,len(drop_list)):
    if i == 0 and len(drop_list) == 1:
      read_text("a "+str(drop_list[i])+"!")
    elif i == 0:
      read_text("a "+str(drop_list[i]))
    elif i == len(drop_list)-1:
      read_text(" and a "+str(drop_list[i])+"!")
  # Empties drop_list and change booleans to FALSE to prevent message from repeating
  drop_list = []
  has_dropped_item = False
  flg1 = False
Beispiel #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)
Beispiel #15
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)
Beispiel #16
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)
Beispiel #17
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)
Beispiel #18
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.")
Beispiel #19
0
def deal_attack(player1,player1name,player1attack,player1baseAtk,player1critPercentage):
  # Draws a random float between 0 and 1 to decide attack damage
  random_float = random.random()
  if random_float <= player1critPercentage:
    # Chance of critical hit, which doubles the amount of attack damage
    read_text("CRITICAL! ")
    player1_attack = player1baseAtk * 2
  else:
    player1_attack = random.randint(player1attack[0],player1attack[2])
  if player1 == "MONSTER" or player1 == "BOSS": 
    # Prints what the mosnter or boss dealt to the player
    player.currentHP = player.currentHP - player1_attack
    read_text("The " + player1name + " dealt " + str(player1_attack) + " damage to you!")
  elif player1 == "PLAYER": 
    # Prints what the player dealt to monster or boss
    if in_monster_fight == True and (player.position1,player.position2) in monster_positions: # DEALS ATTACK TO MONSTER
      monster.currentHP = monster.currentHP - player1_attack
    elif in_monster_fight == True and (player.position1,player.position2) == boss_position: # DEALS ATTACK TO BOSS
      boss.currentHP = boss.currentHP - player1_attack
    read_text("You dealt " + str(player1_attack) + " damage to it!")
    pause(2)
Beispiel #20
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)
Beispiel #21
0
 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)
   # Prints gate to the boss
   read_text("You find yourself in a room with a locked gate in the east side. Something is locked in there, you thought. You hear a low, rumbling sound on the other side.")
 elif has_dropped_item == True and flg1 == True:
   print_dropped_items(monster.name)
   remove_events(player.position1,player.position2,treasure_positions)
 elif (player.position1,player.position2) in treasure_positions:
   read_text("You walk in to find a treasure chest right in the middle of the room. It appears to be locked.")
   # Prevents user from finding a treasure chest and then stumble across a trap
   remove_events(player.position1,player.position2,trap_positions)
 elif (player.position1,player.position2) in trap_positions:
   trigger_trap()
 else: 
   # You walk into empty room
   read_text(narrator_lines.inactive[0])
 print_new_lines(1)
 if player_died == False:
   # Prints player's stats and prints the possible actions
Beispiel #22
0
def print_hand(player_hand):
  if len(player_hand) == 0:
    read_text("You enter the dark entrance of the dungeon with nothing in your hand.")
  else:
    read_text("You enter the dark entrance of the dungeon, wielding a " + str(player_hand[0].name) +" in your hand.")
Beispiel #23
0
def check_invalid_input(player_action = "None"):
  global player_input
  # Checks for invalid integer inputs
  while player_input > len(player_action) or player_input < 1:
    read_text(narrator_lines.general[1])
    player_input = int(input(" "))
Beispiel #24
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()
Beispiel #25
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!!")