Skip to content

Commit

Permalink
update whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfeo committed Nov 21, 2023
1 parent cf261da commit 2c4d306
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 74 deletions.
34 changes: 8 additions & 26 deletions TheMiddleman/BusinessLogic/MarketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,14 @@ public void RunSimulation()
_OnStartOfGame.Invoke();
while (_currentDay <= _simulationDuration && _middlemen.Count > 0)
{
ConsoleUI.PrintDayInFrame(_currentDay);
ConsoleUI.ShowCurrentDay(_currentDay);
SimulateDay();
}
}

public void SimulateDay()
{
if (_currentDay > 1)
{
_productService.UpdateProducts();
}
if (_currentDay > 1) { _productService.UpdateProducts(); }
foreach (var middleman in _middlemen)
{
_middlemanService.DeductStorageCosts(middleman);
Expand All @@ -71,40 +68,28 @@ public void SimulateDay()

public void InitiateSelling(Middleman middleman, string userInput)
{
if (!ValidateSelectedProductForSelling(userInput, middleman, out Product? selectedProduct))
{
return;
}
if (!ValidateSelectedProductForSelling(userInput, middleman, out Product? selectedProduct)) { return; }
if (selectedProduct == null)
{
ConsoleUI.ShowErrorLog("Es wurde kein Produkt ausgewählt.\n");
return;
}
string quantityInput = AskQuantity($"Wieviel von {selectedProduct.Name} verkaufen?");
if (!ValidateQuantityToSell(middleman, quantityInput, selectedProduct, out int quantityToSell))
{
return;
}
if (!ValidateQuantityToSell(middleman, quantityInput, selectedProduct, out int quantityToSell)) { return; }
_middlemanService.Sale(middleman, selectedProduct, quantityToSell);
ConsoleUI.ShowMessage($"Sie haben {quantityToSell}x {selectedProduct.Name} verkauft.");
}

public void InitiatePurchase(Middleman middleman, string userInput)
{
if (!ValidateSelectedProduct(userInput, out Product? selectedProduct))
{
return;
}
if (!ValidateSelectedProduct(userInput, out Product? selectedProduct)) { return; }
if (selectedProduct == null)
{
ConsoleUI.ShowErrorLog("Es wurde kein Produkt ausgewählt.\n");
return;
}
string quantityInput = AskQuantity($"Wieviel von {selectedProduct.Name} kaufen?");
if (!ValidateQuantityToBuy(quantityInput, selectedProduct, out int quantityToBuy))
{
return;
}
if (!ValidateQuantityToBuy(quantityInput, selectedProduct, out int quantityToBuy)) { return; }
_middlemanService.Purchase(middleman, selectedProduct, quantityToBuy, out string errorLog);
if (!string.IsNullOrEmpty(errorLog))
{
Expand Down Expand Up @@ -192,10 +177,7 @@ private string AskQuantity(string prompt)

private void CheckForEndOfSimulation()
{
if (_currentDay > _simulationDuration || _middlemen.Count == 0)
{
EndSimulation();
}
if (_currentDay > _simulationDuration || _middlemen.Count == 0) { EndSimulation(); }
}

private void EndSimulation()
Expand Down Expand Up @@ -227,4 +209,4 @@ public void SetSimulationDuration(int duration)
{
_simulationDuration = duration;
}
}
}
2 changes: 1 addition & 1 deletion TheMiddleman/BusinessLogic/MiddlemanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ public List<Product> GetOwnedProducts(Middleman middleman)
{
return _middlemanRepository.GetOwnedProducts(middleman);
}
}
}
2 changes: 1 addition & 1 deletion TheMiddleman/BusinessLogic/ProductService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ public List<Product> GetAllProducts()
return null;
}
}
}
}
4 changes: 2 additions & 2 deletions TheMiddleman/DataAccess/MiddlemanRespository.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using TheMiddleman.Entity;
namespace TheMiddleman.DataAccess

namespace TheMiddleman.DataAccess
{
public class MiddlemanRespository : IMiddlemanRespository
{
Expand Down Expand Up @@ -32,4 +32,4 @@ public List<Product> GetOwnedProducts(Middleman middleman)
return middleman.Warehouse.Keys.ToList();
}
}
}
}
75 changes: 49 additions & 26 deletions TheMiddleman/DataAccess/ProductRepository.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

using System.Runtime.Serialization;

