コード例 #1
0
ファイル: textbasedgame.py プロジェクト: V1Soft/textbasedgame
def newGame(name=None):
    global usr, usrFile
    entities.worldEntities = []
    if name != None:
        usr = name
    else:
        try:
            usr = input('What is your desired username? : ')
            usrFile = usr + '.save' # Add extension
        except KeyboardInterrupt:
            play()
    entities.player = obj.Player(usr, 100, 100, float(5))
    entities.player.inventory = [entities.getWeapon('stick'), entities.getFood('potato')]
    entities.player.location = entities.getLocation('Main')
    print('New game set up. Welcome.')
    commandLine()
コード例 #2
0
ファイル: locations.py プロジェクト: V1Soft/textbasedgame
def personInteraction():
    entities.player.location = entities.getLocation('Interact')
    personType = random.randint(1, 3)
    if personType == 1:
        person = [random.choice(entities.enemies), random.choice(entities.weapons)]
        if utils.confirm('You see a mean-looking person in the distance. Do you choose to approach?'):
            utils.fight(person[0], person[1])
        else:
            print('You run away in fear.')
    elif personType == 2:
        if entities.worldEntities:
            person = random.choice(entities.worldEntities)
            person.inventory.append(random.choice(entities.weapons))
            if utils.confirm('You see a familiar, mean-looking person in the distance. Do you choose to approach?'):
                utils.fight(person, person.inventory[0])
            else:
                print('You run away in fear.')
        else:
            person = random.choice(entities.enemies)
            person.inventory.append(random.choice(entities.weapons))
            if utils.confirm('You see a mean-looking person in the distance. Do you choose to approach?'):
                utils.fight(person, person.inventory[0])
            else:
                print('You run away in fear.')
    else:
        person = [random.choice(entities.helpers), random.choice(entities.helperItems)]
        if utils.confirm('You see a kind-looking person in the distance. Do you choose to approach?'):
            print('The person is a(n) ' + person[0].name + '!')
            if person[0] == entities.getHelper('old lady'):
                if random.randint(0,1) == 0:
                    utils.fight(entities.getEnemy('old lady'), entities.getWeapon('cane'))
                else:
                    time.sleep(0.5)
                    print('The %s smiles and holds a(n) %s out in her hand.' % (person[0].name, person[1].name))
                    entities.player.inventory.append(person[1])
                    time.sleep(0.2)
                    print(person[1].name + ' added to your inventory!')
            else:
                time.sleep(0.5)
                print('The %s smiles and holds a(n) %s out in her hand.' % (person[0].name, person[1].name))
                entities.player.inventory.append(person[1])
                time.sleep(0.2)
                print(person[1].name + ' added to your inventory!')
        else:
            print('You walk away')
            time.sleep(2)
コード例 #3
0
ファイル: locations.py プロジェクト: V1Soft/textbasedgame
def memory():
    while True:
        try:
            rand = random.randint(0,1)
            print(rand, end='')
        except KeyboardInterrupt:
            try:
                print('\nRegaining Train of Thought...\n')
                time.sleep(10)
            except KeyboardInterrupt:
                try:
                    print('\nEntering Subconcience...\n')
                    time.sleep(10)
                except KeyboardInterrupt:
                    print('\nProgress Lost.')
                    sys.exit(0)
                try:
                    while True:
                        command = input('ZZZ : ').split(' ')
                        if command[0].upper() == 'WAKE':
                            print('It cost 10 coins to wake.')
                            entities.player.spend(10)
                            return
                        elif command[0].upper() == 'LOADMOD':
                            if len(command) > 1:
                                os.system(command[1])
                            else:
                                print('Usage: loadmod <mod>')
                        elif command[0].upper() == 'VIEWMATRIX':
                            os.system('cat textbasedgame.py')
                            print('You are not here...')
                            time.sleep(5)
                            return
                            while True:
                                command = input('ZZZ/Matrix : ').split(' ')
                                if command[0].upper() == 'GOTO':
                                    print('Whoops')
                                    #print(str(open('textbasedgame.py', newline=None)).split('\n')[int(command[1])])
                        elif command[0].upper() == 'GET':
                            if len(command) > 2:
                                if len(command) < 4:
                                    if command[1].upper() == 'FOOD':
                                        entities.player.inventory.append(entities.getFood(command[2]))
                                    elif command[1].upper() == 'WEAPON':
                                        entities.player.inventory.append(entities.getWeapon(command[2]))
                                else:
                                    try:
                                        if command[1].upper() == 'FOOD':
                                            i = 0
                                            while i < int(command[3]):
                                                entities.player.inventory.append(entities.getFood(command[2]))
                                                i += 1
                                        elif command[1].upper() == 'WEAPON':
                                            i = 0
                                            while i < int(command[3]):
                                                entities.player.inventory.append(entities.getWeapon(command[2]))
                                                i += 1
                                    except ValueError:
                                        print('Usage:\tget <type> <object>\n\tget <type:food/weapon> <object> <amount>\nAmount must be integer.')
                            else:
                                print('"get" requires 3 arguments. Maximum: 4.')
                        elif command[0].upper() == 'GOTO':
                            if command[1].upper() == 'SLEEP':
                                print('Before you may sleep...')
                                time.sleep(2.5)
                                print('You must fight me...')
                                time.sleep(2.5)
                                print('I am you...')
                                time.sleep(2.5)
                                print('But you are not me.')
                                time.sleep(10)
                                utils.fight(entities.you, utils.getBestInventoryWeapon()[1])
                                sleep()
                except KeyboardInterrupt:
                    try:
                        print('\nRegaining Train of Thought...\n')
                        time.sleep(10)
                    except KeyboardInterrupt:
                        print('\nSuffered Memory Loss.\n')
                        rand = random.randint(0,2)
                        if rand == 0:
                            entities.player.inventory = []
                        elif rand == 1:
                            entities.player.money = 0
                        else:
                            entities.player.power = float(0)
                        return