Beispiel #1
0
        // Выдаем два шарика
        public void Dispense()
        {
            gumballMachine.ReleaseBall();

            if (gumballMachine.GetCount() == 0)
            {
                gumballMachine.SetState(gumballMachine.GetSoldOutState());
            }
            // Если в автомате есть второй шарик, освобождаем его
            else
            {
                Console.WriteLine("YOU'RE A WINNER! You got two gumballs for your quarter");
                gumballMachine.ReleaseBall();

                if (gumballMachine.GetCount() > 0)
                {
                    gumballMachine.SetState(gumballMachine.GetNoQuarterState());
                }
                else
                {
                    Console.WriteLine("Oops, out of gumballs!");
                    gumballMachine.SetState(gumballMachine.GetSoldOutState());
                }
            }
        }
        public void Dispense()
        {
            gumballMachine.ReleaseBall();

            if (gumballMachine.GetCount() > 0)
            {
                gumballMachine.SetState(gumballMachine.GetNoQuarterState());
            }
            else
            {
                Console.WriteLine("Oops, out of gumballs!");
                gumballMachine.SetState(gumballMachine.GetSoldOutState());
            }
        }
        public void TurnCrank()
        {
            Console.WriteLine("You turned...");
            //Добавляем генератор случайных чисел с 10%-й вероятностью выиграша...
            int randomWinner = random.Next(1, 11);

            // Проверяем повезло ли покупателю
            if ((randomWinner == 1) && (gumballMachine.GetCount() > 1))
            {
                gumballMachine.SetState(gumballMachine.GetWinnerState());
            }
            else
            {
                gumballMachine.SetState(gumballMachine.GetSoldState());
            }
        }