Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from assets import *
- import pickle
- import time
- import sys
- import os.path
- def print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100):
- """
- Call in a loop to create terminal progress bar
- @params:
- iteration - Required : current iteration (Int)
- total - Required : total iterations (Int)
- prefix - Optional : prefix string (Str)
- suffix - Optional : suffix string (Str)
- decimals - Optional : positive number of decimals in percent complete (Int)
- bar_length - Optional : character length of bar (Int)
- """
- str_format = "{0:." + str(decimals) + "f}"
- percents = str_format.format(100 * (iteration / float(total)))
- filled_length = int(round(bar_length * iteration / float(total)))
- bar = '█' * filled_length + '-' * (bar_length - filled_length)
- sys.stdout.write('\r%s |%s| %s%s %s' % (prefix, bar, percents, '%', suffix)),
- if iteration == total:
- sys.stdout.write('\n')
- sys.stdout.flush()
- class App:
- #initialize the Application
- def __init__(self):
- #print info
- print("TermiPG - Felix Martin Productions V0.0.1")
- def newPlayer(self, first, last, path):
- global hero
- dummy1 = WarriorCharacter("dummy", "dummy")
- dummy2 = BerserkerCharacter("dummy", "dummy")
- try:
- if path.upper() == "WARRIOR":
- hero = WarriorCharacter(first, last)
- self.termiPG()
- elif path.upper() == "BERSERKER":
- hero = BerserkerCharacter(first, last)
- self.termiPG()
- elif path.upper() == "LIST":
- print("Available Classes:\n------------------\n")
- print("Warrior: {}\n".format(dummy1.desc))
- print("Stats\n-----")
- dummy1.show_stats("OFFENSIVE")
- dummy1.show_stats("DEFENSIVE")
- print("\nBerserker: {}\n".format(dummy2.desc))
- print("Stats\n-----")
- dummy2.show_stats("OFFENSIVE")
- dummy2.show_stats("DEFENSIVE")
- elif path.upper() == "MENU":
- self.termiPG()
- else:
- print("Invalid choice! Please type LIST, one of the available classes, or MENU to return to the main menu!")
- self.termiPG()
- except:
- print("Error creating new character.")
- #load file function
- def loadPlayer(self, fileName):
- try:
- if os.path.exists(fileName.upper()):
- hero.load(fileName)
- self.termiPG()
- else:
- print("Save file not found. ")
- self.termiPG()
- except:
- print("Error loading player.")
- self.termiPG()
- #main menu function
- def termiPG(self):
- #init the menu
- print("Type a command, help or quit to exit the program.")
- cmd = input("")
- #if the cmd is help
- if cmd.upper() == "HELP":
- print("Available commands are: addContact, delContact, writeFile, readFile, help, quit")
- self.contact_manager(db)
- #or if the cmd is addcontact
- elif cmd.upper() == "ADDCONTACT":
- 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())
- #or if the cmd is writefile...
- elif cmd.upper() == "WRITEFILE":
- self.write_db_to_file(db, "contacts.txt")
- #... etc etc etc
- elif cmd.upper() == "READFILE":
- self.search_contact(db, input("What contact shall you search?\n").upper())
- elif cmd.upper() == "DELCONTACT":
- self.remove_user_from_db(db, input("What contact shall you delete?\n"))
- #if the cmd is quit
- elif cmd.upper() == "QUIT":
- #thank the user for using my program
- print("Thank you for using Contact Manager.")
- #delay2 seconds
- time.sleep(2)
- quit()
- #if the user activates the secret command
- elif cmd.upper() == "DEBUG()":
- print("Activating DEBUG Function.\n")
- print(db)
- self.contact_manager(db)
- #finally, if it is none of these
- else:
- print("Unknown command.")
- self.contact_manager(db)
- #run the app
- App()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement