5
\$\begingroup\$

The objective of the game is to survive as long as possible. You have a need and that is hunger. Your hunger decreases by 10 every 3 minutes and if your hunger reaches 0 you will die and the amount of time you survived will be displayed. You need to eat or drink something to increase your hunger and that cost money! you start off with $100 that should be enough for a while but soon you will run out of money so you can work and there are a total of 5 jobs you can work for, you can start off as a cashier and work your way up by gaining Skill points!

Future plans:

  • Add a loan system
  • Add housing system
  • Random events that would steal cash or hunger or both!
  • Add more items to store
  • Add a shopping cart to the store
  • Add save/load system
  • Add a pin to the bank system.

import random; import time; import threading; import sys; import psutil; from colorama import init; from termcolor import colored

while True: # Contains all variables and hunger decrease
    def show_faster(str):
        for char in str:
            time.sleep(0.1)
            sys.stdout.write(char)
            sys.stdout.flush()
    init()
    print(colored("""


              M                                          ega     ga
      mMe   imMe                                      imMega     g
     imMeg SimMe    mMegaS     aSi Meg     egaSim    SimM            mM gaS  Meg
     imMegaSimMe   imM  aSi  egaSimMe     MegaSim    SimMe     Meg  imMegaSimMega
    SimMegaS mMe  SimM gaSi  ega  mMe        aSim     imMega   Meg  imM  aSi  ega
    Sim  ga  mMe  SimMegaSi  ega  mMe    mMegaSim      mMegaS  Meg  imM  aSi  ega
    Sim  ga  mMe aSim       MegaSimMe   imMe aSim       MegaS mMeg SimM gaSi  ega
   aSim      mMegaSimM gaSi  egaSimMe  SimMe aSim  gaSimMega  mMeg Sim  gaSi  egaS
   aSim      mMeg SimMegaSi      imMe  SimMegaSim  gaSimMega imMegaSim  gaSi  egaS
  gaSim      mMeg  imMegaS  Me  SimMe   imMegaSim  gaSimMe   imMegaSim  gaSi  egaS
                           mMegaSimM
                           mMegaSim

                                              """, 'red'))
    t0 = time.time()
    print("="*15)
    while True:
        try:
            user = input('Enter a name:')
            if len(user) < 3:
                print("Your name must be at least 3 char long")
            else:
                break
        except ValueError:
            print("Sorry, I didn't understand that. Please try again")
    print("="*15)
    time.sleep(1)
    show_faster("...Loading....\n")
    time.sleep(1)
    show_faster("...Initializing.....\n")
    time.sleep(1)
    show_faster("...Done..\n")
    print("="*15)
    print(colored("Please check out the more info section to know what to do!", "green"))
    print("="*15)
    cash = 100
    Bank_balance = 0
    hunger = 100
    inventory = []
    Skill = 0
    count = 0
    job_position = []
    shutdown = psutil.Process()
    def hungerdecrease():
        global hunger
        if hunger > 0:
            # no rearm when dead
            threading.Timer(0.001,hungerdecrease).start()  # rearm timer
            lock.acquire()
            hunger -= 0.001
            lock.release()
        elif hunger <= 0:
            t1 = time.time()
            total = t1 - t0
            total2 = round(total / 60)
            print(f"\nYou died of hunger. :( should have eaten!. You stood alive for {total2} minutes.")
            shutdown.terminate()
    lock = threading.Lock()
    threading.Timer(0.001,hungerdecrease).start()
    def count_work(num):
        global Bank_balance
        bonus = random.randint(500,3000)
        if count >= num:
            print(colored(f"You got a bonus of ${bonus}.", 'green'))
            print("="*15)
            Bank_balance += bonus
    break

def mainmenu():
    print("Welcome To the game!")
    print("="*15)
    time.sleep(1)
    main = input("Where would you like to go?\nA)The Bank\nB)Store\nC)Work\nD)Inventory\nE)More information\nF)Exit\n>>>").lower().strip()
    if main == "a":
        Bank_Of_Omni()
    elif main == "b":
        store()
    elif main == "c":
        print("="*15)
        work()
    elif main == "d":
        Your_Stuff()
    elif main == "e":
        moreinfo()
    elif main == "f":
        print("Good Bye!")
        quit()
    else:
        print("="*15)
        print("Invalid input. Try again!")
        print("="*15)
        mainmenu()

def Bank_Of_Omni():
        print("="*15)
        print(f"Welcome to Omnibank {user}.")
        print("="*15)
        time.sleep(.01)
        option = input("What will you like to do?\nA)Deposit\nB)Withdraw\nC)Check Balance\nD)Mainmenu\n>>>").lower().strip()
        print("="*15)
        if option == "a":
            Deposit()
        elif option == "b":
            Withdraw()
        elif option == "c":
            Checkbalance()
        elif option == "d":
            mainmenu()
        else:
            print("Invlid input")
            Bank_Of_Omni()

def Deposit():

            global cash
            global Bank_balance

            depositing = input("Do you want to make a deposit?(y/n)\n>>>").lower().strip()
            if cash <= 0:
                print("="*15)
                print(colored(f"You don't have enough in cash to depsoit! You have ${cash} in cash.", 'red'))
                Bank_Of_Omni()
            if depositing == "y":
                try:
                    print("="*15)
                    Deposit1 = float(input(f"You have ${cash} cash! How much do you want to deposit?\n>>>")) # make an option
                    print("="*15)
                    if Deposit1 <= cash:
                        if Deposit1 > 0:
                            Bank_balance = Bank_balance + Deposit1
                            cash = cash - Deposit1
                            print(colored(f"{user}, your bank balance is now: ${Bank_balance}, and your cash is now: ${cash}", 'green'))

                            Bank_Of_Omni()
                        elif Deposit1 < 0:
                            print(colored("Insufficient Funds", 'red'))
                            Bank_Of_Omni()
                        else:
                            print(colored("Insufficient Funds", 'red'))
                            Bank_Of_Omni()
                    elif Deposit1 > cash:
                        print(colored("Insufficient Funds", 'red'))
                        Bank_Of_Omni()
                except ValueError:
                    print(colored("Invalid input. Try again!", 'red'))
                    print("="*15)
                    Deposit()
            elif depositing == "n":
                print("="*15)
                print(colored("Invalid input. Try again!", 'red'))
                Bank_Of_Omni()
            else:
                print("="*15)
                print(colored("Invalid input. Try again!", 'red'))
                Bank_Of_Omni()

def Withdraw():

    global cash
    global Bank_balance
    withdrawing = input("Do you want to make a withdraw?(y/n)\n>>>").lower().strip()
    print("="*15)
    if Bank_balance <= 0:
            print(colored(f"You don't have enough in the bank to withdraw! Your bank balance is ${Bank_balance}", 'red'))
            Bank_Of_Omni()
    if withdrawing == "y":
        try:
            withdraw1 = float(input(f"You have ${Bank_balance} in your bank account and ${cash} in cash! How much do you want to withdraw?\n>>>")) # make an option
            print("="*15)
            if withdraw1 <= Bank_balance:
                if withdraw1 > 0:
                    Bank_balance = Bank_balance - withdraw1
                    cash = cash + withdraw1
                    print(colored(f"{user}, your bank balance is now: ${Bank_balance}, and your cash is now: ${cash}", 'green'))
                    Bank_Of_Omni()
                elif withdraw1 < 0:
                    print(colored("Insufficient Funds", 'red'))
                    Bank_Of_Omni()
                else:
                    print(colored("Insufficient Funds", 'red'))
                    Bank_Of_Omni()
            elif withdraw1 > Bank_balance:
                print(colored("Insufficient Funds", 'red'))
                Bank_Of_Omni()
        except ValueError:
            print("="*15)
            print(colored("Invalid input. Try again!", 'red'))
            print("="*15)
            Withdraw()
    elif withdrawing == "n":
        print("="*15)
        print(colored("Invalid input. Try again!", 'red'))
        Bank_Of_Omni()
    else:
        print(colored("Invalid input. Try again!", 'red'))
        Bank_Of_Omni()

def Checkbalance():
        print(colored(f"Your Bank balance is: ${Bank_balance}. You have ${cash} in cash.", 'green'))
        Bank_Of_Omni()

def store():

    global inventory
    global cash
    global Bank_balance
    print("Welcome to David's Grocery")
    print("="*15)
    # ask = ('buy', 'quit')
    items = [('eggs', 3.16), ('mealdeal', 8), ('chicken', 4.38), ('milk', 2.60), ('tomatoes', 4), ('cheese', 3), ('apples', 2), ('potatoes', 4), ('beer', 3.37), ('wine', 15), ('coca-cola', 1.92)]

    print("This is our menu! Take a look around!")
    print(f"""

            Wine ..... $15.00 ...(+8 hunger)
            Chicken.... $4.38 ...(+9 hunger)
            Coca-Cola ...... $1.92 ...(+4 hunger)
            Milk ..... $2.60 ...(+2 hunger)
            Beer ..... $3.37 ...(+5 hunger)
            Tomatoes ....... $4 ...(+1 hunger)
            MealDeal .... $8.00 ...(+10 hunger)
            Cheese ..... $3.00 ...(+4 hunger)
            Potatoes ...... $4 ...(+3 hunger)
            Apples ....... $2 ...(+2 hunger)
            Eggs ..... $3.16 ... (+3 hunger)
                """)
    buying = input("Do you want to buy something?(y/n)\n>>>").lower().strip()
    if buying == "y":
        item = input("What item do you want to buy?\n>>>").lower().strip() # make an option
        print("="*15)
        if item == "":
            print("="*15)
            print(colored("Invlid input. Try agian!", 'red'))
            print("="*15)
            store()
        for i in items:
            if item == i[0]:
                print(item, '(are) is $', i[1])
                buy = input("\nAre you sure you want to buy this item?(y/n)\n>>").lower()
                print("="*15)
                if buy == "y":
                    if cash > i[1]:
                        cash = cash - i[1]
                        print("You bought (a) " + item + f" you have ${cash} left over")
                        print("="*15)
                        inventory.append(item)
                        store()
                    else:
                        print("="*15)
                        print(colored("Insufficient Funds", 'red'))
                        print("="*15)
                        mainmenu()

                elif buy == 'n':
                    print("="*15)
                    print("Too bad you don't want (a) " + item)
                    print("="*15)
                    mainmenu()
                else:
                    print("="*15)
                    print(colored("Invlid input. Try agian!", 'red'))
                    print("="*15)
                    mainmenu()


                if i[1] > cash:
                    print('You do not have enough money for this item.\n')
                    print("Going back to menu!")
                    print("="*15)
                    mainmenu()
        else:
            if item != i[0]:
                print("="*15)
                print(colored("Invlid input. Try agian!", 'red'))
                print("="*15)
                store()
    elif buying == "n":
        print("="*15)
        mainmenu()
    else:
        print("="*15)
        print(colored("Invlid input. Try agian!", 'red'))
        print("="*15)
        store()

def work():

    print("Welcome to the Job Assocaition!")
    print("="*15)
    intro_job = input("Select an option!\n\nA)Job Selection\nB)Position\nC)Go to work!\nD)Mainmenu\n>>>").lower().strip()
    print("="*15)
    if intro_job == "a":
        job_selection()
    elif intro_job == "b":
        position()
    elif intro_job == "c":
        go_to_work()
    elif intro_job == "d":
        mainmenu()
    else:
        print(colored("Invalid input. Try again!", 'red'))
        print("="*15)
        work()

