Exemplo n.º 1
0
        public void Dispense()
        {
            if (_gumballMachine.Count > 0)
            {
                _gumballMachine.ReleaseBall();
            }

            if (_gumballMachine.Count > 0)
            {
                _gumballMachine.CurrentState = new NoQuarterState(_gumballMachine).GetCurrentState();
            }
            else
            {
                _gumballMachine.CurrentState = new SoldOutState(_gumballMachine).GetCurrentState();
            }
        }
        public void Dispense()
        {
            int winner = new Random().Next(0, 10);

            if (_gumballMachine.Count > 0)
            {
                _gumballMachine.ReleaseBall();
                if (winner < 1)
                {
                    _gumballMachine.CurrentState = new WinnerState(_gumballMachine).GetCurrentState();
                }
                else
                {
                    _gumballMachine.CurrentState = new NoQuarterState(_gumballMachine).GetCurrentState();
                }
            }
            else
            {
                _gumballMachine.CurrentState = new HasQuarterState(_gumballMachine).GetCurrentState();
            }
        }