public int GiveChange(CopyContext copyContext) { int i = Balance; Balance = 0; copyContext.state = new PayState(); return(i); }
public override void Pay(CopyContext copyContext, int amount) { if (amount <= 0) { return; } Console.WriteLine($"Баланс: {amount}"); copyContext.state = new ChooseDeviceState(amount); }
public override void ChooseDevice(CopyContext copyContext, string device) { if (device.Equals(DEVICE_USB)) { copyContext.state = new ChooseDocFromUSBState(Balance); return; } if (device.Equals(DEVICE_WIFI)) { copyContext.state = new ChooseDocFromWiFiState(Balance); return; } throw new Exception("Invalid device"); }
public override void PrintDoc(CopyContext copyContext) { Console.WriteLine($"Печатаем с {DeviceType}, документ с именем {DocumentName}"); Balance -= copyContext.price; if (Balance < copyContext.price) { Console.WriteLine($"Осталось денег: {Balance}, внесите ещё"); copyContext.state = new PayState(Balance); } else { Console.WriteLine($"Осталось денег: {Balance}"); ReturnOneStateBack(copyContext); } }
static void Main(string[] args) { CopyContext copyContext = new CopyContext(); try { copyContext.Pay(10); copyContext.ChooseDevice(ChooseDeviceState.DEVICE_WIFI); copyContext.ChooseDoc("Hello.doc"); copyContext.PrintDoc(); } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadLine(); }
public override void ChooseDevice(CopyContext copyContext, string device) { throw new Exception("Pay first!"); }
protected override void ReturnOneStateBack(CopyContext copyContext) { copyContext.state = new ChooseDocFromWiFiState(Balance); }
public override void ChooseDoc(CopyContext copyContext, string name) { throw new Exception("Choose device first!"); }
public override void PrintDoc(CopyContext copyContext) { throw new Exception("Pay first!"); }
public abstract void ChooseDoc(CopyContext copyContext, string name);
public abstract void PrintDoc(CopyContext copyContext);
public abstract void Pay(CopyContext copyContext, int amount);
public abstract void ChooseDevice(CopyContext copyContext, string device);
public override void PrintDoc(CopyContext copyContext) { throw new Exception("Choose device first!"); }
protected abstract void ReturnOneStateBack(CopyContext copyContext);
public override void Pay(CopyContext copyContext, int amount) { throw new Exception("You already paid!"); }
public override void ChooseDoc(CopyContext copyContext, string name) { copyContext.state = new PrintDocFromWiFiState(Balance, name); }
public override void ChooseDoc(CopyContext copyContext, string name) { throw new Exception("You already chose!"); }