dmitryEfremov

Untitled

Aug 6th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. using ConsoleApp1;
  2. using System;
  3. using System.Buffers;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Net.Http.Headers;
  8. using System.Runtime.CompilerServices;
  9. using System.Runtime.InteropServices.ComTypes;
  10. using System.Security.Cryptography.X509Certificates;
  11.  
  12. namespace ConsoleApp1
  13. {
  14. class Program
  15. {
  16. static void Main(string[] args)
  17. {
  18. Seller seller = new Seller();
  19. Buyer buyer = new Buyer();
  20. bool exit = true;
  21. while (exit)
  22. {
  23. Console.ForegroundColor = ConsoleColor.Green;
  24. Console.SetCursorPosition(45, 0);
  25. buyer.ShowCashBuyer();
  26. Console.SetCursorPosition(0, 0);
  27. Console.ForegroundColor = ConsoleColor.White;
  28. Console.WriteLine("<<<Добро пожаловать в магазин>>>");
  29. Console.WriteLine("Нажмите 1 что бы посмотреть список доступных для покупки товаров");
  30. Console.WriteLine("Нажмите 2 что бы купить товар");
  31. Console.WriteLine("Нажмите 3 что бы посмотреть инвентарь\n");
  32. Console.Write("Выберите функцию: ");
  33. switch (Convert.ToInt32(Console.ReadLine()))
  34. {
  35. case 1:
  36. seller.ShowProducts();
  37. break;
  38. case 2:
  39. Console.WriteLine("Напишите название товара");
  40. buyer.BuyProduct(Console.ReadLine());
  41. break;
  42. case 3:
  43. buyer.ShowInventory();
  44. break;
  45. default:
  46. Console.WriteLine("Вы ввели неверную функцию, повторите попытку...");
  47. break;
  48. }
  49. Console.ReadLine();
  50. Console.Clear();
  51. }
  52. }
  53. }
  54.  
  55. class Buyer
  56. {
  57. static Random rnd = new Random();
  58. private int _money = rnd.Next(500, 1500);
  59. List<string> _inventory = new List<string>();
  60. Seller seller = new Seller();
  61.  
  62. public void ShowInventory()
  63. {
  64. foreach (var item in _inventory)
  65. {
  66. Console.WriteLine(item);
  67. }
  68. }
  69.  
  70. public void ShowCashBuyer()
  71. {
  72. Console.WriteLine("Бюджет покупателя = " + _money);
  73. }
  74.  
  75. public void BuyProduct(string product)
  76. {
  77. if (_money >= seller.ShowPrice(product))
  78. {
  79. _money -= seller.ShowPrice(product);
  80. seller.SellProduct(product);
  81. _inventory.Add(product);
  82. }
  83. else
  84. {
  85. Console.WriteLine("У вас недостаточно денег.");
  86. }
  87.  
  88. }
  89.  
  90. }
  91.  
  92. class Seller
  93. {
  94. private Product products = new Product();
  95. private int _cash;
  96.  
  97. public void ShowCash()
  98. {
  99. Console.WriteLine($"Касса у магазина - {_cash}");
  100. }
  101. public void SellProduct(string product)
  102. {
  103. _cash += ShowPrice(product);
  104. GiveProduct(product);
  105. }
  106. private class Product
  107. {
  108. public Dictionary<string, int> _products = new Dictionary<string, int>
  109. {
  110. {"Молоко", 100},
  111. {"Сахар", 60},
  112. {"Снежок", 80},
  113. {"Конфеты", 50},
  114. {"Сникерс", 30},
  115. {"Mallboro", 175},
  116. {"Газета", 10},
  117. {"Соль", 30},
  118. {"Майонез", 90}
  119. };
  120. }
  121. public void ShowProducts()
  122. {
  123. foreach (var item in products._products)
  124. {
  125. Console.WriteLine($"{item.Key} - {item.Value}");
  126. }
  127. }
  128.  
  129. public int ShowPrice(string product)
  130. {
  131. return products._products[product];
  132. }
  133.  
  134. public void GiveProduct(string product)
  135. {
  136. products._products.Remove(product);
  137. }
  138. }
  139. }
  140.  
Add Comment
Please, Sign In to add comment