Exemple #1
0
        public new  Clothes Clone()
        {
            Clothes temp  = new Clothes();
            Goods   goods = base.Clone();

            temp.Id     = goods.Id;
            temp.Name   = goods.Name;
            temp.Price  = goods.Price;
            temp.Weight = goods.Weight;
            temp.Count  = goods.Count;

            temp.color = this.color;
            temp.size  = this.size;
            return(temp);
        }
Exemple #2
0
        /// <summary>
        /// 直接购买操作
        /// </summary>
        /// <param name="index">物品在list中的下标</param>
        /// <param name="count">购买的数量</param>
        public bool directBuy(int index, int count)
        {
            double pay = list[index].Price * count;

            //判断金额是否足够
            if (pay <= user.Money)
            {
                user.Money        = user.Money - pay;
                list[index].Count = list[index].Count - count;
                if (list[index].GetType() == typeof(Food))
                {
                    Food food = ((Food)list[index]).Clone();
                    food.Count = count;
                    user.Hold.Add(food);
                }
                else if (list[index].GetType() == typeof(Clothes))
                {
                    Clothes food = ((Clothes)list[index]).Clone();
                    food.Count = count;
                    user.Hold.Add(food);
                }
                else if (list[index].GetType() == typeof(Phone))
                {
                    Phone food = ((Phone)list[index]).Clone();
                    food.Count = count;
                    user.Hold.Add(food);
                }
                else
                {
                    Console.WriteLine("没有您选中的物品类型!");
                    return(false);
                }
                return(true);
            }
            else
            {
                Console.WriteLine("金额不足,购买失败!");
                return(false);
            }
        }