This repository has been archived on 2022-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
patterns/state/gumballmachinestate/soldstate.d

50 lines
1.0 KiB
D

module soldstate;
import std.stdio : writeln;
import state, gumballmachine;
class SoldState : State
{
GumballMachine gumballMachine;
this(GumballMachine gumballMachine)
{
this.gumballMachine = gumballMachine;
}
void insertQuarter()
{
writeln("Please wait, we're already giving you a gumball");
}
void ejectQuarter()
{
writeln("Sorry, you already turned the crank");
}
void turnCrank()
{
writeln("Turning twice doesn't get you another gumball!");
}
void dispense()
{
gumballMachine.releaseBall();
if (gumballMachine.getCount() > 0)
{
gumballMachine.setState(gumballMachine.getNoQuarterState());
}
else
{
writeln("Oops, out of gumballs!");
gumballMachine.setState(gumballMachine.getSoldOutState());
}
}
void refill() {}
override string toString() const
{
return "dispensing a gumball";
}
}