Advertisement
AgentFelix

Grimsite | Old Start

Nov 19th, 2018
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.70 KB | None | 0 0
  1. from assets import *
  2. import pickle
  3. import time
  4. import sys
  5. import os.path
  6.  
  7. def print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100):
  8.     """
  9.    Call in a loop to create terminal progress bar
  10.    @params:
  11.        iteration   - Required  : current iteration (Int)
  12.        total       - Required  : total iterations (Int)
  13.        prefix      - Optional  : prefix string (Str)
  14.        suffix      - Optional  : suffix string (Str)
  15.        decimals    - Optional  : positive number of decimals in percent complete (Int)
  16.        bar_length  - Optional  : character length of bar (Int)
  17.    """
  18.     str_format = "{0:." + str(decimals) + "f}"
  19.     percents = str_format.format(100 * (iteration / float(total)))
  20.     filled_length = int(round(bar_length * iteration / float(total)))
  21.     bar = '█' * filled_length + '-' * (bar_length - filled_length)
  22.  
  23.     sys.stdout.write('\r%s |%s| %s%s %s' % (prefix, bar, percents, '%', suffix)),
  24.  
  25.     if iteration == total:
  26.         sys.stdout.write('\n')
  27.     sys.stdout.flush()
  28.    
  29. class App:
  30.     #initialize the Application
  31.     def __init__(self):
  32.         #print info
  33.         print("TermiPG - Felix Martin Productions V0.0.1")
  34.        
  35.     def newPlayer(self, first, last, path):
  36.         global hero
  37.         dummy1 = WarriorCharacter("dummy", "dummy")
  38.         dummy2 = BerserkerCharacter("dummy", "dummy")
  39.         try:
  40.             if path.upper() == "WARRIOR":
  41.                 hero = WarriorCharacter(first, last)
  42.                 self.termiPG()
  43.             elif path.upper() == "BERSERKER":
  44.                 hero = BerserkerCharacter(first, last)
  45.                 self.termiPG()
  46.             elif path.upper() == "LIST":
  47.                 print("Available Classes:\n------------------\n")
  48.                 print("Warrior: {}\n".format(dummy1.desc))
  49.                 print("Stats\n-----")
  50.                 dummy1.show_stats("OFFENSIVE")
  51.                 dummy1.show_stats("DEFENSIVE")
  52.                 print("\nBerserker: {}\n".format(dummy2.desc))
  53.                 print("Stats\n-----")
  54.                 dummy2.show_stats("OFFENSIVE")
  55.                 dummy2.show_stats("DEFENSIVE")
  56.             elif path.upper() == "MENU":
  57.                 self.termiPG()
  58.             else:
  59.                 print("Invalid choice! Please type LIST, one of the available classes, or MENU to return to the main menu!")
  60.                 self.termiPG()
  61.         except:
  62.             print("Error creating new character.")
  63.     #load file function
  64.     def loadPlayer(self, fileName):
  65.         try:
  66.             if os.path.exists(fileName.upper()):
  67.                 hero.load(fileName)
  68.                 self.termiPG()
  69.             else:
  70.                 print("Save file not found. ")
  71.                 self.termiPG()
  72.         except:
  73.             print("Error loading player.")
  74.             self.termiPG()
  75.            
  76.     #main menu function
  77.     def termiPG(self):
  78.  
  79.         #init the menu
  80.         print("Type a command, help or quit to exit the program.")
  81.         cmd = input("")
  82.         #if the cmd is help
  83.         if cmd.upper() == "HELP":
  84.             print("Available commands are: addContact, delContact, writeFile, readFile, help, quit")
  85.            
  86.             self.contact_manager(db)
  87.         #or if the cmd is addcontact
  88.         elif cmd.upper() == "ADDCONTACT":
  89.            
  90.             self.add_contact_to_db(db, input("What is the contacts reference name?\n").upper(), input("What is the contacts first name?\n").upper(), input("What is the contacts last name?\n").upper(), input("What is the contacts (cell/main/home/etc) number?\n").upper(), input("What is the contacts address?\n").upper())
  91.         #or if the cmd is writefile...
  92.         elif cmd.upper() == "WRITEFILE":
  93.            
  94.             self.write_db_to_file(db, "contacts.txt")
  95.         #... etc etc etc
  96.         elif cmd.upper() == "READFILE":
  97.            
  98.             self.search_contact(db, input("What contact shall you search?\n").upper())
  99.        
  100.         elif cmd.upper() == "DELCONTACT":
  101.            
  102.             self.remove_user_from_db(db, input("What contact shall you delete?\n"))
  103.         #if the cmd is quit
  104.         elif cmd.upper() == "QUIT":
  105.             #thank the user for using my program
  106.             print("Thank you for using Contact Manager.")
  107.             #delay2 seconds
  108.             time.sleep(2)
  109.             quit()
  110.  
  111.         #if the user activates the secret command
  112.         elif cmd.upper() == "DEBUG()":
  113.            
  114.             print("Activating DEBUG Function.\n")
  115.             print(db)
  116.             self.contact_manager(db)
  117.         #finally, if it is none of these
  118.         else:
  119.             print("Unknown command.")
  120.             self.contact_manager(db)
  121.            
  122. #run the app    
  123. App()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement