did some commenting, should document the whole thing better tmrw
This commit is contained in:
parent
0dfcca72e2
commit
365c6359bc
51
main.py
51
main.py
@ -8,44 +8,61 @@ 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
|
||||
# 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
|
||||
# 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
|
||||
|
||||
|
||||
# This function accepts a number and returns the value millified
|
||||
# For example 1000 becomes 1K
|
||||
# 135220 becomes 135.22K
|
||||
# 25012345 becomes 25.01M etc
|
||||
# millnames can be redefined in data.py
|
||||
def millify(n):
|
||||
exponent = len(str(round(n))) - 1 # n = 1,000 return 3, n = 300,000 returns 5
|
||||
millvalue = exponent//3
|
||||
millvalue = exponent//3 # millvalue = how many sets of 3 zero's there are after the mill, 1000 -> 999999 all equals 3, 1million -> 999 million all equal 6, etc
|
||||
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])
|
||||
return f"{round((n/(10**(millvalue*3))),2)}{millname}" # Returns the formatted value
|
||||
|
||||
# Returns a random bool based on a percentage, 100 or more always returns True
|
||||
def rand_bool(percent):
|
||||
return random.randrange(100) < percent
|
||||
|
||||
def try_arrest():
|
||||
# Every day there is a chance that you will be fined based on the threat level
|
||||
# This function checks if the day has changed, if it has then it uses your threat level to
|
||||
# randomly fine you or not, eg a threat level of 100% or more (threat level MIDNIGHT) will always
|
||||
# result in an arrest and a threat level of 5% will result in a fine 1/20 of the time
|
||||
# Every time you get a fine the value increases based on the fine values in data.fines
|
||||
# If all fines have been received then each fine results in the highest fine in data.fines
|
||||
def try_fine():
|
||||
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:
|
||||
previous_date = datetime.fromtimestamp(int(save.datetime))
|
||||
# Checks if the day, month or year has changed
|
||||
if previous_date.strftime("%d") != current_day or previous_date.strftime("%m") != current_month or previous_date.strftime("%Y") != current_year:
|
||||
# Work out the current threat level
|
||||
for biz in save.businesses:
|
||||
threat += biz['cost']
|
||||
# Randomly decide to fine or not based on threat level
|
||||
if rand_bool(threat):
|
||||
# If the user has been fined more times than there are fines in data.fines, fine them the last fine in that list
|
||||
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 just fine them the amount at the current fine index
|
||||
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.fine_count += 1 # Increase the amount of times you've been fined
|
||||
save_game()
|
||||
|
||||
def add_new_money():
|
||||
@ -169,7 +186,7 @@ Additional functionality:
|
||||
|
||||
### End of loop
|
||||
add_new_money()
|
||||
try_arrest()
|
||||
try_fine()
|
||||
save_game()
|
||||
|
||||
main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user