def job_selection():
    global Skill
    global job_position

    job = input("Select a job\n\nA)Cashier\nB)Waitress\nC)Teacher\nD)Administrative assistant\nE)HR Manager\nF)Go back\n>>>").lower().strip()
    print("="*15)
    if job == "a":
        print(colored("Cashiers are paid $12 an hr and require no skill. Hunger is decreased by 10 per day! You will work 8hrs a day!", 'green'))
        print("="*15)
        want_job = input("Do you want the job?(y/n)\n>>>").lower().strip()
        print("="*15)
        if want_job == "y":
            if job_position > []:
                if "Cashier" == job_position:
                    print(colored("You already work in this position!", 'red'))
                    print("="*15)
                    job_selection()
                else:
                    change = input("Are you sure you want to change position?(y/n)\n>>>").lower().strip()
                    print("="*15)
                    if change == "y":
                        del job_position[:]
                        if want_job == "y":
                            print(colored("You got the job! You will be paid per day you work! Your skill will increase by 0.5 per day of work!(Go to work to start working!)", 'green'))
                            print('='*15)
                            job_position.append('Cashier')
                            work()

                        elif want_job == "n":
                            job_selection()
                        else:
                            print(colored("Invlid input. Try agian!", 'red'))
                            print('='*15)
                            job_selection()
                    elif change == "n":
                        print("Going back!")
                        print("="*15)
                        job_selection()
                    else:
                        print(colored("Invlid input. Try agian!", 'red'))
                        print("="*15)
                        job_selection()
            elif job_position <= []:
                if want_job == "y":
                    print(colored("You got the job! You will be paid per day you work! Your skill will increase by 0.5 per day of work!(Go to work to start working!)", 'green'))
                    print('='*15)
                    job_position.append('Cashier')
                    work()

                elif want_job == "n":
                    job_selection()
                else:
                    print(colored("Invlid input. Try agian!", 'red'))
                    print('='*15)
                    job_selection()
        elif want_job == "n":
            print(colored("Going Back", 'green'))
            print("="*15)
            job_selection()
        else:
            print(colored("Invlid input. Try agian!", 'red'))
            print('='*15)
            job_selection()
    elif job == "b":
        print(colored("Waitress are paid $9 an hr plus tips! and require 10 skill. Hunger is decreased by 10 per day! You will work 8hrs a day!", 'green'))
        print("="*15)
        want_job = input("Do you want the job?(y/n)\n>>>").lower().strip()
        print("="*15)
        if want_job == "y":
            if job_position > []:
                if "Waitress" == job_position:
                    print(colored("You already work in this position!", 'red'))
                    print("="*15)
                    job_selection()
                if Skill >= 10:
                    change = input("Are you sure you want to change position?(y/n)\n>>>").lower().strip()
                    print("="*15)
                    if change == "y":
                        del job_position[:]
                        if want_job == "y":
                            print(colored("You got the job! You will be paid per day you work! Your skill will increase by 1.5 per day of work!(Go to work to start working!)", 'green'))
                            print('='*15)
                            job_position.append('Waitress')
                            work()

                        elif want_job == "n":
                            job_selection()
                        else:
                            print(colored("Invlid input. Try agian!", 'red'))
                            print('='*15)
                            job_selection()
                    elif change == "n":
                        print("Going back!")
                        print("="*15)
                        job_selection()
                    else:
                        print(colored("Invlid input. Try agian!", 'red'))
                        print("="*15)
                        job_selection()
                elif Skill < 10:
                    print(colored("You don't have enough Skills to get the job! You need 10 Skills!", 'red'))
                    print("="*15)
                    job_selection()
            elif job_position <= []:
                if Skill >= 10:
                    if want_job == "y":
                        print(colored("You got the job! You will be paid per day you work! Your skill will increase by 1.5 per day of work!(Go to work to start working!)", 'green'))
                        print('='*15)
                        job_position.append('Waitress')
                        work()

                    elif want_job == "n":
                        job_selection()
                    else:
                        print(colored("Invlid input. Try agian!", 'red'))
                        print('='*15)
                        job_selection()
                elif Skill < 10:
                    print(colored("You don't have enough Skills to get the job! You need 10 Skills!", 'red'))
                    print("="*15)
                    job_selection()
        elif want_job == "n":
            print(colored("Going Back", 'green'))
            print("="*15)
            job_selection()
        else:
            print(colored("Invlid input. Try agian!", 'red'))
            print('='*15)
            job_selection()
    elif job == "c":
        print(colored("Teachers are paid $15 an hr plus bonuses! and require 50 skill. Hunger is decreased by 10 per day! You will work 8hrs a day!", 'green'))
        print("="*15)
        want_job = input("Do you want the job?(y/n)\n>>>").lower().strip()
        print("="*15)
        if want_job == "y":
            if job_position > []:
                if "Teacher" == job_position:
                    print(colored("You already work in this position!", 'red'))
                    print("="*15)
                    job_selection()
                if Skill >= 50:
                    change = input("Are you sure you want to change position?(y/n)\n>>>").lower().strip()
                    print("="*15)
                    if change == "y":
                        del job_position[:]
                        if want_job == "y":
                            print(colored("You got the job! You will be paid per day you work! Your skill will increase by 5 per day of work!(Go to work to start working!)", 'green'))
                            print('='*15)
                            job_position.append('Teacher')
                            work()

                        elif want_job == "n":
                            job_selection()
                        else:
                            print(colored("Invlid input. Try agian!", 'red'))
                            print('='*15)
                            job_selection()
                    elif change == "n":
                        print("Going back!")
                        print("="*15)
                        job_selection()
                    else:
                        print(colored("Invlid input. Try agian!", 'red'))
                        print("="*15)
                        job_selection()
                elif Skill < 10:
                    print(colored("You don't have enough Skills to get the job! You need 50 Skills!", 'red'))
                    print("="*15)
                    job_selection()
            elif job_position <= []:
                if Skill >= 50:
                    if want_job == "y":
                        print(colored("You got the job! You will be paid per day you work! Your skill will increase by 5 per day of work!(Go to work to start working!)", 'green'))
                        print('='*15)
                        job_position.append('Teacher')
                        work()

                    elif want_job == "n":
                        job_selection()
                    else:
                        print(colored("Invlid input. Try agian!", 'red'))
                        print('='*15)
                        job_selection()
                elif Skill < 50:
                    print(colored("You don't have enough Skills to get the job! You need 50 Skills!", 'red'))
                    print("="*15)
                    job_selection()
        elif want_job == "n":
            print(colored("Going Back", 'green'))
            print("="*15)
            job_selection()
        else:
            print(colored("Invlid input. Try agian!", 'red'))
            print('='*15)
            job_selection()
    elif job == "d":
        print(colored("Administrative assistant are paid $22 an hr plus bonuses! and require 250 skill. Hunger is decreased by 12 per day! You will work 8hrs a day!", 'green'))
        print("="*15)
        want_job = input("Do you want the job?(y/n)\n>>>").lower().strip()
        print("="*15)
        if want_job == "y":
            if job_position > []:
                if "Administrative assistant" == job_position:
                    print(colored("You already work in this position!", 'red'))
                    print("="*15)
                    job_selection()
                if Skill >= 250:
                    change = input("Are you sure you want to change position?(y/n)\n>>>").lower().strip()
                    print("="*15)
                    if change == "y":
                        del job_position[:]
                        if want_job == "y":
                            print(colored("You got the job! You will be paid per day you work! Your skill will increase by 10 per day of work!(Go to work to start working!)", 'green'))
                            print('='*15)
                            job_position.append('Administrative assistant')
                            work()

                        elif want_job == "n":
                            job_selection()
                        else:
                            print(colored("Invlid input. Try agian!", 'red'))
                            print('='*15)
                            job_selection()
                    elif change == "n":
                        print("Going back!")
                        print("="*15)
                        job_selection()
                    else:
                        print(colored("Invlid input. Try agian!", 'red'))
                        print("="*15)
                        job_selection()
                elif Skill < 250:
                    print(colored("You don't have enough Skills to get the job! You need 250 Skills!", 'red'))
                    print("="*15)
                    job_selection()
            elif job_position <= []:
                if Skill >= 250:
                    if want_job == "y":
                        print(colored("You got the job! You will be paid per day you work! Your skill will increase by 10 per day of work!(Go to work to start working!)", 'green'))
                        print('='*15)
                        job_position.append('Administrative assistant')
                        work()

                    elif want_job == "n":
                        job_selection()
                    else:
                        print(colored("Invlid input. Try agian!", 'red'))
                        print('='*15)
                        job_selection()
                elif Skill < 250:
                    print(colored("You don't have enough Skills to get the job! You need 250 Skills!", 'red'))
                    print("="*15)
                    job_selection()
        elif want_job == "n":
            print(colored("Going Back", 'green'))
            print("="*15)
            job_selection()
        else:
            print(colored("Invlid input. Try agian!", 'red'))
            print('='*15)
            job_selection()
    elif job == "e":
        print(colored("HR Manager's are paid $35 an hr plus bonuses! and require 1500 skill. Hunger is decreased by 15 per day! You will work 6hrs a day!", 'green'))
        print("="*15)
        want_job = input("Do you want the job?(y/n)\n>>>").lower().strip()
        print("="*15)
        if want_job == "y":
            if job_position > []:
                if "HR Manager" == job_position:
                    print(colored("You already work in this position!", 'red'))
                    print("="*15)
                    job_selection()
                if Skill >= 1500:
                    change = input("Are you sure you want to change position?(y/n)\n>>>").lower().strip()
                    print("="*15)
                    if change == "y":
                        del job_position[:]
                        if want_job == "y":
                            print(colored("You got the job! You will be paid per day you work! Your skill will increase by 20 per day of work!(Go to work to start working!)", 'green'))
                            print('='*15)
                            job_position.append('HR Manager')
                            work()

                        elif want_job == "n":
                            job_selection()
                        else:
                            print(colored("Invlid input. Try agian!", 'red'))
                            print('='*15)
                            job_selection()
                    elif change == "n":
                        print("Going back!")
                        print("="*15)
                        job_selection()
                    else:
                        print(colored("Invlid input. Try agian!", 'red'))
                        print("="*15)
                        job_selection()
                elif Skill < 250:
                    print(colored("You don't have enough Skills to get the job! You need 1,500 Skills!", 'red'))
                    print("="*15)
                    job_selection()
            elif job_position <= []:
                if Skill >= 1500:
                    if want_job == "y":
                        print(colored("You got the job! You will be paid per day you work! Your skill will increase by 20 per day of work!(Go to work to start working!)", 'green'))
                        print('='*15)
                        job_position.append('HR Manager')
                        work()

                    elif want_job == "n":
                        job_selection()
                    else:
                        print(colored("Invlid input. Try agian!", 'red'))
                        print('='*15)
                        job_selection()
                elif Skill < 1500:
                    print(colored("You don't have enough Skills to get the job! You need 1,500 Skills!", 'red'))
                    print("="*15)
                    job_selection()
        elif want_job == "n":
            print(colored("Going Back", 'green'))
            print("="*15)
            job_selection()
        else:
            print(colored("Invlid input. Try agian!", 'red'))
            print('='*15)
            job_selection()
    elif job == "f":
        work()
    else:
        print(colored("Invalid input. Try again!", 'red'))
        print("="*15)
        job_selection()

