Exemple #1
0
 /// <summary>
 /// Pickup first item on given tile
 /// </summary>
 /// <param name="w"></param>
 public void PickupItems(World w)
 {
     if (Inventory.Count >= 10) return;
     // Get a list with nonSolid entities on terrain tile and filter for bananas or keys
     List<Entity> EntitiesOnTile =
         w.getEntitiesOnTerrainTile(getLocation(), true)
             .Where(e => e.getType() == ENTITIES.fruit || e.getType() == ENTITIES.key)
             .ToList();
     // If there's nothing in the list of entities, return;
     if (EntitiesOnTile.Count == 0) return;
     // Add first item of list to inventory
     Inventory.Add(new Item(EntitiesOnTile[0]));
     // If key is picked up, unlock door
     if (EntitiesOnTile[0] is Key)
         w.UnlockDoor((Key)EntitiesOnTile[0]);
     // Remove item from world
     w.getEntities().Remove(EntitiesOnTile[0]);
 }