dis446 / Shelter-Survival-Text-Based

An open source, text based version of the popular Bethesda Fallout Shelter game.
8 stars 7 forks source link

Change the implementation of assigned rooms #24

Closed kungtotte closed 8 years ago

kungtotte commented 8 years ago

It's cumbersome and error prone to have assigned rooms implemented as a string, it's better to use a dict (or a set, to enforce unique values), and pass around person objects.

E.g:

if person in room.assigned:
    # person object found in the dict

for person in room.assigned:
    # do efficiency calcs here, etc. Easily allows 
    # per-person boosts like:
    # boost += person.intelligence
sgtlaggy commented 8 years ago

Why should it be a dict, rather than a list?

kungtotte commented 8 years ago

It should actually be a list. The dict thing was just because I was stuck thinking about the way people are currently handled (with string references to their names).

dis446 commented 8 years ago

Currently, rooms keep track of which inhabitants are in them with a weird string of binary numbers. I.e. 100010 means that the 1st and 5th people are assigned to the room. Transitioning from a list to a dictionary ( for the people) has broken this system. We need a new way for rooms to know who's assigned to them. I would recommend having the room.assigned variable set to a list of the names of the people assigned there, as mentioned before. This can be easily cross-referenced with the people dictionary.