def position():
    global job_position
    print(colored(f"Your job position is {job_position}.", 'green'))
    print('='*15)
    job_selection()

def go_to_work():
    global Skill, job_position, Bank_balance, hunger, count
    print("Welcome to your work station!")
    print("="*15)
    if job_position == []:
        print(colored("You need to have a job to work!(Go to job selection)", "red"))
        print("="*15)
        work()
    sure1 = input("Do you want to work today?(y/n)\n>>>").lower().strip()
    print("="*15)
    if sure1 == "y":
        if "Cashier" in job_position:
            print(colored("You worked hard today! $89 Has Been deposited to your bank account! -10 hunger, +0.5 skills!","green"))
            print("="*15)
            tax = round(96 * 0.0699)
            Bank_balance += 96 - tax
            hunger -= 10
            Skill += 0.5
            work()
    if "Waitress" in job_position:

        Tip = random.randint(0, 100)
        if sure1 == "y":
            print(colored(f"You worked hard today! $67 Has Been deposited to your bank account. Your Tip for today is: ${Tip}.  -10 hunger, +1.5 skills!", "green"))
            print("="*15)
            tax = round(72 * 0.0699)
            Bank_balance += 72 + Tip - tax
            hunger -= 10
            Skill += 1.5
            work()
        elif sure1 == "n":
            work()
        else:
            print(colored("Invlid input. Try agian!", 'red'))
            go_to_work()

    elif "Teacher" in job_position:

        if sure1 == "y":
            print(colored(f"You worked hard today! $120 Has Been deposited to your bank account. -10 hunger, +5 skill!", "green"))
            print("="*15)
            tax = round(120 * 0.0699)
            Bank_balance += 120 - tax
            hunger -= 10
            Skill += 5
            count += 1
            count_work(12)
            count_work(24)
            count_work(36)
            count_work(48)
            count_work(60)
            count_work(72)
            work()
        elif sure1 == "n":
            work()
        else:
            print(colored("Invlid input. Try agian!", 'red'))
            go_to_work()
    elif "Administrative assistant" in job_position:
        if sure1 == "y":
            print(colored(f"You worked hard today! $176 Has Been deposited to your bank account. -12 hunger, +10 skill!", "green"))
            print("="*15)
            tax = round(176 * 0.0699)
            Bank_balance += 176 - tax
            hunger -= 12
            Skill += 10
            count += 1
            count_work(12)
            count_work(24)
            count_work(36)
            count_work(48)
            count_work(60)
            count_work(72)
            work()
        elif sure1 == "n":
            work()
        else:
            print(colored("Invlid input. Try agian!", 'red'))
            go_to_work()
    elif "HR Manager" in job_position:
        if sure1 == "y":
            print(colored(f"You worked hard today! $210 Has Been deposited to your bank account. -15 hunger, +20 skill!", "green"))
            print("="*15)
            tax = round(210 * 0.0699)
            Bank_balance += 210 - tax
            hunger -= 15
            Skill += 20
            count += 1
            count_work(12)
            count_work(24)
            count_work(36)
            count_work(48)
            count_work(60)
            count_work(72)
            work()
        elif sure1 == "n":
            work()
        else:
            print(colored("Invlid input. Try agian!", 'red'))
            go_to_work()
    elif sure1 == "n":
        work()
    else:
        print(colored("Invlid input. Try agian!", 'red'))
        work()