namespace TheMiddleman.DataAccess
{
public class ProductRepository : IProductRepository
{
private readonly string _filePath;

private List<Product> _products = null!;

public ProductRepository()
Expand Down Expand Up @@ -44,49 +42,74 @@ public List<Product> CreateProducts()
{
if (line.StartsWith("- name: "))
{
string name = ReadProductName(line);
currentProduct = CreateProduct(idCounter++, name, 0);
currentProduct = ProcessProductName(line, ref idCounter);
}
else if (line.StartsWith(" durability: "))
{
if (currentProduct != null)
{
int durability = ReadProductDurability(line);
currentProduct.Durability = durability;
_products.Add(currentProduct);
}
ProcessProductDurability(line, currentProduct);
}
else if (line.StartsWith(" baseprice: "))
{
int basePrice = ReadProductBasePrice(line);
if (currentProduct != null)
{
currentProduct.BasePrice = basePrice;
}
ProcessProductBasePrice(line, currentProduct);
}
else if (line.StartsWith(" minProductionRate: "))
{
int minProductionRate = int.Parse(line.Substring(20));
if (currentProduct != null)
{
currentProduct.MinProductionRate = minProductionRate;
}
ProcessMinProductionRate(line, currentProduct);
}
else if (line.StartsWith(" maxProductionRate: "))
{
int maxProductionRate = int.Parse(line.Substring(20));
if (currentProduct != null)
{
currentProduct.MaxProductionRate = maxProductionRate;
}
ProcessMaxProductionRate(line, currentProduct);
}
}
return _products;
}

private void ProcessMaxProductionRate(string line, Product? currentProduct)
{
int maxProductionRate = int.Parse(line.Substring(20));
if (currentProduct != null)
{
currentProduct.MaxProductionRate = maxProductionRate;
}
}

private void ProcessMinProductionRate(string line, Product? currentProduct)
{
int minProductionRate = int.Parse(line.Substring(20));
if (currentProduct != null)
{
currentProduct.MinProductionRate = minProductionRate;
}
}

private Product? ProcessProductName(string line, ref int idCounter)
{
string name = ReadProductName(line);
return CreateProduct(idCounter++, name, 0);
}

private void ProcessProductDurability(string line, Product? product)
{
if (product != null)
{
int durability = ReadProductDurability(line);
product.Durability = durability;
_products.Add(product);
}
}

private void ProcessProductBasePrice(string line, Product? product)
{
if (product != null)
{
int basePrice = ReadProductBasePrice(line);
product.BasePrice = basePrice;
}
}

public List<Product> GetAllProducts()
{
return _products;
}
}
}
}
15 changes: 8 additions & 7 deletions TheMiddleman/Entities/Middleman.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ namespace TheMiddleman.Entity
{
public class Middleman
{
public Middleman(string name, string company, int accountBalance)
{
Name = name;
Company = company;
AccountBalance = accountBalance;
}
public int Id { get; set; }
public string? Name { get; }
public string? Company { get; }
public int AccountBalance { get; set; }
public int MaxStorageCapacity { get; set; } = 100;
public Dictionary<Product, int> Warehouse { get; set; } = new Dictionary<Product, int>();

public Middleman(string name, string company, int accountBalance)
{
Name = name;
Company = company;
AccountBalance = accountBalance;
}
}
}
}
2 changes: 1 addition & 1 deletion TheMiddleman/Entities/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public class Product
public int MinProductionRate { get; set; }
public int MaxProductionRate { get; set; }
public int AvailableQuantity { get; set; } = 0;
}
}
2 changes: 1 addition & 1 deletion TheMiddleman/MainRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ static void Main()
{
new Game().Run();
}
}
}
16 changes: 7 additions & 9 deletions TheMiddleman/UserInterface/ConsoleUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ private void ManageUserInteraction(string userInput, Middleman middleman, ref bo
EndRound(ref endRound);
break;
case "e":
InitiateShopping(middleman);
ShowShopping(middleman);
break;
case "v":
InitiateSelling(middleman);
ShowSelling(middleman);
break;
case "t":
InitiateWarehouseExpansion(middleman);
ShowWarehouseExpansion(middleman);
break;
default:
NotifyInvalidMenuChoice();
Expand All @@ -224,7 +224,7 @@ private void EndRound(ref bool endRound)
endRound = true;
}

private void InitiateShopping(Middleman middleman)
private void ShowShopping(Middleman middleman)
{
ShowShoppingMenu();
Console.WriteLine("z) Zurück");
Expand All @@ -239,7 +239,7 @@ private void InitiateShopping(Middleman middleman)
}
}

private void InitiateSelling(Middleman middleman)
private void ShowSelling(Middleman middleman)
{
ShowSellingMenu(middleman);
string userChoice = GetUserInput();
Expand All @@ -253,7 +253,7 @@ private void InitiateSelling(Middleman middleman)
}
}

private void InitiateWarehouseExpansion(Middleman middleman)
private void ShowWarehouseExpansion(Middleman middleman)
{
ShowExtendingWarehouse(middleman);
}
Expand All @@ -267,7 +267,6 @@ private void ShowExtendingWarehouse(Middleman middleman)
{
ShowMessage("Um wie viel Einheiten möchten Sie das Lager vergrößern? ($50 pro Einheit)");
_marketService.MiddlemanService().IncreaseWarehouseCapacity(middleman);
ShowMenuAndTakeAction(middleman, _marketService._currentDay);
}

private void ShowAllProducts()
Expand Down Expand Up @@ -376,7 +375,7 @@ private void PrintProductLine(Product product, int idWidth, int nameWidth, int d
$"{("$" + product.PurchasePrice.ToString() + "/Stück").PadRight(priceWidth)}");
}

public static void PrintDayInFrame(int currentDay)
public static void ShowCurrentDay(int currentDay)
{
string dayText = $"Tag {currentDay}";
int padding = 4;
Expand All @@ -394,7 +393,6 @@ public static void PrintDayInFrame(int currentDay)
Console.ResetColor();
}


private void SetColor(ConsoleColor color)
{
Console.ForegroundColor = color;
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.pdb
Binary file not shown.
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.
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 2c4d306

Please sign in to comment.