Esempio n. 1
0
 /// <summary>
 /// Method fills the List<Gum>
 /// </summary>
 /// <param name="num"></param>
 /// <param name="taste"></param>
 /// <param name="color"></param>
 private void FillMachineWithGum(int num, string taste, string color)
 {
     for (int i = 0; i < num; i++)
     {
         Gums.Add(new Gum(taste, color));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Method that returns a random Gum from the Machine an removes it from the list
        /// </summary>
        /// <returns></returns>
        public Gum GetGum()
        {
            Random rnd = new Random();

            Thread.Sleep(100);
            try
            {
                int rndNum = rnd.Next(0, Gums.Count);
                Gum gum    = Gums[rndNum];
                Gums.Remove(Gums[rndNum]);
                return(gum);
            }
            catch (Exception)
            {
                Console.WriteLine("No more gums in the machine");
                return(null);
            }
        }