def moreinfo():

    print("="*15)
    print(colored(f"Hey {user}, Your objective is to survive as long as possible. You start off with $100 cash and 100 hunger, Go to inventory to see your hunger level and inventory and more!", 'green'))
    print("="*15)
    print(colored("Your hunger will decrease every 3 minutes by 10 hunger. So make sure to eat!", 'green'))
    print("="*15)
    print(colored("You can't eat something that will increase your hunger past 100.", 'green'))
    print("="*15)
    print(colored("You can work to have an income and survive. You can start of as a Cashier and gradually get better paying jobs but each job require a certain amount of skill to get the job! when you recieve your check it will automatically be taxed!", 'green'))
    print("="*15)
    print(colored("Tax rate is 6.99%!", 'green'))
    print("="*15)
    print(colored("More stuff to come soon!", 'red'))
    print("="*15)
    mainmenu()

def Your_Stuff():

    global hunger
    global player
    global inventory
    items = [('eggs', 3), ('mealdeal', 10), ('chicken', 9), ('milk', 2), ('tomatoes', 1), ('cheese', 4), ('apples', 2), ('potatoes', 3), ('beer', 5), ('wine', 8), ('coca-cola', 4)]
    ask = input("Choose an option:\n\nA)Show hunger level\nB)Inventory\nC)Quick check\nD)Mainmenu\n>>>").lower().strip()
    print("="*15)
    if ask == "a":
        print(f"Your hunger level is at " + str(hunger))
        print("="*15)
        if hunger < 50:
            print("You should eat something.")
            print("="*15)
            Your_Stuff()
        elif hunger > 80:
            print("You hunger is good!!")
            print("="*15)
            Your_Stuff()
        else:
            print("You are just ok!")
            print("="*15)
            Your_Stuff()
    elif ask == "b":
        print(f"You have {inventory} in your inventory!")
        print("="*15)
        if inventory > []:
            if hunger < 100:
                eat = input("Do you want to eat something?(y/n)\n>>>").lower().strip()
                print("="*15)
                if eat == "y":
                    nibble = input("What do you want to eat?(Must be in inventory)\n>>>").lower().strip()
                    print("="*15)
                    if nibble in inventory:
                        for i in items:
                            if nibble == i[0]:
                                print(nibble, 'is going to increase hunger by ' + str(i[1]) + ".")
                                print("="*15)
                                sure = input(f"Are you sure you want to eat the {nibble}?(y/n)").lower().strip()
                                print("="*15)
                                if sure == "y":
                                    print(f"You ate the {nibble} you gained " + str(i[1]) + " hunger.")
                                    print("="*15)
                                    hunger = hunger + i[1]
                                    inventory.remove(nibble)
                                    Your_Stuff()
                                    hunger2 = hunger + i[1]
                                    if hunger2 > 100:
                                        print("You can't eat this because it will increase you hunger beyond 100 hunger! Try and eat something else!")
                                        print("="*15)
                                        Your_Stuff()
                                elif sure == "n":
                                    Your_Stuff()
                    else:
                        print("You don't have this item in your inventory.")
                        print("="*15)
                        Your_Stuff()

                elif eat == "n":
                    Your_Stuff()
                else:
                    print("Invlid input. Try again!")
                    Your_Stuff()
            elif hunger >= 100:
                print("you are full")
                print("="*15)
                Your_Stuff()
            else:
                Your_Stuff()
        else:
            Your_Stuff()
    elif ask == "c":
        print(colored(f"Your hunger is at {hunger}, Your job_position is {job_position}, Your inventory has {inventory}, Your bank Balance is ${Bank_balance}, Your skill is at {Skill}.", 'magenta'))
        print("="*15)
        mainmenu()
    elif ask == "d":
        print("Going to menu!")
        print("="*15)
        mainmenu()
    else:
        print("Invlaid input. Try again!")
        print("="*15)
        Your_Stuff()
mainmenu()
\$\endgroup\$
  • \$\begingroup\$ Welcome to Code Review! To raise the intereset in actually looking at your code, you should give a short description on what the game is about and what aspects make it stand out from all the other "I did this game to learn Python" posts. Following our site goals, you should then also update your title to make the question more interesting. \$\endgroup\$ – AlexV Jul 19 at 21:56
  • \$\begingroup\$ @AlexV Thanks for that! I added what the game does and what I have planned for the future of the game! But I don't know what to name the title. \$\endgroup\$ – Joshua Torres Jul 19 at 22:41
5
\$\begingroup\$

Wow! What a project!

