Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp15
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool worktime = true;
- int userInput;
- Player player = new Player(new AutoPart[] { new Wheel(), new Wheel(), new Wheel(), new GasTank(), new Engine(), new GasTank() }, 1000);
- while (worktime)
- {
- Car car = new Car();
- bool newCar = true;
- player.CheckMoney(ref worktime, ref newCar);
- while (newCar)
- {
- Console.Clear();
- player.ShowMoney();
- Console.WriteLine($"\nЧто желаете сделать:\nВыполнить диагностику - 1\nПочинить машину - 2\nОтказать в обслуживании - 3\nЗаказать делать - 4\nЗакрыть автосервис - 5");
- userInput = Convert.ToInt32(Console.ReadLine());
- switch (userInput)
- {
- case 1:
- car.Diagnostics();
- Console.ReadKey();
- break;
- case 2:
- player.ShowAllParts();
- player.PartForRepair(out string partForRepair);
- bool repairСonfirmed = car.CheckRepair(partForRepair);
- if (repairСonfirmed)
- {
- player.SellPart(partForRepair);
- newCar = false;
- }
- else
- {
- player.Fine();
- newCar = false;
- }
- break;
- case 3:
- player.Fine();
- newCar = false;
- break;
- case 4:
- Console.WriteLine("Для заказа:\nКолеса - нажмите 1\nТопливного бака - нажмите 2\nДвигателя - 3\nДля выхода - 0");
- userInput = Convert.ToInt32(Console.ReadLine());
- switch (userInput)
- {
- case 1:
- player.BuyPart(new Wheel());
- break;
- case 2:
- player.BuyPart(new GasTank());
- break;
- case 3:
- player.BuyPart(new Engine());
- break;
- default:
- break;
- }
- break;
- case 5:
- worktime = false;
- newCar = false;
- break;
- default:
- Console.WriteLine("Вы ввели неверную команду - попрбуйте еще раз");
- break;
- }
- }
- }
- Console.WriteLine("Автосервис закрыт!");
- }
- }
- class Player
- {
- private AutoPart[] _autoPart;
- private int _money;
- public Player(AutoPart[] autoPart, int money)
- {
- _autoPart = autoPart;
- _money = money;
- }
- public void ShowMoney()
- {
- Console.WriteLine($"У вас {_money} рублей");
- }
- public void CheckMoney(ref bool worktime, ref bool newCar)
- {
- if (_money < 0)
- {
- Console.WriteLine($"Вы банкрот.У вас {_money} рублей");
- worktime = false;
- newCar = false;
- }
- }
- public void ChangeMoney(int moneyChange)
- {
- _money += moneyChange;
- }
- public void ShowAllParts()
- {
- for (int i = 0; i < _autoPart.Length; i++)
- {
- Console.WriteLine($"Номер детали: {i} | Имя детали: {_autoPart[i].Name} | Стоимость детали : {_autoPart[i].Price} | Стоимость работы: {_autoPart[i].CostWork}");
- }
- }
- public void PartForRepair(out string partForRepair)
- {
- Console.WriteLine("Выберите деталь которую хотитье использовать для ремонта:");
- partForRepair = _autoPart[Convert.ToInt32(Console.ReadLine())].Name;
- }
- public void Fine()
- {
- _money -= 5000;
- }
- public void SellPart(string partForRepair)
- {
- for (int i = 0; i < _autoPart.Length; i++)
- {
- if (_autoPart[i].Name == partForRepair)
- {
- _autoPart[i].UsingDetail();
- ChangeMoney(_autoPart[i].Price + _autoPart[i].CostWork);
- DeleteEmpty(i);
- break;
- }
- }
- }
- public void DeleteEmpty(int emptyCell)
- {
- AutoPart[] tempAutoPart = new AutoPart[_autoPart.Length - 1];
- for (int i = 0; i < tempAutoPart.Length; i++)
- {
- if (i >= emptyCell)
- {
- tempAutoPart[i] = _autoPart[i + 1];
- }
- else
- {
- tempAutoPart[i] = _autoPart[i];
- }
- }
- _autoPart = tempAutoPart;
- }
- public void BuyPart(AutoPart autoPart)
- {
- Console.WriteLine($"Вы точно хотите купить {autoPart.Name}? Стоимость покупки {autoPart.Price} рублей.\nДля подтвержения - нажмите 1\nДля отмены -2");
- if (Convert.ToInt32(Console.ReadLine()) == 1)
- {
- AutoPart[] tempAutoPart = new AutoPart[_autoPart.Length + 1];
- for (int i = 0; i < _autoPart.Length; i++)
- {
- tempAutoPart[i] = _autoPart[i];
- }
- tempAutoPart[tempAutoPart.Length - 1] = autoPart;
- _autoPart = tempAutoPart;
- ChangeMoney(-autoPart.Price);
- }
- else
- {
- return;
- }
- }
- }
- class AutoPart
- {
- public string Name { get; private set; }
- public int CostWork { get; private set; }
- public int Count { get; private set; }
- public int Price { get; private set; }
- public bool DetailWork { get; private set; }
- public AutoPart(string name, int constWork, int count, int price, bool work)
- {
- Name = name;
- CostWork = constWork;
- Count = count;
- Price = price;
- DetailWork = work;
- }
- public void DetailStatus(bool status)
- {
- DetailWork = status;
- }
- public void UsingDetail()
- {
- Count -= 1;
- }
- }
- class Wheel : AutoPart
- {
- public Wheel(string name = "Колесо", int costWork = 300, int count = 1, int price = 700, bool work = true) : base(name, costWork, count, price, work) { }
- }
- class GasTank : AutoPart
- {
- public GasTank(string name = "Топливнй бак", int costWork = 500, int count = 1, int price = 1200, bool work = true) : base(name, costWork, count, price, work) { }
- }
- class Engine : AutoPart
- {
- public Engine(string name = "Двигатель", int costWork = 1500, int count = 1, int price = 3000, bool work = true) : base(name, costWork, count, price, work) { }
- }
- class Car
- {
- private bool _repared = false;
- private Random _defectPart = new Random();
- private AutoPart[] _partsCar = new AutoPart[] { new Wheel(), new Wheel(), new Wheel(), new Wheel(), new GasTank(), new Engine() };
- public Car()
- {
- DefectPart();
- }
- public void DefectPart()
- {
- int random = _defectPart.Next(0, _partsCar.Length);
- _partsCar[random].DetailStatus(false);
- }
- public void Diagnostics()
- {
- for (int i = 0; i < _partsCar.Length; i++)
- {
- Console.WriteLine($"Имя детали: {_partsCar[i].Name} | Статус детали {_partsCar[i].DetailWork}");
- }
- }
- public bool CheckRepair(string playerPartName)
- {
- for (int i = 0; i < _partsCar.Length; i++)
- {
- if (_partsCar[i].Name == playerPartName && _partsCar[i].DetailWork == false)
- {
- _partsCar[i].DetailStatus(true);
- _repared = true;
- }
- }
- return _repared;
- }
- }
- }
Add Comment
Please, Sign In to add comment