Example #1
0
        protected override void OnChildPageAppearing(object sender, EventArgs e)
        {
            MessagingCenter.Subscribe <FoodViewModel, FoodEntry>(this, CommandNames.AddFood, (obj, item) =>
            {
                Foods.Add(item);
            });

            MessagingCenter.Subscribe <FoodViewModel, FoodEntry>(this, CommandNames.RemoveFood, (obj, item) =>
            {
                Foods.Remove(item);
            });
        }
Example #2
0
        /// <summary>
        ///     减少食物
        /// </summary>
        /// <param name="foodId">食物Id</param>
        /// <returns></returns>
        public bool RemoveFood(int foodId)
        {
            var food = Foods.Find(p => p.Id == foodId);

            if (food == null)
            {
                return(false);
            }

            var success = Foods.Remove(food);

            if (success)
            {
                OnRemoveFood?.Invoke(food);
            }

            return(success);
        }
Example #3
0
 private void SubMethod(object obj)
 {
     try
     {
         if ((string)obj == "Mashroom")
         {
             if (MashroomCount > 0)
             {
                 MashroomCount--;
                 MashroomsCustomNos.RemoveAt(MashroomsCustomNos.Count - 1);
                 Foods.Remove(Foods.OfType <Caters.Model.Pizza.Mashroom>().First());
             }
         }
         else if ((string)obj == "Panner")
         {
             if (PannerCount > 0)
             {
                 PannerCount--;
                 PannerCustomNos.RemoveAt(PannerCustomNos.Count - 1);
                 Foods.Remove(Foods.OfType <Caters.Model.Pizza.PannerPizza>().First());
             }
         }
         else if ((string)obj == "SevenUp")
         {
             if (SevenUpCount > 0)
             {
                 SevenUpCount--;
                 SevenUpCustomNos.RemoveAt(SevenUpCustomNos.Count - 1);
                 Foods.Remove(Foods.OfType <Caters.Model.ColdDrink.SevenUp>().First());
             }
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        public virtual Tuple <bool, byte> DeleteFood(int id)
        {
            Food food    = Foods.SingleOrDefault(w => w.ID == id);
            bool success = false;

            if (food != null)
            {
                if (food.Animals.Count > 0)
                {
                    return(new Tuple <bool, byte>(false, (byte)ModelType.Animal));
                }
                Foods.Remove(food);
                try
                {
                    SaveChanges();
                    success = true;
                }
                catch (Exception e)
                {
                    Logger.LogError($"Exception removing food! Exception: {e.ToString()}", GetType(), $"DeleteFood(id: {id})");
                }
            }
            return(new Tuple <bool, byte>(success, (byte)ModelType.Model));
        }
Example #5
0
        public void GetHarvestedFood()
        {
            var harvested = new List <Food>();

            foreach (var food in Foods)
            {
                for (int index = 0; index < Agents.Count; index++)
                {
                    var agent = Agents[index];
                    if (GetDistance(food.X, food.Y, agent.X, agent.Y) < 15)
                    {
                        harvested.Add(food);
                        agent.HarvestedFood++;
                    }
                }
            }

            foreach (var t in harvested)
            {
                Foods.Remove(t);
                var food = new Food(Random.Next(0, Width), Random.Next(0, Height));
                Foods.Add(food);
            }
        }
Example #6
0
        private void RemoveFood(Food food)
        {
            Foods.Remove(food);

            RemoveFoodAsync(food);
        }
Example #7
0
 private void RemoveFood(Transform Food)
 {
     Foods.Remove(Food);
     Destroy(Food.gameObject);
 }