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/hasquarterstate.d

43 lines
817 B
D
Raw Normal View History

2022-11-19 23:40:58 +00:00
module hasquarterstate;
import std.stdio : writeln;
import state, gumballmachine;
class HasQuarterState : State
{
GumballMachine gumballMachine;
this(GumballMachine gumballMachine)
{
this.gumballMachine = gumballMachine;
}
void insertQuarter()
{
writeln("You can't insert another quarter");
}
void ejectQuarter()
{
writeln("Quarter returned");
gumballMachine.setState(gumballMachine.getNoQuarterState());
}
void turnCrank()
{
writeln("You turned...");
gumballMachine.setState(gumballMachine.getSoldState());
}
void dispense()
{
writeln("No gumball dispensed");
}
void refill() {}
override string toString() const
{
return "waiting for turn of crank";
}
}