I had tons of fun working on this! There are a lot of things to like about your code. Instead of going over the general improvements I made, I'm going to explain each part that I changed and why I changed it.

Note: I did not touch the threading * and other hunger behavior because I am not confident enough with my ability to improve that. Another answer can possible touch on that.*

Here we go!

Import Statements

import random; import time; import threading; import sys; import psutil; from colorama import init; from termcolor import colored

According to PEP-8, this is unconventional. All imports should be on their own line, and ordered alphabetically, with the from .. import .. statements being ordered after.

import psutil
import random
import sys
import time
import threading
from colorama import init
from termcolor import colored

Job Selection

Your method to choose a job was a whole 332 lines long! That's a lot of code to just select what your profession is. Using a simple dict, we can use the names of the jobs as values, and have each abcde option as the key. Using this method, I was about to shrink the method down to 23 lines, 309 lines shorter!

Global Variables

Q: Should you use global variables in your program?

A: 90% of the time, NO.

It's anyones guess what the right answer is. Using global variables has a plethora of nasty things that can affect your program. This document can explain the negative effects of using global variables better than I ever will be.

Method Docstrings

You should include docstrings on the first line of every method you write. This will help documentation identify what your method is supposed to do.

Variable/Method Naming

You should use snake_case and not camelCase or nonexistentcase when naming variables in python.

Main Guard

When running code outside a method/class, it's always good to use a main guard. This is a StackOverflow question that helps explain the benefit/use of the guard. An excerpt from the accepted answer:

Having a main guard clause in a module allows you to both run code in the module directly and also use procedures and classes in the module from other modules. Without the main guard clause, the code to start your script would get run when the module is imported.

Objects

In your code, you have variables like so:

cash = 100
Bank_balance = 0
hunger = 100
inventory = []
Skill = 0
count = 0
job_position = []

This code is just screaming to be organized into an object. Having classes, especially in this context of a simulator, can really help the flow of the program, and help you remember what belongs to what. I put the above code into a player class:

class Player:
    """ Player Class """

    def __init__(self, name):
        self.name = name
        self.bank_account = BankAccount(self)
        self.cash = 100
        self.hunger = 100
        self.job = None
        self.skill = 0
        self.inventory = []
        self.pin = 0

        #Used to calculate bonuses for Teacher, AA, and HR
        self.fulltime_days_worked = 0

Now, you have all that code neatly organized into one place.

I also want to touch up on the job selection a bit more. You have tons of if statements and nested if statements explaining and collecting input about if the player wanted to choose that job. You can store all the information about the job into an object as well. Using this method, I was able to neatly organize a list of jobs that would be available for the player to select:

class Job:
    """ Job Class """

    def __init__(
            self,
            title,
            pay,
            skill_required,
            working_hours,
            hunger_decrease,
            skill_increase):

        self.title = title
        self.pay = pay
        self.skill_required = skill_required
        self.working_hours = working_hours
        self.hunger_decrease = hunger_decrease
        self.skill_increase = skill_increase

    def __str__(self):
        return f"""
            Title: {self.title}
            Pay: ${self.pay}
            Skill Required: {self.skill_required}
            Hours Per Day Working: {self.working_hours}
            Hunger Decrease Per Day: {self.hunger_decrease}
            Skill Increase Per Day: {self.skill_increase}
        """

Finally, the banking portion of the program can also be organized into an object, storing it's own account_balance, and PIN number (I saw your future plans to implement a PIN and decided to go for it!).

Shop

I could have put this into its own Shop class, and almost did, but I relented. Since the user is really only interacting with the shop through one means, I decided that a method would be good enough. Instead of using tuples, I changed it to a dict again, so I could easily lookup the price of the item with its corresponding name.

Main Menu

Awesome ASCII title! I stored the methods in a dict as well, so instead of having multiple if/elif spam, I could simply match the input with the key in the dict, and call that method.

count_work => determine_bonus

I changed the method name to be more resemblant of what the method is actually doing. Since

count_work(12)
count_work(24)
count_work(36)
count_work(48)
count_work(60)
count_work(72)

is just checking every 12 days, you can use the moludo operator to check if it's divisible by 12, like so:

# Changed `count` to `fulltime_days_worked` because its more descriptive and
# that's essentially what `count` was counting
if (player.fulltime_days_worked % 12) == 0:

Below is the refactored code for you. Thank you for posting this, I really had a blast reviewing and rewriting it!

Note: If anything doesn't work the way it is supposed to, mention me in a comment and I'll fix it (obviously not the hunger/threading. Because I didn't touch it, it is not included in the final reviewed code. I'll leave it up to you to implement it.). I went through tons of tests through each and every method, and everything was fine, but something could always fall through the cracks

Refactored Code

""" Import Statements"""
import random
import time
import threading
import sys
import psutil
from colorama import init
from termcolor import colored

def main_menu():
    """ Main Menu of the game """
    options = {
        "a": player.bank_account.interface,
        "b": store,
        "c": work,
        "d": your_stuff,
        "e": more_info,
        "f": quit
    }
    print("Welcome To the game!")
    print("="*15)
    time.sleep(1)
    main = input("Where would you like to go?\nA) The Bank\nB) Store\nC) Work\nD) Inventory\nE) More information\nF) Exit\n>>>").lower().strip()

    if main in list(options.keys()):
        options[main]()
    else:
        print("="*15)
        print("Invalid input. Try again!")
        print("="*15)
        main_menu()

class Job:
    """ Job Class """

    def __init__(
            self,
            title,
            pay,
            skill_required,
            working_hours,
            hunger_decrease,
            skill_increase):

        self.title = title
        self.pay = pay
        self.skill_required = skill_required
        self.working_hours = working_hours
        self.hunger_decrease = hunger_decrease
        self.skill_increase = skill_increase

    def __str__(self):
        return f"""
            Title: {self.title}
            Pay: ${self.pay}
            Skill Required: {self.skill_required}
            Hours Per Day Working: {self.working_hours}
            Hunger Decrease Per Day: {self.hunger_decrease}
            Skill Increase Per Day: {self.skill_increase}
        """

