示例#1
0
 static void drawContainer(CoffeeMashine Mashine)
 {
     //TODO: not very DRY!
     Console.SetCursorPosition(0, 17);
     Console.Write("Kaffee {0,3}% : ", Mashine.CCoffee);
     for (int counter = 0; counter < 50; counter++)
     {
         Console.BackgroundColor = (Mashine.CCoffee / 2 > counter?ConsoleColor.Blue : ConsoleColor.Black);
         Console.Write(" ");
     }
     Console.ResetColor();
     Console.Write("\nMilch {0,3}% :  ", Mashine.CMilk);
     for (int counter = 0; counter < 50; counter++)
     {
         Console.BackgroundColor = (Mashine.CMilk / 2 > counter ? ConsoleColor.Blue : ConsoleColor.Black);
         Console.Write(" ");
     }
     Console.ResetColor();
     Console.Write("\nWasser {0,3}% : ", Mashine.CWater);
     for (int counter = 0; counter < 50; counter++)
     {
         Console.BackgroundColor = (Mashine.CWater / 2 > counter ? ConsoleColor.Blue : ConsoleColor.Black);
         Console.Write(" ");
     }
     Console.ResetColor();
     Console.Write("\nSatz {0,3}% :   ", Mashine.CWasteCoffee);
     for (int counter = 0; counter < 50; counter++)
     {
         Console.BackgroundColor = (Mashine.CWasteCoffee / 2 > counter ? ConsoleColor.Blue : ConsoleColor.Black);
         Console.Write(" ");
     }
     Console.ResetColor();
     Console.Write("\nReste {0,3}% :  ", Mashine.CWasteWater);
     for (int counter = 0; counter < 50; counter++)
     {
         Console.BackgroundColor = (Mashine.CWasteWater / 2 > counter ? ConsoleColor.Blue : ConsoleColor.Black);
         Console.Write(" ");
     }
     Console.ResetColor();
 }
示例#2
0
        static void Main()
        {
            Console.CursorVisible = false;
            Console.SetCursorPosition(15, 0);
            Console.WriteLine("Hallo User, dies ist ein Kaffeeautomat");
            Console.SetCursorPosition(15, 1);
            Console.WriteLine("Kaffeemaschine wird gestartet");

            CoffeeMashine coffeeMashine = new CoffeeMashine();
            ConsoleKey    userInput;
            bool          shutdownMashine = false;

            Button[] buttons = new Button[5];
            buttons[0].Text         = "Kaffee";
            buttons[0].MachineValue = Recipe.Coffee;

            buttons[1].Text         = "Capuchino";
            buttons[1].MachineValue = Recipe.Capuchino;

            buttons[2].Text         = "Milchkaffee";
            buttons[2].MachineValue = Recipe.CoffeeMilk;

            buttons[3].Text         = "Heiße Milch";
            buttons[3].MachineValue = Recipe.HotMilk;

            buttons[4].Text         = "Heißes Wasser";
            buttons[4].MachineValue = Recipe.HotWater;

            byte activeButtonID = 0;


            do
            {
                Thread.Sleep(50);
                DrawButtons(activeButtonID, buttons);
                userInput = Console.ReadKey(true).Key;

                switch (userInput)
                {
                case ConsoleKey.UpArrow:
                    if (activeButtonID > 0)
                    {
                        activeButtonID--;
                    }
                    break;

                case ConsoleKey.DownArrow:
                    if (activeButtonID < buttons.Length - 1)
                    {
                        activeButtonID++;
                    }
                    break;

                case ConsoleKey.Enter:
                    Console.WriteLine("Ihr " + buttons[activeButtonID].Text + " wird zubereitet");
                    if (coffeeMashine.Dispense(buttons[activeButtonID].MachineValue))
                    {
                        Console.WriteLine("Ihr " + buttons[activeButtonID].Text + " ist Fertig");
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Fehler beim zubereten, prüfen sie die Kontainer");
                        Console.ResetColor();
                        Thread.Sleep(2000);
                    }

                    Console.WriteLine("Ihr Kaffee ist fertig");
                    break;

                case ConsoleKey.K:
                    Console.WriteLine("Ihr Kaffee wird zubereitet");
                    if (coffeeMashine.Dispense(Recipe.Coffee))
                    {
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Ihr Kaffee konnte nicht zubereitet werden, checken sie die Kontainer");
                        Console.ResetColor();
                    }

                    break;

                case ConsoleKey.A:
                    shutdownMashine = true;
                    break;

                case ConsoleKey.W:
                    coffeeMashine.Maintenance();
                    Console.WriteLine("Wartung durchgeführt, container sind wieder ok.");
                    break;

                default:
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Die Eingabe verstehe ich nicht.");
                    Console.ResetColor();
                    break;
                }
            } while (!shutdownMashine);

            Console.WriteLine("Kaffeeautomat wird beendet");
        }