Пример #1
0
    static public void serve()
    {
        while (!Trays.isEmpty())
        {
            if (Trays.borekInPlate <= 1 && Trays.totalBorek != 0 && !(Trays.borekInPlate == Trays.totalBorek))
            {
                Console.WriteLine("The waiter came, filling the borek tray...");

                if (Trays.totalBorek > 4)
                {
                    Trays.borekInPlate = 5;
                }
                else
                {
                    Trays.borekInPlate = Trays.totalBorek;
                }
                Console.WriteLine("The waiter is return..\n");
            }
            else if (Trays.drinkInPlate <= 1 && Trays.totalDrink != 0 && !(Trays.drinkInPlate == Trays.totalDrink))
            {
                Console.WriteLine("The waiter came, filling the drink tray...");

                if (Trays.totalDrink > 4)
                {
                    Trays.drinkInPlate = 5;
                }
                else
                {
                    Trays.drinkInPlate = Trays.totalDrink;
                }
                Console.WriteLine("The waiter is return..\n");
            }
            else if (Trays.cakeInPlate <= 1 && Trays.totalCake != 0 && !(Trays.cakeInPlate == Trays.totalCake))
            {
                Console.WriteLine("The waiter came, filling the cake tray...");

                if (Trays.totalCake > 4)
                {
                    Trays.cakeInPlate = 5;
                }
                else
                {
                    Trays.cakeInPlate = Trays.totalCake;
                }
                Console.WriteLine("The waiter is return..\n");
            }
            Thread.Sleep(2000);
        }
        Console.ResetColor();
        foreach (var guest in Guests.getGuests())
        {
            Console.WriteLine(guest.name + "\nBorek: {0} Drink: {1} Cake: {2}", guest.takenBorek, guest.takenDrink, guest.takenCake);
            Console.WriteLine("*****************************");
        }
    }
Пример #2
0
    public static void drinkLine()
    {
        List <Guest> inDrinkLine     = new List <Guest>(Guests.getGuests());
        List <Guest> neverTakesDrink = new List <Guest>(Guests.getGuests());
        bool         fromNeverTakes  = false;
        var          rand            = new Random();
        int          index;
        Guest        guest;

        while (!Trays.isEmpty())
        {
            if (neverTakesDrink.Count != 0)
            {
                index          = rand.Next(neverTakesDrink.Count);
                guest          = neverTakesDrink[index];
                fromNeverTakes = true;
            }
            else
            {
                index = rand.Next(inDrinkLine.Count);
                guest = inDrinkLine[index];
            }


            if (Trays.totalDrink != 0 && Trays.drinkInPlate > 0)
            {
                lock (guest)
                {
                    if (fromNeverTakes)
                    {
                        neverTakesDrink.RemoveAt(index);
                        fromNeverTakes = false;
                    }
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine(guest.name + " is going to take a Drink");
                    guest.takenDrink++;
                    Trays.totalDrink--;
                    Trays.drinkInPlate--;
                    Console.WriteLine(guest.name + " take a Drink");
                    Console.WriteLine(guest.name + " is return\n");
                }
            }
            if (guest.takenDrink == 5)
            {
                inDrinkLine.RemoveAt(index);
            }
            Thread.Sleep(rand.Next(1000, 4000));
        }
    }