diff --git a/main.py b/main.py index 65286cc..792bc5e 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +#TODO comments explaining stuff import data # Import data.py which contains the businesses and leaderboards from datetime import datetime import math @@ -7,28 +8,25 @@ except: with open("save.py", "w") as file: content = f"businesses = []\nmoney = 100\ndatetime = {datetime.now().strftime('%s')}\nfine_count = 0" # Commands -# TODO help: help's the user +# help: help's the user # status: output's networth, available money, TL, your businesses and earning/hour # shop/buy: lists available businesses # sell: sells that business # leaderboard: shows the wealth leaderboard # quit: exit's game +# TODO upgrade: upgrades some stats about a business for some money # Additional functionality: # randomly get sent to get fined based on threat level, more than 5 fines means next time is prision and that's 2 years ingame # permanent saves -# https://stackoverflow.com/questions/3154460/python-human-readable-large-numbers def millify(n): - n = float(n) - millidx = max( - 0, - min( - len(data.millnames)-1, - int(math.floor(0 if n == 0 else math.log10(abs(n))/3)) - ) - ) - return '{:.0f}{}'.format(n / 10**(3 * millidx), data.millnames[millidx]) + exponent = len(str(round(n))) - 1 # n = 1,000 return 3, n = 300,000 returns 5 + millvalue = exponent//3 + millname = data.millnames[millvalue] # exponent = 3 returns K (thousand), exponent = 7 returns M (million) + #print(f"E: {exponent}, M: {millname}, Mv: {millvalue} = ",end="") + return f"{round((n/(10**(millvalue*3))),2)}{millname}" + #return '{:.0f}{}'.format(n / 10**(3 * millidx), data.millnames[millidx]) def rand_bool(percent): return random.randrange(100) < percent @@ -79,7 +77,7 @@ def main(): game_loop = True while game_loop: save.datetime = datetime.now().strftime("%s") - print(f"{data.currency}{round(save.money,2)} > ", end="") + print(f"{data.currency}{millify(save.money)} > ", end="") user_input = input() # TODO make this a match case? if user_input.lower() == "quit" or user_input.lower() == "exit": @@ -93,7 +91,7 @@ def main(): print(" 0: cancel") for i in range(len(data.businesses)): if data.businesses[i]['cost'] <= save.money: - print(f" {i+1}: {data.businesses[i]['pretty_name']}: {data.currency}{data.businesses[i]['cost']}, Earning: {data.currency}{data.businesses[i]['earning']}/hour, Threat: {data.businesses[i]['threat']}%") + print(f" {i+1}: {data.businesses[i]['pretty_name']}: {data.currency}{millify(data.businesses[i]['cost'])}, Earning: {data.currency}{millify(data.businesses[i]['earning'])}/hour, Threat: {data.businesses[i]['threat']}%") user_input = input() try: user_input_int = int(user_input) - 1 @@ -112,31 +110,28 @@ def main(): elif user_input.lower() == "sell": print(" 0: cancel") for i in range(len(save.businesses)): - print(f" {i+1}: {save.businesses[i]['pretty_name']}: {data.currency}{save.businesses[i]['cost']}") + print(f" {i+1}: {save.businesses[i]['pretty_name']}: {data.currency}{millify(save.businesses[i]['cost'])}") user_input = input() - try: - user_input_int = int(user_input) - 1 - if user_input_int == -1: - continue - elif user_input_int < len(data.businesses): - print(f"Selling {data.businesses[user_input_int]['pretty_name']}") - save.businesses.pop(user_input_int) - save.money += data.businesses[user_input_int]['cost'] - else: - print("Invalid number") - except: - print("Didn't input a number") + user_input_int = int(user_input) - 1 + if user_input_int == -1: + continue + elif user_input_int < len(data.businesses): + print(f"Selling {save.businesses[user_input_int]['pretty_name']}") + save.money += save.businesses[user_input_int]['cost'] + save.businesses.pop(user_input_int) + else: + print("Invalid number") ### Display info relavent to your enterprise elif user_input.lower() == "status": print("------------- STATUS -------------") - print(f"Money Available: {data.currency}{round(save.money,2)}") + print(f"Money Available: {data.currency}{millify(save.money)}") print("Your businesses:") total_earning = 0 networth = save.money threat = 0 for biz in save.businesses: - print(f" {biz['pretty_name']}: {data.currency}{biz['earning']}/hour") + print(f" {biz['pretty_name']}: {data.currency}{millify(biz['earning'])}/hour") total_earning += biz['earning'] networth += biz['cost'] threat += biz['threat'] @@ -145,8 +140,8 @@ def main(): print(f"Threat Level: {threat}%") else: print("Threat Level: MIDNIGHT") - print(f"Total earning: {data.currency}{total_earning}/hour") - print(f"Networth: {data.currency}{round(networth,2)}") + print(f"Total earning: {data.currency}{millify(total_earning)}/hour") + print(f"Networth: {data.currency}{millify(networth)}") print("----------------------------------") ### Display leaderboard