Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- CarService carService = new CarService();
- carService.StartWork();
- }
- }
- class CarService
- {
- private Warehouse _warehouse;
- private int _money;
- private Random _random;
- public CarService()
- {
- _random = new Random();
- _warehouse = new Warehouse();
- _money = _random.Next(10000,20000);
- }
- public void StartWork()
- {
- bool isWorking = true;
- string userInput;
- while (isWorking && _money > 0)
- {
- Console.ReadKey();
- Console.Clear();
- Car car = new Car(_warehouse.GetDetail(_random.Next(0, _warehouse.GetCountDetails())));
- ShowInfo();
- Console.WriteLine("1.Продолжить\n2.Выход");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- StartService(car);
- break;
- case "2":
- isWorking = false;
- break;
- default:
- break;
- }
- }
- if (_money <= 0)
- {
- Console.WriteLine("Вы банкрот, игра окончена!");
- }
- }
- private void StartService(Car car)
- {
- bool isService = true;
- string userInput;
- int fine = 5000;
- int priceWork = 5000;
- int income = priceWork + car.Breaking.Price;
- while (isService && _money > 0)
- {
- Console.ReadKey();
- Console.Clear();
- ShowInfo();
- car.ShowInfo();
- Console.WriteLine($"\nДоход если почините машину: {income}");
- Console.WriteLine("\n1.Заменить деталь\n2.Купить деталь\n3.Отказать клиенту");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- ReplaceDetail(car,fine,priceWork);
- isService = false;
- break;
- case "2":
- BuyDetail();
- break;
- case "3":
- Console.WriteLine($"Вы отказали клиенту и заплатили штраф в размере {fine}");
- _money -= fine;
- isService = false;
- break;
- default:
- break;
- }
- }
- }
- private void ReplaceDetail(Car car, int fine, int priceWork)
- {
- string userInput;
- Console.WriteLine("\nКакую деталь заменить?");
- userInput = Console.ReadLine();
- int number;
- if (int.TryParse(userInput, out number) && _warehouse.CheckDetail(number - 1))
- {
- int income = priceWork + _warehouse.GetDetail(number - 1).Price;
- if (_warehouse.GetDetail(number - 1) == car.Breaking)
- {
- if (_warehouse.CheckAmountDetail(number - 1))
- {
- _warehouse.SubtractDetails(number - 1);
- _money += income;
- Console.WriteLine($"Деталь заменена успешно. Доход: {income}");
- }
- else
- {
- _money -= fine;
- Console.WriteLine($"Детали не было на складе, клиент уехал. Вы выплатили штраф в размере {fine}");
- }
- }
- else
- {
- fine += income;
- _money -= fine;
- Console.WriteLine($"Вы выбрали не ту деталь для замены, вы выплатели штраф в размере {fine}");
- }
- }
- else
- {
- _money -= fine;
- Console.WriteLine($"Детали не было на складе, клиент уехал. Вы выплатили штраф в размере {fine}");
- }
- }
- private void BuyDetail()
- {
- string userInput;
- Console.WriteLine("\nКакую деталь купить?");
- userInput = Console.ReadLine();
- int number;
- if (int.TryParse(userInput, out number) && _warehouse.CheckDetail(number - 1))
- {
- if (_money > _warehouse.GetDetail(number - 1).Price)
- {
- _money -= _warehouse.GetDetail(number - 1).Price;
- Console.WriteLine($"Деталь {_warehouse.GetDetail(number - 1).Name} куплена");
- _warehouse.AddDetail(number - 1);
- }
- else
- {
- Console.WriteLine("Не хватило денег на деталь(((");
- }
- }
- }
- private void ShowInfo()
- {
- Console.WriteLine($"Автосервис:\nДеньги: {_money}");
- _warehouse.ShowInfo();
- }
- }
- class Warehouse
- {
- private Dictionary<int, Detail> _details;
- private List<string> _nameDetails;
- private Dictionary<string, int> _detailsCounts;
- public Warehouse()
- {
- Random random = new Random();
- _nameDetails = new List<string> { "Двигатель", "Трансмиссия", "Тормозная система"};
- _details = new Dictionary<int,Detail>();
- _detailsCounts = new Dictionary<string, int>();
- for (int i = 0; i < _nameDetails.Count; i++)
- {
- _details.Add(i, new Detail(_nameDetails[i])) ;
- _detailsCounts.Add(_details[i].Name,random.Next(0,5));
- }
- }
- public void ShowInfo()
- {
- Console.WriteLine("Детали: ");
- int index = 1;
- foreach (var detail in _details)
- {
- Console.Write($"{index}. ");
- detail.Value.ShowInfo();
- Console.Write($" || Кол-во: {_detailsCounts[detail.Value.Name]}\n");
- index++;
- }
- }
- public Detail GetDetail(int index)
- {
- return _details[index];
- }
- public bool CheckDetail(int index)
- {
- if (_details.ContainsKey(index))
- return true;
- else
- {
- Console.WriteLine("Нет такой детали нет на складе!");
- return false;
- }
- }
- public bool CheckAmountDetail(int index)
- {
- if (_detailsCounts[_nameDetails[index]] > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public int GetCountDetails()
- {
- return _details.Count;
- }
- public void SubtractDetails(int index)
- {
- _detailsCounts[_nameDetails[index]]--;
- }
- public void AddDetail(int index)
- {
- _detailsCounts[_nameDetails[index]]++;
- }
- }
- class Car
- {
- public Detail Breaking { get; private set; }
- public Car(Detail detail)
- {
- Breaking = detail;
- }
- public void ShowInfo()
- {
- Console.WriteLine("Поломка у машины: ");
- Breaking.ShowInfo();
- }
- }
- class Detail
- {
- public string Name { get; private set; }
- public int Price { get; private set; }
- public Detail(string name)
- {
- Random random = new Random();
- Name = name;
- Price = random.Next(10000,20000);
- }
- public void ShowInfo()
- {
- Console.Write($"Название детали: {Name} || Стоимость: {Price}");
- }
- }
- }
Add Comment
Please, Sign In to add comment