class Player:
    """ Player Class """

    def __init__(self, name):
        self.name = name
        self.bank_account = BankAccount(self)
        self.cash = 100
        self.hunger = 100
        self.job = None
        self.skill = 0
        self.inventory = []
        self.pin = 0

        #Used to calculate bonuses for Teacher, AA, and HR
        self.fulltime_days_worked = 0

class BankAccount:
    """ Bank Class """

    def __init__(self, user):
        self.user = user
        self.options = {
            "a": self.deposit,
            "b": self.withdraw,
            "c": self.check_balance,
            "d": main_menu
        }
        self.account_balance = 0.00

    def interface(self):
        """ Main interface for the bank """
        print("="*15)
        print(f"Welcome to Omnibank {self.user.name}.")
        print("="*15)
        time.sleep(.01)

        #Check if user has set a pin
        if player.pin != 0:

            login = input("Enter your PIN: ")

            if login == player.pin:

                while True:
                    option = input("What will you like to do?\nA) Deposit\nB) Withdraw\nC) Check Balance\nD) Mainmenu\n>>>").lower().strip()
                    print("="*15)
                    if option in list(self.options.keys()):
                        self.options[option]()

            print(colored("Invalid PIN!", "red"))
            self.interface()

        #Prompt user to set a pin
        pin = input("Enter a four digit pin for future logins: ")
        if len(pin) != 4:
            print(colored("That was an invalid pin length! Enter again!", "red"))
            self.interface()
        player.pin = pin
        print(colored("Your personal pin has been set up!", "green"))
        self.interface()

    def deposit(self):
        """ Bank Deposit Method """
        print(f"Your current cash is ${player.cash}")
        amount = input("How much would you like to deposit?")
        if float(amount) > self.user.cash:
            print(colored("You don't have that much money to deposit!", "red"))
            self.interface()
        self.account_balance += float(amount)
        self.user.cash -= float(amount)
        print(colored(f"Your account balance is now ${self.account_balance}!", "green"))
        print(colored(f"Your current cash is now ${self.user.cash}!", "green"))
        self.interface()

    def withdraw(self):
        """ Bank Withdraw Method """
        print(f"Your current account balance is ${player.bank_account.account_balance}")
        amount = input("How much would you like to withdraw?")
        if float(amount) > self.account_balance:
            print(colored("You don't have that much money to withdraw!", "red"))
            self.interface()
        self.account_balance -= float(amount)
        self.user.cash += float(amount)
        print(colored(f"Your bank balance is now ${self.account_balance}!", "green"))
        print(colored(f"Your current cash is now ${self.user.cash}!", "green"))
        self.interface()

    def check_balance(self):
        """ Bank Check Balance Method """
        print(colored(f"Your current balance is ${self.account_balance}", "green"))

def store():
    """ Method for purchasing items at the store """

    print("Welcome to David's Grocery")
    print("="*15)

    items = {
        'eggs': 3.16,
        'mealdeal': 8,
        'chicken': 4.38,
        'milk': 2.60,
        'tomatoes': 4,
        'cheese': 3,
        'apples': 2,
        'potatoes': 4,
        'beer': 3.37,
        'wine': 15,
        'coca-cola': 1.9
    }

    print("This is our menu! Take a look around!")
    print(f"""

            Wine ..... $15.00 ...(+8 hunger)
            Chicken.... $4.38 ...(+9 hunger)
            Coca-Cola ...... $1.92 ...(+4 hunger)
            Milk ..... $2.60 ...(+2 hunger)
            Beer ..... $3.37 ...(+5 hunger)
            Tomatoes ....... $4 ...(+1 hunger)
            MealDeal .... $8.00 ...(+10 hunger)
            Cheese ..... $3.00 ...(+4 hunger)
            Potatoes ...... $4 ...(+3 hunger)
            Apples ....... $2 ...(+2 hunger)
            Eggs ..... $3.16 ... (+3 hunger)

    """)

    buy = input("Would you like to buy something? (Y/N)")

    if buy.lower() == "y":
        item = input("Enter item to buy: ").lower()
        if item in list(items.keys()):
            cost = items[item]
            if player.cash < cost:
                print(colored(f"Not enough money to buy {item}!", "red"))
                store()
            print(colored(f"{item} bought for ${cost}", "green"))
            player.cash -= cost
            player.inventory.append(item)
            store()
        print(colored("Invalid option, choose again!", "red"))
        store()
    main_menu()

def more_info():
    """Displays more information about the game """

    print("="*15)
    print(colored(f"Hey {player.name}, Your objective is to survive as long as possible. You start off with $100 cash and 100 hunger, Go to inventory to see your hunger level and inventory and more!", 'green'))
    print("="*15)
    print(colored("Your hunger will decrease every 3 minutes by 10 hunger. So make sure to eat!", 'green'))
    print("="*15)
    print(colored("You can't eat something that will increase your hunger past 100.", 'green'))
    print("="*15)
    print(colored("You can work to have an income and survive. You can start of as a Cashier and gradually get better paying jobs but each job require a certain amount of skill to get the job! when you recieve your check it will automatically be taxed!", 'green'))
    print("="*15)
    print(colored("Tax rate is 6.99%!", 'green'))
    print("="*15)
    print(colored("More stuff to come soon!", 'red'))
    print("="*15)
    main_menu()

def select_job():
    """ ORIGIONAL METHOD WAS 332 LINES LONG!!!!!!!!!! """
    job_titles = {
        "a": "Cashier",
        "b": "Waitress",
        "c": "Teacher",
        "d": "Administrative Assistant",
        "e": "HR Manager"
    }
    selected_job = input("Select a job\n\nA) Cashier\nB) Waitress\nC) Teacher\nD) Administrative assistant\nE) HR Manager\n>>>").lower().strip()
    for job in get_jobs():
        if job.title == job_titles[selected_job]:
            print(job)
            interested = input("Would you like this job? (Y/N)").lower()
            if interested == "y":
                if player.skill >= job.skill_required:
                    print(colored(f"You have successfully taken the job of {job.title}!", "green"))
                    player.job = job
                    main_menu()
                print(colored("You don't have enough skill for this job!", "red"))
            select_job()
    print(colored("That is an invalid option! Select again!", "red"))
    select_job()
    main_menu()

