diff options
author | marcinzelent <marcin@zelent.net> | 2021-02-21 14:13:49 +0100 |
---|---|---|
committer | marcinzelent <marcin@zelent.net> | 2019-12-20 14:21:37 +0100 |
commit | b1eb36d3fbc5012b07489454a7452e8488507f6a (patch) | |
tree | f6a9e6e561eabde5b06366a6aeac78df123ca917 /Views |
Diffstat (limited to 'Views')
-rw-r--r-- | Views/CheckOrdersView.cs | 50 | ||||
-rw-r--r-- | Views/MainView.cs | 68 | ||||
-rw-r--r-- | Views/OrderPizzaStep1View.cs | 61 | ||||
-rw-r--r-- | Views/OrderPizzaStep2View.cs | 67 | ||||
-rw-r--r-- | Views/OrderPizzaStep3View.cs | 58 | ||||
-rw-r--r-- | Views/OrderPizzaStep4View.cs | 82 | ||||
-rw-r--r-- | Views/View.cs | 24 |
7 files changed, 410 insertions, 0 deletions
diff --git a/Views/CheckOrdersView.cs b/Views/CheckOrdersView.cs new file mode 100644 index 0000000..bedf38f --- /dev/null +++ b/Views/CheckOrdersView.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using KukaPizza.Controllers; +using KukaPizza.Models; + +namespace KukaPizza.Views +{ + public class CheckOrdersView : View + { + private CheckOrdersController _controller; + private List<PizzaOrder> orders; + public CheckOrdersView(CheckOrdersController controller) + { + _controller = controller; + orders = controller.Orders; + Init(_controller); + } + + protected override void Draw() + { + Console.Clear(); + Console.Write( +@"================================================================================ + Your orders +================================================================================ +"); + foreach (var o in orders) + { + Console.WriteLine($" Base pizza: {o.BasePizza.Name}"); + Console.WriteLine($" Extra toppings: {o.ExtraToppingsToString()}"); + Console.WriteLine($" Size: {o.Size}"); + Console.Write("--------------------------------------------------------------------------------"); + } + + Console.WriteLine("\n 0. Go back"); + } + + protected override void Interact() + { + int choice = 0; + + do + { + choice = Console.ReadKey(true).KeyChar; + + Draw(); + } while (choice != '0'); + } + } +}
\ No newline at end of file diff --git a/Views/MainView.cs b/Views/MainView.cs new file mode 100644 index 0000000..42f7c91 --- /dev/null +++ b/Views/MainView.cs @@ -0,0 +1,68 @@ +using System; +using KukaPizza.Controllers; + +namespace KukaPizza.Views +{ + public class MainView : View + { + private MainController _controller; + public MainView(MainController controller) + { + _controller = controller; + Init(_controller); + + } + protected override void Draw() + { + Console.Write(@" + + + + __ __ __ ____ +/\ \/\ \ /\ \ /\ _`\ __ +\ \ \/'/' __ __\ \ \/'\ __ \ \ \L\ \/\_\ ____ ____ __ + \ \ , < /\ \/\ \\ \ , < /'__`\ \ \ ,__/\/\ \/\_ ,`\ /\_ ,`\ /'__`\ + \ \ \\`\\ \ \_\ \\ \ \\`\ /\ \L\.\_ \ \ \/ \ \ \/_/ /_\/_/ /_/\ \L\.\_ + \ \_\ \_\ \____/ \ \_\ \_\ \__/.\_\ \ \_\ \ \_\/\____\ /\____\ \__/.\_\ + \/_/\/_/\/___/ \/_/\/_/\/__/\/_/ \/_/ \/_/\/____/ \/____/\/__/\/_/ + + + + + 1. Order a pizza + 2. Check orders + + 0. Exit + + + +================================================================================ + Copyright © 2019 Marcin Zelent & Paulius Klezys +================================================================================"); + } + + protected override void Interact() + { + int choice = 0; + + do + { + choice = Console.ReadKey(true).KeyChar; + + switch (choice) + { + case '1': + _controller.OpenOrderPizza(); + break; + case '2': + _controller.OpenCheckOrders(); + break; + } + + Draw(); + } while (choice != '0'); + + if (choice == '0') _controller.Close(); + } + } +}
\ No newline at end of file diff --git a/Views/OrderPizzaStep1View.cs b/Views/OrderPizzaStep1View.cs new file mode 100644 index 0000000..d596fee --- /dev/null +++ b/Views/OrderPizzaStep1View.cs @@ -0,0 +1,61 @@ +using System; +using KukaPizza.Controllers; +using KukaPizza.Models; + +namespace KukaPizza.Views +{ + public class OrderPizzaStep1View : View + { + private static OrderPizzaController _controller; + private Pizza[] pizzas; + + public OrderPizzaStep1View(OrderPizzaController controller) + { + _controller = controller; + pizzas = controller.Pizzas; + Init(_controller); + } + + protected override void Draw() + { + Console.Clear(); + Console.Write( +@"================================================================================ + Step 1. Choose base pizza +================================================================================ + +"); + + for (int i = 0; i < pizzas.Length; i++) + { + Console.WriteLine($" {i + 1}. {pizzas[i].Name} ({pizzas[i].ToppingsToString()}) - {pizzas[i].Price}"); + } + + Console.WriteLine("\n 0. Go back"); + Console.Write($"\nChoose number [0-{pizzas.Length}]: "); + } + + protected override void Interact() + { + string choice = ""; + + do + { + Console.CursorVisible = true; + choice = Console.ReadLine(); + Console.CursorVisible = false; + + if (choice == "") choice = "-1"; + + int choiceInt = Int32.Parse(choice); + if (choiceInt > 0 && choiceInt < pizzas.Length + 1) + { + _controller.ChooseBasePizza(choiceInt - 1); + NavigateTo(typeof(OrderPizzaStep2View)); + } + + Draw(); + } while (choice != "0"); + } + } +}
\ No newline at end of file diff --git a/Views/OrderPizzaStep2View.cs b/Views/OrderPizzaStep2View.cs new file mode 100644 index 0000000..b8abcc7 --- /dev/null +++ b/Views/OrderPizzaStep2View.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using KukaPizza.Controllers; +using KukaPizza.Models; + +namespace KukaPizza.Views +{ + public class OrderPizzaStep2View : View + { + private static OrderPizzaController _controller; + private Topping[] toppings; + private List<int> selectedToppings; + public OrderPizzaStep2View(OrderPizzaController controller) + { + _controller = controller; + toppings = _controller.Toppings; + selectedToppings = _controller.SelectedToppings; + Init(_controller); + } + + + protected override void Draw() + { + Console.Clear(); + Console.Write( +@"================================================================================ + Step 2. Add extra toppings +================================================================================ + +"); + + for (int i = 0; i < toppings.Length; i++) + { + Console.WriteLine($" [{(selectedToppings.Contains(i + 1) ? 'x' : ' ')}] {i + 1}. {toppings[i].Name} - {toppings[i].Price}"); + } + + Console.WriteLine($"\n {toppings.Length + 1}. Done\n 0. Go back"); + Console.Write($"\nChoose number [0-{toppings.Length + 1}]: "); + } + + protected override void Interact() + { + string choice = ""; + + do + { + Console.CursorVisible = true; + choice = Console.ReadLine(); + Console.CursorVisible = false; + + if (choice == "") choice = "-1"; + + int choiceInt = Int32.Parse(choice); + + if (choiceInt != 0 && choiceInt != toppings.Length + 1) + _controller.SelectTopping(choiceInt); + else if (choiceInt == toppings.Length + 1) + { + _controller.AddExtraToppings(); + NavigateTo(typeof(OrderPizzaStep3View)); + } + + Draw(); + } while (choice != "0"); + } + } +}
\ No newline at end of file diff --git a/Views/OrderPizzaStep3View.cs b/Views/OrderPizzaStep3View.cs new file mode 100644 index 0000000..6fbfebc --- /dev/null +++ b/Views/OrderPizzaStep3View.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using KukaPizza.Controllers; +using KukaPizza.Models; + +namespace KukaPizza.Views +{ + public class OrderPizzaStep3View : View + { + private OrderPizzaController _controller; + + public OrderPizzaStep3View(OrderPizzaController controller) + { + _controller = controller; + Init(_controller); + } + + protected override void Draw() + { + Console.Clear(); + Console.Write( +@"================================================================================ + Step 3. Choose pizza size +================================================================================ + + 1. Small + 2. Medium + 3. Large + +"); + Console.WriteLine($" 0. Go back"); + Console.Write($"\nChoose number [0-3]: "); + } + + protected override void Interact() + { + string choice = ""; + + do + { + Console.CursorVisible = true; + choice = Console.ReadLine(); + Console.CursorVisible = false; + + if (choice == "") choice = "-1"; + + int choiceInt = Int32.Parse(choice); + if (choiceInt > 0 && choiceInt < 4) + { + _controller.ChooseSize(choiceInt); + NavigateTo(typeof(OrderPizzaStep4View)); + } + + Draw(); + } while (choice != "0"); + } + } +}
\ No newline at end of file diff --git a/Views/OrderPizzaStep4View.cs b/Views/OrderPizzaStep4View.cs new file mode 100644 index 0000000..b027e7e --- /dev/null +++ b/Views/OrderPizzaStep4View.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using KukaPizza.Controllers; +using KukaPizza.Models; + +namespace KukaPizza.Views +{ + public class OrderPizzaStep4View : View + { + private OrderPizzaController _controller; + private PizzaOrder order; + + public OrderPizzaStep4View(OrderPizzaController controller) + { + _controller = controller; + order = _controller.Order; + Init(_controller); + } + protected override void Draw() + { + Console.Clear(); + Console.Write( +@"================================================================================ + Step 4. Confirm order +================================================================================ + +"); + Console.WriteLine($" Base pizza: {order.BasePizza.Name}"); + Console.WriteLine($" Extra toppings: {order.ExtraToppingsToString()}"); + Console.WriteLine($" Size: {order.Size}"); + Console.WriteLine($" Price: {order.GetPrice()}"); + + Console.Write( +@" + Do you want to place this order? + 1. Yes, pay with Visa card + 2. Yes, pay with Mastercard card + 3. No, go back +"); + Console.Write($"\nChoose number [1-3]: "); + } + + protected override void Interact() + { + string choice = ""; + + do + { + Console.CursorVisible = true; + choice = Console.ReadLine(); + Console.CursorVisible = false; + + if (choice == "1") + { + _controller.MakePaymentWithVisa(); + } + else if (choice == "2") + { + _controller.MakePaymentWithMastercard(); + } + else if (choice == "3") + { + _controller.CancelOrder(); + Console.WriteLine("\nOrder canceled."); + } + + if (choice == "1" || choice == "2") + { + _controller.ConfirmOrder(); + Console.WriteLine("\nOrder successfully placed."); + } + + Console.WriteLine("Press any key to return to the main screen..."); + Console.ReadKey(); + _controller.GoBackToMainView(); + + + Draw(); + } while (choice != "3"); + } + } +}
\ No newline at end of file diff --git a/Views/View.cs b/Views/View.cs new file mode 100644 index 0000000..5db14c9 --- /dev/null +++ b/Views/View.cs @@ -0,0 +1,24 @@ +using System; +using KukaPizza.Controllers; + +namespace KukaPizza.Views +{ + public abstract class View + { + private Controller _controller; + public void Init(Controller controller) + { + _controller = controller; + Draw(); + Interact(); + } + + protected abstract void Draw(); + protected abstract void Interact(); + + public void NavigateTo(Type view) + { + Activator.CreateInstance(view, _controller); + } + } +}
\ No newline at end of file |