OO and game design questions
Terry Reedy
tjreedy at udel.edu
Tue Oct 19 17:48:08 EDT 2010
On 10/19/2010 1:46 PM, Ian Kelly wrote:
> On Tue, Oct 19, 2010 at 5:37 AM, Dave Angel <davea at ieee.org
> <mailto:davea at ieee.org>> wrote:
>
> On 2:59 PM, dex wrote:
>
> Using strong references, I have to remove room B from list of rooms,
> and also remove door to room B, as it holds reference to room B.
> To do
> that, I have to keep list of doors that lead to room B.
>
> Using weak references, I don't have to worry about removing all
> doors
> to room B. They all now have a dead reference, which better models
> actual situation. If part of mine collapses, or if a module on space
> station is destroyed, the passage to that location does not
> magically
> vanish - it's just obstructed.
>
> Can you please tell me if there's something wrong with my reasoning?
>
> Simply replace room B with a "destroyed room" object. That can be
> quite small, and you only need one, regardless of how many rooms are
> thus eliminated.
>
>
> How does this avoid the problem of having to keep a list of doors that
> lead to room B? You can't just replace one object with another. You
> would have to replace every reference to B with a reference to the new
> object. This is no simpler than deleting the references or replacing
> them with None.
One should rather *change* (not replace) the room into a 'destroyed
room' or 'collapsed passage' or whatever, that cannot be entered. The
keeps the room around but allows it to be repaired, rebuilt, cleared, or
whatever.
--
Terry Jan Reedy
More information about the Python-list
mailing list