53 lines
1.3 KiB
D
53 lines
1.3 KiB
D
|
module hasquarterstate;
|
||
|
|
||
|
import std.stdio : writeln;
|
||
|
import std.random : Random, uniform, unpredictableSeed;
|
||
|
import state, gumballmachine;
|
||
|
|
||
|
class HasQuarterState : State
|
||
|
{
|
||
|
GumballMachine gumballMachine;
|
||
|
Random randomWinner;
|
||
|
|
||
|
this(GumballMachine gumballMachine)
|
||
|
{
|
||
|
this.gumballMachine = gumballMachine;
|
||
|
randomWinner = Random(unpredictableSeed);
|
||
|
}
|
||
|
|
||
|
void insertQuarter()
|
||
|
{
|
||
|
writeln("Вы не можете вставить еще один четвертак");
|
||
|
}
|
||
|
|
||
|
void ejectQuarter()
|
||
|
{
|
||
|
writeln("Четвертак возвращен");
|
||
|
gumballMachine.setState(gumballMachine.getNoQuarterState());
|
||
|
}
|
||
|
|
||
|
void turnCrank()
|
||
|
{
|
||
|
writeln("Вы дернули за рычаг...");
|
||
|
if ((uniform(0, 10, randomWinner) == 0) && (gumballMachine.getCount() > 1))
|
||
|
{
|
||
|
gumballMachine.setState(gumballMachine.getWinnerState());
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
gumballMachine.setState(gumballMachine.getSoldState());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void dispense()
|
||
|
{
|
||
|
writeln("Жевательная резинка не выдается");
|
||
|
}
|
||
|
|
||
|
void refill() {}
|
||
|
|
||
|
override string toString() const
|
||
|
{
|
||
|
return "ожидание поворота рычага";
|
||
|
}
|
||
|
}
|