takluyver / weatbag

Written by Everyone Altogether, The Big Adventure Game
MIT License
21 stars 11 forks source link

Add item interface #9

Closed kkpattern closed 11 years ago

kkpattern commented 11 years ago

I try to add the item interface like the tile interface. If you want to create a new item, just create a module like weatbag.items.sword and then define the following methods in the module:

def take(tile, player):
    # Called when player try to take the item.
    ...

def use(tile, player):
    # Called when player try to use the item.
    ...

def drop(tile, player):
    # Called when player try to drop the item.
    ...

Then, when player try to pick or use the item in the game, just do:

from weatbag.items import take
...
class Tile:
    ...
    def action(self, player, do):
        ...
        if do[0] in words.take:
            take(do[1], self, player)
        ...

I rewrote the code about berries as an example. If you guys have any better ideas please tell me, I am happy to know.

takluyver commented 11 years ago

Hi @kkpattern. Thanks for this, but it's not quite the way I want to do it. I think it would end up being more confusing for people adding content. Don't be put off: working out the best way to do things is an important part of adding new features.

Specifically, I want to keep items as largely tokens (they're currently string tokens), and have most of the code associated with the tiles. In order to be put in dictionaries, they'll need to be hashable tokens, i.e. class instances with __hash__ and __eq__ methods. It's probably worth having an ItemBase class for that.

Some code will need to be attached to the objects. In particular, I'd like them to have a combine() method, so you can combine objects to make new ones. Then there are all sorts of more specialist possibilities, like a sword that sometimes goes blunt and has to be sharpened.

I'll have a go at designing this, and let you comment on it before I merge it.

takluyver commented 11 years ago

Actually, now that I'm implementing this, I'm coming back to something more like your design, with modules for items...

kkpattern commented 11 years ago

@takluyver Fantastic! I'm looking forward to see your implementing. So should I just close this pull request?

takluyver commented 11 years ago

Oh yes. I'll close it now. I've nearly got something ready...

takluyver commented 11 years ago

Have a look at #11