コード例 #1
0
    void dispense() {
        std::cout << "YOU'RE A WINNER! You get two gumballs for your quarter" << std::endl;
        _gumballMachine->releaseBall();

        if (_gumballMachine->getCount() == 0) {
            _gumballMachine->setState(_gumballMachine->getSoldOutState());
        } else {
            _gumballMachine->releaseBall();

            if (_gumballMachine->getCount() > 0) {
                _gumballMachine->setState(_gumballMachine->getNoQuarterState());
            } else {
                std::cout << "Oops, out of gumballs!" << std::endl;
                _gumballMachine->setState(_gumballMachine->getSoldOutState());
            }
        }
    }
コード例 #2
0
 virtual void turnCrank() {
     std::cout << "You turned..." << std::endl;
     int winner = rand() % 5;	// randomWinner->nextInt(10);
     if ((winner == 0) && (gumballMachine->getCount() > 1)) {
         gumballMachine->setState(gumballMachine->getWinnerState());
     } else {
         gumballMachine->setState(gumballMachine->getSoldState());
     }
 }