Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        private static void Start()
        {
            string choice;

            do
            {
                Console.Clear();
                Console.WriteLine("You stand at the GumMachine");
                Console.WriteLine($"It looks like there is {GumMachine.Instance.Gums.Count} pieces of gums left");
                Console.WriteLine("1) Take a piece of Gum");
                Console.WriteLine("2) Refill the machine with gum");
                choice = Console.ReadLine();
                switch (choice)
                {
                case "1":
                    if (GumMachine.Instance.Gums.Count != 0)
                    {
                        Gum gum = GumMachine.Instance.GetGum();
                        Console.WriteLine(gum.ToString());
                    }
                    else
                    {
                        Console.WriteLine("No more gum - Please refill");
                    }
                    break;

                case "2":
                    Console.WriteLine(GumMachine.Instance.Refillmachine());
                    break;

                default:
                    Console.WriteLine("What are you doing?");
                    break;
                }
                Console.ReadLine();
            } while (true);
        }