def your_stuff():
    """ Prints all of the players attributes """
    print(f"""

        Name: {player.name}
        Hunger Level: {player.hunger}
        Job: {player.job}
        Skill: {player.skill}
        Cash: {player.cash}
        Money In Bank Account: {player.bank_account.account_balance}
    """)
    print("Inventory")
    for item in player.inventory:
        print(f"\t{item}")

def work():
    """ Traversing through another work day """
    if player.job is None:
        select_job()

    switch_jobs = input("Do you want to switch jobs?").lower()
    if switch_jobs == "y":
        select_job()

    work_today = input("Do you want to work today? (Y/N)").lower()
    if work_today == "y":

        if player.job.title == "Cashier":
            print(colored("You worked hard today! $89 Has Been deposited to your bank account! -10 hunger, +0.5 skills!", "green"))
            tax = round(96 * 0.0699)
            player.bank_account.account_balance += (96 - tax)
            player.hunger -= 10
            player.skill += 0.5
            work()

        if player.job.title == "Waitress":
            tip = random.randint(0, 100)
            print(colored(f"You worked hard today! $67 Has Been deposited to your bank account. Your Tip for today is: ${tip}.  -10 hunger, +1.5 skills!", "green"))
            tax = round(72 * 0.0699)
            player.bank_account.account_balance += (72 + tip - tax)
            player.hunger -= 10
            player.skill += 1.5
            work()

        if player.job.title == "Teacher":
            print(colored(f"You worked hard today! $120 Has Been deposited to your bank account. -10 hunger, +5 skill!", "green"))
            tax = round(120 * 0.0699)
            player.bank_account.account_balance += (120 - tax)
            player.hunger -= 10
            player.skill += 5
            player.fulltime_days_worked += 1
            determine_bonus()
            work()

        if player.job.title == "Administrative Assistant":
            print(colored(f"You worked hard today! $176 Has Been deposited to your bank account. -12 hunger, +10 skill!", "green"))
            tax = round(176 * 0.0699)
            player.bank_account.account_balance += 176 - tax
            player.hunger -= 12
            player.skill += 10
            player.fulltime_days_worked += 1
            determine_bonus()
            work()

        if player.job.title == "HR Manager":
            print(colored(f"You worked hard today! $210 Has Been deposited to your bank account. -15 hunger, +20 skill!", "green"))
            print("="*15)
            tax = round(210 * 0.0699)
            player.bank_account.account_balance += 210 - tax
            player.hunger -= 15
            player.skill += 20
            player.fulltime_days_worked += 1
            determine_bonus()
            work()
    main_menu()

def determine_bonus():
    """ Used to determine bonuses """
    if (player.fulltime_days_worked % 12) == 0:
        bonus = random.randint(500, 3000)
        print(colored(f"You got a bonus of ${bonus}.", 'green'))
        player.bank_account.account_balance += bonus

def get_jobs():
    """ This method was a pain in my butt!!!!!! """
    jobs = []
    jobs.append(Job("Cashier", 12, 0, 8, 10, 0.5))
    jobs.append(Job("Waitress", 9, 10, 8, 10, 1.5))
    jobs.append(Job("Teacher", 15, 50, 8, 10, 5))
    jobs.append(Job("Administrative Assistant", 22, 250, 8, 12, 10))
    jobs.append(Job("HR Manager", 35, 1500, 6, 15, 20))
    return jobs

def show_slower(str):
    """ Prints letter by letter """
    for char in str:
        time.sleep(0.1)
        sys.stdout.write(char)
        sys.stdout.flush()


if __name__ == '__main__':
    print(colored("""


       M      M                                         ega     ga
      mMe   imMe                                      imMega     g
     imMeg SimMe    mMegaS     aSi Meg     egaSim    SimM            mM gaS  Meg
     imMegaSimMe   imM  aSi  egaSimMe     MegaSim    SimMe     Meg  imMegaSimMega
    SimMegaS mMe  SimM gaSi  ega  mMe        aSim     imMega   Meg  imM  aSi  ega
    Sim  ga  mMe  SimMegaSi  ega  mMe    mMegaSim      mMegaS  Meg  imM  aSi  ega
    Sim  ga  mMe aSim       MegaSimMe   imMe aSim       MegaS mMeg SimM gaSi  ega
   aSim      mMegaSimM gaSi  egaSimMe  SimMe aSim  gaSimMega  mMeg Sim  gaSi  egaS
   aSim      mMeg SimMegaSi      imMe  SimMegaSim  gaSimMega imMegaSim  gaSi  egaS
  gaSim      mMeg  imMegaS  Me  SimMe   imMegaSim  gaSimMe   imMegaSim  gaSi  egaS
                           mMegaSimM
                           mMegaSim

                                              """, 'yellow'))
    init() #colorama
    shutdown = psutil.Process() #psutil
    name = input("Enter your name! ")
    player = Player(name)

    time.sleep(1)
    show_slower("Loading............\n")
    time.sleep(1)
    show_slower("Initializing.............\n")
    time.sleep(1)
    show_slower("Done\n")

    main_menu()
\$\endgroup\$
  • \$\begingroup\$ Thank you so much for reviewing and rewriting the code. it was very informative and I will learn how to use and implement it in future code! I need to learn how to use classes and this is a great starting point for that! Thank you again! \$\endgroup\$ – Joshua Torres Jul 20 at 19:14
  • \$\begingroup\$ There are two things that don't work. 1) unable to consume the item in your inventory to increase hunger. It just shows what's in your inventory 2) Unable to choose another job or switch jobs. \$\endgroup\$ – Joshua Torres Jul 20 at 19:30
  • \$\begingroup\$ @JoshuaTorres As mentioned, I did not touch the hunger portion of your program so it is not included in the program. I edited code to allow you to switch jobs. \$\endgroup\$ – Linny Jul 20 at 19:35
  • \$\begingroup\$ ahh okay! Thanks! \$\endgroup\$ – Joshua Torres Jul 20 at 19:38
  • 4
    \$\begingroup\$ PEP8's section on imports has no notion on ordering them alphabetically, only that you should group them meaningfully. So it's basically up to you how to order your imports, someone else may prefer to order them by the length of their name ;-) \$\endgroup\$ – AlexV Jul 22 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.