Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfeo committed Nov 5, 2023
1 parent 8d0c186 commit 6480521
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 56 deletions.
8 changes: 7 additions & 1 deletion TheMiddleman/BusinessLogic/ProductService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -28,4 +29,9 @@ public List<Product> GetAllProducts()
{
return productRepository.GetAllProducts();
}

/* public Product getProductById(int id)
{
return productRepository.getProductById(id);
} */
}
13 changes: 13 additions & 0 deletions TheMiddleman/DataAccess/ProductRepository.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

using System.Runtime.Serialization;

namespace TheMiddleman.DataAccess
{
public class ProductRepository : IProductRepository
Expand Down Expand Up @@ -85,5 +88,15 @@ public List<Product> 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;
} */
}
}
40 changes: 29 additions & 11 deletions TheMiddleman/UserInterface/ConsoleUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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
{
Expand All @@ -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}");
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.
88 changes: 44 additions & 44 deletions TheMiddleman/produkte.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6480521

Please sign in to comment.