Esempio n. 1
0
            static void Main(string[] args)
            {
                CoffeeSort arabica = new CoffeeSort(SortsOfCoffee.Arabica, 2);
                CoffeeSort robusta = new CoffeeSort(SortsOfCoffee.Robusta, 5);

                CoffeeMachine coffeeMaker = new CoffeeMachine(arabica, robusta);
                User          coffeeLover = new User(5);

                Program.Run(coffeeMaker, coffeeLover);
            }
Esempio n. 2
0
            private static CoffeeSort SelectionCoffee(CoffeeMachine coffeeMachine, User user)
            {
                while (true)
                {
                    coffeeMachine.TransitionToState(new WaitingState());
                    coffeeMachine.DisplayState();
                    uint selectedSortOfCoffee = user.SelectSortOfCoffee();

                    if (selectedSortOfCoffee == 0)
                    {
                        coffeeMachine.TransitionToState(new ResultSelectionState("\nYou entered incorrect character! Please, try again.\n"));
                        coffeeMachine.DisplayState();
                        continue;
                    }
                    else if (!Program.IsSelectedSortOfCoffeeInList((SortsOfCoffee)selectedSortOfCoffee, (SortsOfCoffee[])Enum.GetValues(typeof(SortsOfCoffee))))
                    {
                        coffeeMachine.TransitionToState(new ResultSelectionState("\nYou entered not existing sort of coffee! Please, try again.\n"));
                        coffeeMachine.DisplayState();
                        continue;
                    }
                    else if (!Program.IsSelectedSortOfCoffeeInList((SortsOfCoffee)selectedSortOfCoffee, (SortsOfCoffee[])coffeeMachine.GetNamesOfSortsThatIsAvailable().ToArray()))
                    {
                        coffeeMachine.TransitionToState(new ResultSelectionState("\nYour option isn't available now. Please, choose another option, or come later.\n"));
                        coffeeMachine.DisplayState();
                        continue;
                    }
                    else
                    {
                        coffeeMachine.TransitionToState(new ResultSelectionState("\nYou selected " + (SortsOfCoffee)selectedSortOfCoffee + " sort of coffee. It is available.\n"));
                        coffeeMachine.DisplayState();
                    }

                    foreach (CoffeeSort sort in coffeeMachine.SortsOfCoffeeIsAvailable)
                    {
                        if (sort.sortName == (SortsOfCoffee)selectedSortOfCoffee)
                        {
                            return(sort);
                        }
                    }
                }
            }
 public void SetCoffeeMachine(CoffeeMachine coffeeMachine)
 {
     this.coffeeMachine = coffeeMachine;
 }
Esempio n. 4
0
 private static void Run(CoffeeMachine coffeeMachine, User user)
 {
     CoffeeSort selectedSortOfCoffee = Program.SelectionCoffee(coffeeMachine, user);
 }