예제 #1
0
 public void Dispense()
 {
     gumballMachine.ReleaseBall();
     if (gumballMachine.GetCount() > 0)
     {
         gumballMachine.SetState(gumballMachine.GetNoQuarterState());
     }
     else
     {
         Console.WriteLine("Oops, out of gumballs.");
         gumballMachine.SetState(gumballMachine.GetSoldOutState());
     }
 }
예제 #2
0
 public void Dispense()
 {
     gumballMachine.ReleaseBall();
     if (gumballMachine.GetCount() > 0)
     {
         gumballMachine.SetState(gumballMachine.GetSoldOutState());
     }
     else
     {
         gumballMachine.ReleaseBall();
         Console.WriteLine("YOU'RE A WINNER! You got two gumballs for your quarter.");
         if (gumballMachine.GetCount() > 0)
         {
             gumballMachine.SetState(gumballMachine.GetNoQuarterState());
         }
         else
         {
             Console.WriteLine("Oops, out of gumballs.");
             gumballMachine.SetState(gumballMachine.GetSoldOutState());
         }
     }
 }
예제 #3
0
        public void TurnCrank()
        {
            Console.WriteLine("You turned....");
            var winner = randomWinner.Next(0, 10);

            if (winner == 2 && gumballMachine.GetCount() > 1)
            {
                gumballMachine.SetState(gumballMachine.GetWinnerState());
            }
            else
            {
                gumballMachine.SetState(gumballMachine.GetSoldState());
            }
        }