usually an adventure game has rooms, objects, and the player.
i started generalizing it a little so everything was a Thing:

class Thing:
    def __init__(self, name, descr, where=None, **connections):
        self.name = name
        self.descr = descr
        self.where = where
        self.contents = []
        if where is not None:
            self.where.contents.append(self)
        self.connections = connections

sadly this excessive generality makes it seem more ai-like :/ the
intent was to make it concise and simple kinda
i'm kind of confused
maybe i'll make the player an object, and have rooms separate. that's
less ai-like.

i dunno i like Thing :s but it makes it last less long :( blrrrgh

ok now i'm compromising and making Room a subclass of Thing that has
exits :s :s stil lmakes it not last as long :s

thinking a little on exits vs connections, i suppose a generalization
there is how things can be moved along other things
for example, you can climb a tree, but the tree doesn't need to be a
room to its own. it's a connection between the top of the tree and the
bottom. and only som ethings can climb that connection. other things
can also travel it, like water or sap flowing along it. dunno.

another idea for exits, connections is maybe more useful: one could
represent the relative location of things. then you could put a box on
a stone, or on some grass, etc ... this sounds like what exits should
be ;-)
maybe too ai-like for now though

2124

ok i tried to make a supersimple adventure to demonstrate what
adventures are like
basically traditionally they have verbs and a bunch of hardcoded
engine behaviors that respond to them (amidst a graph of rooms and
objects and such)
the more one implements old computational linguistics the smarter it gets

this is how text adventures used to look and function, very
simplistically dumbed down.
the attached code creates a super simple one with two rooms, a "simple
room", and a "bland room". the user starts in the simple room, whereas
the bland room contains an object.

You are in the simple room.

What do you do?
> look

You are in a simple, nondescript room.

The bland room is to the east.

What do you do?
> east

You go east to the bland room.

What do you do?
> look

You are in a basic, bland room.
There is an object here.

The simple room is to the west.

What do you do?
> examine object

It is a basic simple object.

What do you do?
> take object

You pick up the object.

What do you do?
> inventory

You are carrying an object.

What do you do?
> west

You go west to the simple room.

What do you do?
> drop object

You drop the object.

What do you do?
> look

You are in a simple, nondescript room.
There is an object here.

The bland room is to the east.

What do you do?
> quit
class Thing:
    def __init__(self, name, descr, where=None):
        self.name = name
        self.descr = descr
        self.where = where
        self.contents = set()
        if where is not None:
            self.where.contents.add(self)
    def move(self, where):
        self.where.contents.remove(self)
        where.contents.add(self)
        self.where = where

class Room(Thing):
    def __init__(self, name, descr, **exits):
        super().__init__(name, descr)
        self.exits = exits

bland_room = Room('bland room', 'You are in a basic, bland room.')
simple_room = Room('simple room', 'You are in a simple, nondescript room.')
simple_room.exits['east'] = bland_room
bland_room.exits['west'] = simple_room
player = Thing('Player', 'You look like you.', simple_room)
object = Thing('object', 'It is a basic simple object.', bland_room)

def indefine(word):
    VOWELS, SEMIVOWELS = 'AEIOUaeiou', 'Yy'
    if word.istitle():
        return word
    elif word[0] in VOWELS or (word[0] in SEMIVOWELS and word[1] not in VOWELS):
        return 'an ' + word
    else:
        return 'a ' + word

print('\nYou are in the ' + player.where.name + '.')
while True:
    print('\nWhat do you do?')
    try:
        verb, *verb_objects = input('> ').rstrip().lower().removeprefix('go ').split(' ', 1)
        print()
        verb_objects = ' '.join(verb_objects).removeprefix('the ').removeprefix('a ').removeprefix(player.where.name).removeprefix('around')
        match = [x for ctx in [player, player.where] for x in ctx.contents if x.name.lower() == verb_objects]
        assert len(match) < 2
        match = match[0] if match else None
        if verb in ['look', 'lookat', 'examine']:
            if verb_objects:
                if match:
                    print(match.descr)
                else:
                    print('There is no ' + verb_objects + ' here.')
            else:
                print(player.where.descr)
                for object in player.where.contents:
                    if object is not player:
                        print('There is ' + indefine(object.name) + ' here.')
                print()
                for exit, dest in player.where.exits.items():
                    print('The ' + dest.name + ' is to the ' + exit + '.');
        elif verb in ['take', 'get', 'pickup']:
            assert match
            if match.where == player:
                print('You already have the ' + match.name + '.')
            else:
                print('You pick up the ' + match.name + '.')
                match.move(player)
        elif verb in ['drop', 'putdown']:
            assert match
            if match.where != player:
                print('You\'re not carrying the ' + match.name + '.')
            else:
                print('You drop the ' + match.name + '.')
                match.move(player.where)
        elif verb in ['inv', 'inventory']:
            print('You are carrying ' + ', '.join([indefine(obj.name) for obj in player.contents]) + '.')
        elif verb in player.where.exits:
            print('You go ' + verb + ' to the ' + player.where.exits[verb].name + '.');
            player.move(player.where.exits[verb])
        elif verb in ['quit']:
            break
        else:
            assert False
    except AssertionError:
        print('I don\'t understand.')
            
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many
  • Re: [ot][spa... Undescribed Horrific Abuse, One Victim & Survivor of Many

Reply via email to