001import java.util.HashMap;
002import java.util.Set;
003
004public class Door {
005    private boolean aLocked;
006    private Item aKey;
007
008    public Door(final boolean pLocked, final Item pKey) {
009        this.aLocked = pLocked;
010        this.aKey = pKey;
011    }
012
013    public boolean getLocked() {
014        return this.aLocked;
015    }
016
017    public void openDoor() {
018        this.aLocked = false;
019    }
020
021    public void closeDoor() {
022        this.aLocked = true;
023    }
024    /**
025     * Détermine si la clé qui permet d'ouvrir la porte est dans la collection d'items passée en argument
026     * @param pItems collection d'items du joueur
027     * @return boolean
028     */
029    public Item getGoodKey(final HashMap<String, Item> pItems) {
030        Set<String> allKeys = pItems.keySet();
031        for (String vKey : allKeys) {
032            if (pItems.get(vKey).equals(this.aKey)) {
033                return aKey;
034            }
035        }
036        return null;
037    }
038}