static void Main(string[] args) { do { management.ActivateSession(); Console.WriteLine("****Vending Machine****"); Console.WriteLine("Money inserted:\t" + management.GetMoney() + " kr"); printOptions(); switch (Console.ReadKey(true).KeyChar) { case '1': management.InsertMoney(GetDepositSelection()); break; case '2': Product prod = management.PurchaseProduct(); if (prod != null) { prod.Use(); } break; case '3': Console.WriteLine("You got " + management.ReturnChange() + " kr back"); break; case '4': management.DeactivateSession(); break; } } while (management.SessionRunning()); }
public bool KeyHandler() { var key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.B: if (Machine.MoneyPool < Product.Price) { Console.WriteLine("Insert more money to purchase this item."); Console.WriteLine("Do you want to insert money now? (y/n)"); ConsoleKeyInfo cki; do { cki = Console.ReadKey(true); }while(!(cki.Key == ConsoleKey.N || cki.Key == ConsoleKey.Y)); switch (cki.Key) { case ConsoleKey.N: this.Machine.CurrentMenu = Machine.MainMenu; break; case ConsoleKey.Y: this.Machine.CurrentMenu = Machine.MoneyMenu; break; } } else if (Amount == 0) { Console.WriteLine("There are none of this item left in the machine."); Console.ReadKey(); this.Machine.CurrentMenu = Machine.MainMenu; } else { Machine.MoneyPool -= Product.Price; Machine.Products[Product] -= 1; Amount -= 1; this.Render(); Console.WriteLine("Because you are filled with instiable need to use the product, you use it right away!"); Product.Use(); Console.ReadKey(); } break; case ConsoleKey.Escape: case ConsoleKey.X: Machine.CurrentMenu = Machine.MainMenu; break; } return(true); }
public bool KeyHandler() { var key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.B: if (Machine.MoneyPool < Product.Price) { Console.WriteLine("Saldo lågt, lägg in mer pengar."); Console.WriteLine("Vill du fylla på ditt saldo? (y/n)"); ConsoleKeyInfo cki; do { cki = Console.ReadKey(true); }while(!(cki.Key == ConsoleKey.N || cki.Key == ConsoleKey.Y)); switch (cki.Key) { case ConsoleKey.N: this.Machine.CurrentMenu = Machine.MainMenu; break; case ConsoleKey.Y: this.Machine.CurrentMenu = Machine.MoneyMenu; break; } } else if (Amount == 0) { Console.WriteLine("Tyvär är denna produkt s**t."); Console.ReadKey(); this.Machine.CurrentMenu = Machine.MainMenu; } else { Machine.MoneyPool -= Product.Price; Machine.Products[Product] -= 1; Amount -= 1; this.Render(); Console.WriteLine("Suget är för stort för att stå imot så du intog produkten direkt!"); Product.Use(); Console.ReadKey(); } break; case ConsoleKey.Escape: case ConsoleKey.X: Machine.CurrentMenu = Machine.MainMenu; break; } return(true); }