OO and game design questions

dex josipmiskovic at gmail.com
Mon Oct 18 09:50:49 EDT 2010


> You're aware Python can collect reference cycles, correct?  You don't
> have to delete references; Python will get them eventually.  

I'm not sure I understand this part? If I don't delete all strong
references, the object will not be deleted.
It will persist and occupy memory as long as there's at least one
reference to it (it could be part of inventory, or target of some
action).


> Instead, I'd recommend managing the lifetime of all objects (creating
> and destroying) through game_object methods.  To create an object,
> don't call its constructor, call obj =
> game_object.create(<object_type>,args) and game_object.destroy(obj).
> (If you really want to be strict about it, you can override __init__
> to raise an exception (thus disabling the normal way to create an
> object), and create the objects in you create method by calling the
> class's __new__ method directly.)

This makes sense, I will make these modifications.

> Your objects should have two sets of attributes (beginning of round,
> end of round) and a method to copy the end-of-round attributes to the
> beginning-of-round area at the end of the round.

Perhaps I could utilize properties. Make getters return start-of-round
attributes
and setters set end-of-round attributes. Things would get a bit messy
if two or more players modify the same attribute or chest content.
I need to think about this some more.

Thanks for your thoughts.





More information about the Python-list mailing list