Text Based Adventure

LIFE Inc.

A Text Adventure Game

Text Based Adventure


Classes


Functions


Conditional Statements


While Loop


Progress so far

from random import randint

class player:
    health = 100
    money = 10000
    level = 0
    activities = ['money', 'game', 'doctor']

    def get_money():
        player.money += 500
    def help():
        print('You can choose', player.activities)
    def game():
        print('This game cost $500 to play')
        play = input('Do you want to play?')
        if play == 'yes':
            player.money -= 500
            print('If you can guess my number in 5 tries, I will give you a prize')
            rando = randint(1,10)
            for i in range(5):
                guess = int(input('Guess a number'))
                if guess == rando:
                    print("Here is $2000")
                    player.money += 2000
                elif guess < rando:
                    print('Guess Higher')
                else:
                    print('Guess Lower')

while True:
    print('=====================')
    print('Money:', player.money)
    activity = input('What would you like to do')

    if activity == 'money':
        player.get_money()
    if activity == 'help':
        player.help()
    if activity == 'game':
        player.game()

        

Final Program

from random import randint, choice
import keyboard
import time
print('Welcome to LIFE Inc!')
print("My name is PyGuy, and I'll be you virtual assistant!")

userName = input('What is your name?')
userAge = int(input('How old are you?'))

print('You will begin with 10 attribute points that you can use')
print('You can spend then on INTELLECT, STRENGTH, or INFLUENCE')

Balance = 10
userIntellect = int(input('Intellect:'))
Balance = Balance - userIntellect
print('Balance:', Balance)
userStrength = int(input('Strength:'))
Balance = Balance - userStrength
print('Balance:', Balance)
userInfluence = int(input('Influence:'))
Balance = Balance - userInfluence
print('Balance:', Balance)                 

class player:
    name = userName
    grade = 'Graduated'
    age = userAge
    money = 10000
    level = 0
    experience = 0
    intellect = userIntellect
    strength = userStrength
    influence = userInfluence
    activities = ['school', 'game', 'gym', 'job']

    def help():
        print('Here are a list of activities you can do!')
        print(player.activities)
        
    def school():
        questions = ['What is your name?', 'How old are you']
        answers = [player.name, str(player.age)]
        print('Welcome to class!')
        print('At school you can increase your intellect by taking quizzes')
        if player.intellect < 10:
            player.grade = 'Kindergarten'
        elif player.intellect >= 10 and player.intellect < 15:
            player.grade = '1st' 
            questions.append('What is 5+5?')
            questions.append('What is 5-3?')
            answers.append('10')
            answers.append('2')
        elif player.intellect >= 15 and player.intellect < 20:
            player.grade = '2nd'
        elif player.intellect > 20 and player.intellect < 25:
            player.grade = '3rd'
        elif player.intellect > 25 and player.intellect < 30:
            player.grade = '4th'
        elif player.intellect > 25 and player.intellect < 30:
            player.grade = '5th'
        elif player.intellect > 30 and player.intellect < 50:
            player.grade = 'Middle School'
        elif player.intellect > 50 and player.intellect < 100:
            player.grade = 'High School'
        print('You are currently in', player.grade)
        quiz = input('Would you like to start a quiz?')
        if quiz == 'yes':
            print('Okay here we go!')
            question = choice(questions)
            print(question)
            answer = input()
            quiz_num = questions.index(question)
            if answer == answers[quiz_num]:
                print('Correct!')
                print(player.name, 'has earnered +1 intellect')
                player.intellect += 1
                player.experience += 5
            else:
                print('That is incorrect')
                print('Study harder next time!')
        else:
            print('Then why did you come to school?')
            
    def game():
        print('Welcome to the game room!')
        print('Lets play a guessing game.')
        print('If you can guess my number in less than 5 tries you will earn a prize!')
        rando = randint(0,10)
        win = False
        for i in range(5):
            guess = int(input('Guess a number between 1-10'))
            if guess == rando:
                player.money += 1000
                print('Great Job, you earned $1000')
                break
            elif guess < rando:
                print('Guess Higher')
            else:
                print('Guess Lower')
        if win == False:
            print('Sorry you did not win this time')
            print('You lost $250 for wasting my time')
            player.money -= 250
            
    def gym():
                
        t = time.localtime()
        start_time = int(time.strftime("%S", t))
        lifts = 0
        print('Tap space to lift weights')
        while True:
            if keyboard.is_pressed('space'):
                lifts += .002
            if lifts > 100:
                break
            
        t = time.localtime()
        end_time = int(time.strftime("%S", t))
        if start_time >= end_time:
            end_time = end_time + 60
        result = 20 - (end_time - start_time)
        print(result)
            
        print('You gain', result, 'strength')
        player.strength += result
        
    def job():
        if player.grade == 'Graduated':
            print('Welcome to work')
            print('You are a bomb diffuser')
            print('Press letters to try to diffuse bomb')
            letters = ['a','b','c','d','e','f','g','h','i','j','k','l',
                       'm','n','o','p','q','r','s','t','u','v','w',
                       'x','y','z']
            bombs = []
            for i in range(5):
                bombs.append(choice(letters))
            time = 100
            while True:
                time -= .001
                if keyboard.is_pressed(bombs[0]):
                    player.money += int(time)
                    print('You earned', int(time), 'dollars')
                    break
                if keyboard.is_pressed(bombs[1]):
                    player.money += int(time)
                    print('You earned', int(time), 'dollars')
                    break
                if keyboard.is_pressed(bombs[2]):
                    player.money += int(time)
                    print('You earned', int(time), 'dollars')
                    break
                if keyboard.is_pressed(bombs[3]):
                    player.money += int(time)
                    print('You earned', int(time), 'dollars')
                    break
                if keyboard.is_pressed(bombs[4]):
                    player.money += int(time)
                    print('You earned', int(time), 'dollars')
                    break
                if time < 0:
                    print('BOOOOM!!, You did not diffuse the bomb')
                    player.money -= int(time)
                    print('You lost', -(int(time)), 'dollars')
                    break
                
            
        else:
            print('You are not old enough to get a job, finish school first')
    
    
        

while True:
    print('================================')
    print('Name:', player.name, '|', 'Age:', player.age,'|','Money:',player.money)
    print('Experience:', player.experience,'|', 'Level:', player.level)
    print('Intellect:', player.intellect,'|', 'Strength:', player.strength, '|', 'Influence:',player.influence)
    print('___________________________________')
    action = input('What would you like to do?')

    if action == 'help':
        player.help()
    if action == 'school':
        player.school()
    if action == 'game':
        player.game()
    if action == 'gym':
        player.gym()
    if action == 'job':
        player.job()