[Tutor] my text adventure
david
din22 at earthlink.net
Wed Nov 30 13:33:47 CET 2005
> You might want to make coords an init parameter for Room, rather than
> assigning it separately. You could also have Rooms register themselves
> with world as part of their initialization, that would be better than
> having to repeat yourself in the definition of world.
brilliant! i'll do that.
>>
>> class Object:
>> def __init__(self,name):
>> self.name = name
>>
>> def getname(self):
>> return self.name
>
> Object is not such a great name, it is too easily confused with object,
> the base class of new-style classes. Maybe Item?
>
> Right now this class isn't pulling its weight, it could be replaced by a
> simple string. Presumably you will add more functionality to it; if so
> it's worth keeping it around, otherwise get rid of it.
>
> Common Python practice is *not* to define setters and getters, just access
> the attribute directly - so get maybe you don't need getname>
i just now learned what setter and getter is.
i did this to make my inventory function work properly.
i'll try to remove my getter.
didn't know we had new-style classes.
>> def look(self):
>> print self.location.name
>>
>> def move(self,direction):
>> if self.location.exits.has_key(direction):
>> self.location = self.location.exits[direction]
>> print self.location.name
>> else: print 'alas, you cannot go that way'
>> def dig(self,direction):
>> lcoords = list(self.location.coords)
>
> Why do you convert to a list? You can access tuple elements by index.
i need to change the coordinates of the current room to the room i'm
digging into so i can check world to see if that room exists.
there is probably a better way to do all that.
>
>> if self.location.exits.has_key(direction):
>> print 'there is already an exit there'
>>
>>
>> elif direction == 'n':
>> ncoords[1] == lcoords[1] + 1
>
> You probably mean
> ncoords[1] = lcoords[1] + 1
> but I think I would make ncoords a local variable and just say
> ncoords = (0, lcoords[1] + 1)
>
> With ncoords as a global you have a bug, you only set one element here,
> the other one will be left over from the last time through.
>
> Kent
i stuck that global up there to make something work. i forget what now.
maybe i should take notes or something :) i'm thinking i should write some
separate convert directions to coordinates function.
thanks for the thought food and thanks for taking time to look at my code.
version 2 will be along shortly but don't hold your breath :) (because thats
bad for you)
More information about the Tutor
mailing list