Exemple #1
0
 public void Dispense()
 {
     Console.WriteLine("You are a winner! You get two gumballs for your quarter");
     _machine.ReleaseBall();
     if (_machine.GetCount() == 0)
     {
         _machine.SetState(_machine.GetSoldOutState());
     }
     else
     {
         _machine.ReleaseBall();
         if (_machine.GetCount() > 0)
         {
             _machine.SetState(_machine.GetNoQuarterState());
         }
         else
         {
             Console.WriteLine("Oops, out of gumballs!");
             _machine.SetState(_machine.GetSoldOutState());
         }
     }
 }
 public void TurnCrank()
 {
     _machine.ReleaseBall();
     if (_machine.GetCount() > 0)
     {
         _machine.SetState(_machine.GetNoQuarterState());
     }
     else
     {
         Console.WriteLine("Oops, out of gumballs!");
         _machine.SetState(_machine.GetSoldOutState());
     }
 }
Exemple #3
0
        public void TurnCrank()
        {
            Console.WriteLine("You turned...");
            int winner = randomWinner.Next(1, 11);

            if (winner < 6 && _machine.GetCount() > 1)
            {
                _machine.SetState(_machine.GetWinnerState());
            }
            else
            {
                this._machine.SetState(_machine.GetSoldState());
            }
        }
        public string Print()
        {
            string output = string.Format("Machine State:{0},Inventory:{1}", this.ToString(), _machine.GetCount());

            return(output);
        }