176 lines
7.3 KiB
Python
176 lines
7.3 KiB
Python
#TODO comments explaining stuff
|
|
import data # Import data.py which contains the businesses and leaderboards
|
|
from datetime import datetime
|
|
import math
|
|
try:
|
|
import save # TODO saving functionality
|
|
except:
|
|
with open("save.py", "w") as file:
|
|
content = f"businesses = []\nmoney = 100\ndatetime = {datetime.now().strftime('%s')}\nfine_count = 0"
|
|
# Commands
|
|
# 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
|
|
|
|
def millify(n):
|
|
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
|
|
|
|
def try_arrest():
|
|
current_day = datetime.now().strftime("%d")
|
|
current_month = datetime.now().strftime("%m")
|
|
current_year = datetime.now().strftime("%Y")
|
|
if datetime.fromtimestamp(int(save.datetime)).strftime("%d") != current_day or datetime.fromtimestamp(int(save.datetime)).strftime("%m") != current_month or datetime.fromtimestamp(int(save.datetime)).strftime("%Y") != current_year:
|
|
for biz in save.businesses:
|
|
threat += biz['cost']
|
|
if rand_bool(threat):
|
|
if save.fine_count >= len(data.fines):
|
|
save.money -= data.fines[len(data.fines)-1]
|
|
print(f"You've been fined {data.currency}{data.fines[len(data.fines)-1]}")
|
|
else:
|
|
save.money -= data.fines[save.fine_count]
|
|
print(f"You've been fined {data.currency}{data.fines[save.fine_count]}")
|
|
save.fine_count += 1
|
|
save_game()
|
|
|
|
def add_new_money():
|
|
current_time = datetime.now().strftime("%s")
|
|
time_difference = int(current_time) - int(save.datetime)
|
|
time_passed = time_difference * data.time_rate
|
|
for biz in save.businesses:
|
|
earning = biz['earning']
|
|
save.money += (earning / 3600) * time_passed
|
|
|
|
def display_leaderboard():
|
|
leaderboard = data.leaderboard
|
|
networth = save.money
|
|
for biz in save.businesses:
|
|
networth += biz['cost']
|
|
leaderboard.append(["Yourself", round(networth,2)])
|
|
leaderboard = sorted(leaderboard, key=lambda leaderboard: leaderboard[1], reverse=True)
|
|
for index in range(len(leaderboard)):
|
|
print(f"#{index+1}: {leaderboard[index][0]} {data.currency}{millify(leaderboard[index][1])}")
|
|
|
|
def save_game():
|
|
with open("save.py", "w") as file:
|
|
content = f'''businesses = {save.businesses}\nmoney = {save.money}\ndatetime = {save.datetime}\nfine_count = {save.fine_count}'''
|
|
file.write(content)
|
|
|
|
def main():
|
|
add_new_money()
|
|
print("Welcome, entrepeneur")
|
|
game_loop = True
|
|
while game_loop:
|
|
save.datetime = datetime.now().strftime("%s")
|
|
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":
|
|
save.datetime = datetime.now().strftime("%s")
|
|
add_new_money()
|
|
save_game()
|
|
game_loop = False
|
|
|
|
### Buy a new business
|
|
elif user_input.lower() == "buy" or user_input.lower() == "shop":
|
|
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}{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
|
|
if user_input_int == -1:
|
|
continue
|
|
elif user_input_int < len(data.businesses) and save.money >= data.businesses[user_input_int]['cost']:
|
|
print(f"Buying {data.businesses[user_input_int]['pretty_name']}")
|
|
save.businesses.append(data.businesses[user_input_int])
|
|
save.money -= data.businesses[user_input_int]['cost']
|
|
else:
|
|
print("Invalid number")
|
|
except:
|
|
print("Didn't input a number")
|
|
|
|
### Sell an owned business
|
|
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}{millify(save.businesses[i]['cost'])}")
|
|
user_input = input()
|
|
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}{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}{millify(biz['earning'])}/hour")
|
|
total_earning += biz['earning']
|
|
networth += biz['cost']
|
|
threat += biz['threat']
|
|
|
|
if threat < 100:
|
|
print(f"Threat Level: {threat}%")
|
|
else:
|
|
print("Threat Level: MIDNIGHT")
|
|
print(f"Total earning: {data.currency}{millify(total_earning)}/hour")
|
|
print(f"Networth: {data.currency}{millify(networth)}")
|
|
print("----------------------------------")
|
|
|
|
### Display leaderboard
|
|
elif user_input.lower() == "leaderboard":
|
|
display_leaderboard()
|
|
|
|
elif user_input.lower() == "help":
|
|
print('''
|
|
Commands
|
|
help: help's the user
|
|
status: output's networth, available money, threat level, your businesses and earning/hour
|
|
shop/buy: lists available businesses
|
|
sell: sells that business
|
|
leaderboard: shows the wealth leaderboard
|
|
quit: exit's game
|
|
|
|
Additional functionality:
|
|
randomly get fined based on threat level
|
|
permanent saves
|
|
''')
|
|
elif user_input == "" or user_input == undefined:
|
|
print("",end="")
|
|
else:
|
|
print("Error: Invalid command")
|
|
|
|
### End of loop
|
|
add_new_money()
|
|
try_arrest()
|
|
save_game()
|
|
|
|
main()
|