diff --git a/TheMiddleman/BusinessLogic/ProductService.cs b/TheMiddleman/BusinessLogic/ProductService.cs index 97f099f..a2e874a 100644 --- a/TheMiddleman/BusinessLogic/ProductService.cs +++ b/TheMiddleman/BusinessLogic/ProductService.cs @@ -15,8 +15,9 @@ public void CalculateProductAvailability() { foreach (Product product in productRepository.GetAllProducts()) { + product.AvailableQuantity = 0; int maxAvailability = product.MaxProductionRate * product.Durability; - double weight = 0.8; + double weight = 0.1; int productionToday = (int)((weight * product.MaxProductionRate) + ((1 - weight) * random.Next(product.MinProductionRate, product.MaxProductionRate + 1))); product.AvailableQuantity += productionToday; product.AvailableQuantity = Math.Max(0, product.AvailableQuantity); @@ -28,4 +29,9 @@ public List GetAllProducts() { return productRepository.GetAllProducts(); } + + /* public Product getProductById(int id) + { + return productRepository.getProductById(id); + } */ } diff --git a/TheMiddleman/DataAccess/ProductRepository.cs b/TheMiddleman/DataAccess/ProductRepository.cs index bef66ef..ae34cf2 100644 --- a/TheMiddleman/DataAccess/ProductRepository.cs +++ b/TheMiddleman/DataAccess/ProductRepository.cs @@ -1,3 +1,6 @@ + +using System.Runtime.Serialization; + namespace TheMiddleman.DataAccess { public class ProductRepository : IProductRepository @@ -85,5 +88,15 @@ public List GetAllProducts() { return _products; } + + /* public Product getProductById(int id) + { + var product = _products?.Find(p => p.Id == id); + if (product == null) + { + throw new ProductNotFoundException($"Produkt mit ID {id} nicht gefunden."); + } + return product; + } */ } } diff --git a/TheMiddleman/UserInterface/ConsoleUI.cs b/TheMiddleman/UserInterface/ConsoleUI.cs index b445b71..8b6e071 100644 --- a/TheMiddleman/UserInterface/ConsoleUI.cs +++ b/TheMiddleman/UserInterface/ConsoleUI.cs @@ -80,23 +80,18 @@ private void DisplayMiddlemanInfo(Middleman middleman, int currentDay) char topRightCorner = '\u2557'; // '╗' Double down and left char bottomLeftCorner = '\u255A'; // '╚' Double up and right char bottomRightCorner = '\u255D'; // '╝' Double up and left - // Creating borders with the extended characters string topBorder = topLeftCorner + new string(horizontalLine, 42) + topRightCorner; string bottomBorder = bottomLeftCorner + new string(horizontalLine, 42) + bottomRightCorner; - Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(topBorder); Console.ResetColor(); - Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"{verticalLine} {middleman.Name} von {middleman.Company}".PadRight(43) + verticalLine); Console.ResetColor(); - Console.WriteLine($"{verticalLine} Kontostand: ${middleman.AccountBalance}".PadRight(43) + verticalLine); Console.WriteLine($"{verticalLine} Lagerkapazität: {middleman.Warehouse.Values.Sum()}/{Middleman.MaxStorageCapacity}".PadRight(43) + verticalLine); Console.WriteLine($"{verticalLine} Tag: {currentDay}".PadRight(43) + verticalLine); - Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(bottomBorder); Console.ResetColor(); @@ -165,24 +160,40 @@ private void ShowShoppingMenu(Middleman middleman) string? userChoice = Console.ReadLine(); if (userChoice == "z") { + Console.Clear(); return; } SelectProductAndPurchase(middleman, userChoice, _marketService.getProductService().GetAllProducts()); + ShowShoppingMenu(middleman); } private void ShowSellingMenu(Middleman middleman) { + Console.Clear(); + Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Produkte im Besitz:"); + string header = "| ID | Name | Menge | Verkaufspreis |"; + string divider = "|------|---------------------|------------------|------------------|"; + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine(header); + Console.WriteLine(divider); + Console.ResetColor(); int index = 1; foreach (var entry in middleman.Warehouse) { - Console.WriteLine($"{index}) {entry.Key.Name} ({entry.Value}) ${entry.Key.SellingPrice}/Stück"); + string id = index.ToString().PadRight(4); + string name = entry.Key.Name.PadRight(19); + string quantity = entry.Value.ToString().PadRight(16); + string sellingPrice = $"${entry.Key.SellingPrice}/Stück".PadRight(16); + Console.WriteLine($"| {id} | {name} | {quantity} | {sellingPrice} |"); index++; } + Console.ResetColor(); Console.WriteLine("z) Zurück"); string userChoice = Console.ReadLine() ?? ""; if (userChoice == "z") { + Console.Clear(); return; } SelectProductAndSell(middleman, userChoice); @@ -195,20 +206,26 @@ private void SelectProductAndPurchase(Middleman middleman, string? userChoice, L { return; } - Product? selectedProduct = products.Find(p => p.Id == selectedProductId); - if (selectedProduct == null) { return; } else { + if (selectedProduct.AvailableQuantity == 0) + { + Console.Clear(); + Console.WriteLine("Dieses Produkt ist nicht mehr verfügbar. Bitte erneut versuchen.\n"); + ShowShoppingMenu(middleman); + } Console.WriteLine($"Wieviel von {selectedProduct.Name} kaufen?"); int quantity = int.Parse(Console.ReadLine() ?? ""); if (quantity <= 0) { - return; + Console.Clear(); + Console.WriteLine("Beim letzten Kauf wurde eine ungültige Menge eingegeben. Bitte erneut versuchen.\n"); + ShowShoppingMenu(middleman); } else { @@ -227,8 +244,9 @@ private void SelectProductAndSell(Middleman middleman, string userChoice) int quantityToSell = int.Parse(Console.ReadLine() ?? "0"); if (quantityToSell <= 0 || quantityToSell > availableQuantity) { - Console.WriteLine("Ungültige Menge."); - return; + Console.Clear(); + Console.WriteLine("Beim letzten Verkauf wurde eine ungültige Menge eingegeben. Bitte erneut versuchen.\n"); + ShowSellingMenu(middleman); } _marketService.getMiddlemanService().ProcessSale(middleman, selectedProduct, quantityToSell); Console.WriteLine($"Verkauf erfolgreich. Neuer Kontostand: ${middleman.AccountBalance}"); diff --git a/TheMiddleman/bin/Debug/net7.0/TheMiddleman.dll b/TheMiddleman/bin/Debug/net7.0/TheMiddleman.dll index 824c15e..0726195 100644 Binary files a/TheMiddleman/bin/Debug/net7.0/TheMiddleman.dll and b/TheMiddleman/bin/Debug/net7.0/TheMiddleman.dll differ diff --git a/TheMiddleman/bin/Debug/net7.0/TheMiddleman.pdb b/TheMiddleman/bin/Debug/net7.0/TheMiddleman.pdb index 20baafc..6efe56d 100644 Binary files a/TheMiddleman/bin/Debug/net7.0/TheMiddleman.pdb and b/TheMiddleman/bin/Debug/net7.0/TheMiddleman.pdb differ diff --git a/TheMiddleman/obj/Debug/net7.0/TheMiddleman.dll b/TheMiddleman/obj/Debug/net7.0/TheMiddleman.dll index 824c15e..0726195 100644 Binary files a/TheMiddleman/obj/Debug/net7.0/TheMiddleman.dll and b/TheMiddleman/obj/Debug/net7.0/TheMiddleman.dll differ diff --git a/TheMiddleman/obj/Debug/net7.0/TheMiddleman.pdb b/TheMiddleman/obj/Debug/net7.0/TheMiddleman.pdb index 20baafc..6efe56d 100644 Binary files a/TheMiddleman/obj/Debug/net7.0/TheMiddleman.pdb and b/TheMiddleman/obj/Debug/net7.0/TheMiddleman.pdb differ diff --git a/TheMiddleman/produkte.yml b/TheMiddleman/produkte.yml index f30a8b9..9405c4c 100644 --- a/TheMiddleman/produkte.yml +++ b/TheMiddleman/produkte.yml @@ -1,131 +1,131 @@ - name: Gurke durability: 21 baseprice: 5 - minProductionRate: 100 - maxProductionRate: 500 + minProductionRate: -100 + maxProductionRate: 400 - name: Aprikose durability: 4 baseprice: 20 - minProductionRate: 50 - maxProductionRate: 200 + minProductionRate: -50 + maxProductionRate: 400 - name: Tomate durability: 10 baseprice: 7 - minProductionRate: 150 - maxProductionRate: 700 + minProductionRate: -150 + maxProductionRate: 400 - name: Kartoffel durability: 30 baseprice: 3 - minProductionRate: 200 - maxProductionRate: 900 + minProductionRate: -200 + maxProductionRate: 400 - name: Zwiebel durability: 40 baseprice: 2 - minProductionRate: 300 - maxProductionRate: 1000 + minProductionRate: -300 + maxProductionRate: 400 - name: Karotte durability: 20 baseprice: 4 - minProductionRate: 200 - maxProductionRate: 800 + minProductionRate: -200 + maxProductionRate: 400 - name: Apfel durability: 14 baseprice: 6 - minProductionRate: 250 - maxProductionRate: 1000 + minProductionRate: -250 + maxProductionRate: 400 - name: Banane durability: 7 baseprice: 10 - minProductionRate: 100 - maxProductionRate: 500 + minProductionRate: -100 + maxProductionRate: 400 - name: Orangensaft durability: 5 baseprice: 12 - minProductionRate: 300 - maxProductionRate: 1500 + minProductionRate: -300 + maxProductionRate: 400 - name: Milch durability: 3 baseprice: 8 - minProductionRate: 500 - maxProductionRate: 3000 + minProductionRate: -500 + maxProductionRate: 400 - name: Käse durability: 25 baseprice: 15 - minProductionRate: 100 - maxProductionRate: 500 + minProductionRate: -100 + maxProductionRate: 400 - name: Schokolade durability: 180 baseprice: 20 - minProductionRate: 50 - maxProductionRate: 300 + minProductionRate: -50 + maxProductionRate: 400 - name: Brot durability: 5 baseprice: 5 - minProductionRate: 200 - maxProductionRate: 1000 + minProductionRate: -200 + maxProductionRate: 400 - name: Wasser durability: 365 baseprice: 1 - minProductionRate: 1000 - maxProductionRate: 5000 + minProductionRate: -1000 + maxProductionRate: 400 - name: Ei durability: 21 baseprice: 3 - minProductionRate: 500 - maxProductionRate: 2500 + minProductionRate: -500 + maxProductionRate: 400 - name: Hähnchenbrust durability: 4 baseprice: 10 - minProductionRate: 100 - maxProductionRate: 600 + minProductionRate: -100 + maxProductionRate: 400 - name: Tofu durability: 10 baseprice: 12 - minProductionRate: 150 - maxProductionRate: 700 + minProductionRate: -150 + maxProductionRate: 400 - name: Lachs durability: 3 baseprice: 25 - minProductionRate: 50 - maxProductionRate: 250 + minProductionRate: -50 + maxProductionRate: 400 - name: Erdbeeren durability: 7 baseprice: 15 - minProductionRate: 150 - maxProductionRate: 700 + minProductionRate: -150 + maxProductionRate: 400 - name: Salat durability: 7 baseprice: 6 - minProductionRate: 200 - maxProductionRate: 900 + minProductionRate: -200 + maxProductionRate: 400 - name: Joghurt durability: 14 baseprice: 8 - minProductionRate: 200 - maxProductionRate: 1200 + minProductionRate: -200 + maxProductionRate: 400 - name: Olivenöl durability: 365 baseprice: 30 - minProductionRate: 100 - maxProductionRate: 500 + minProductionRate: -100 + maxProductionRate: 400