Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- namespace FifthProject
- {
- class Program
- {
- static void Main(string[] args)
- {
- Character character = new Character();
- Player player = new Player();
- Trader trader = new Trader();
- int id, price = 0, scale = 0;
- string name = null;
- bool usability = false;
- while (true)
- {
- ShowMenu();
- int menu = ConvertToInt();
- switch (menu)
- {
- case 1:
- AddInfo(ref price, ref scale, ref name,ref usability);
- trader.AddNewItem(price, scale, name, usability, ref player.playerItems);
- break;
- case 2:
- AddInfo(ref price, ref scale, ref name, ref usability);
- player.AddNewItem(price, scale, name, usability, ref trader.traderItems);
- break;
- case 3:
- player.ShowItems(player.playerItems);
- id = ConvertToInt();
- character.TradeItem(ref player.playerItems, ref trader.traderItems, id);
- break;
- case 4:
- trader.ShowItems(trader.traderItems);
- id = ConvertToInt();
- character.TradeItem(ref trader.traderItems, ref player.playerItems, id);
- break;
- case 5:
- player.ShowItems(player.playerItems);
- Console.ReadKey();
- break;
- case 6:
- trader.ShowItems(trader.traderItems);
- Console.ReadKey();
- break;
- }
- Console.Clear();
- }
- }
- static void ShowMenu()
- {
- Console.WriteLine("\tMenu\n" +
- "1. Добавить новый предмет в инвентарь\n" +
- "2. Добавить новый предмет торговцу\n" +
- "3. Продать предмет\n" +
- "4. Купить предмет\n" +
- "5. Показать инвентарь\n" +
- "6. Показать инвентарь продавца\n");
- }
- static void AddInfo(ref int price, ref int scale, ref string name, ref bool usability)
- {
- Console.WriteLine("Введите цену");
- price = ConvertToInt();
- Console.WriteLine("Введите размер");
- scale = ConvertToInt();
- Console.WriteLine("Введите имя");
- name = Console.ReadLine();
- Console.WriteLine("Можно ли использовать этот предмет?\n" +
- "1. Да\n" +
- "2. Нет\n");
- int menu = ConvertToInt();
- if (menu == 1)
- {
- usability = true;
- }
- else if (menu == 2)
- {
- usability = false;
- }
- }
- static int ConvertToInt()
- {
- int output;
- bool enterIsCorrect = false;
- do
- {
- string input = Console.ReadLine();
- enterIsCorrect = int.TryParse(input, out output);
- if (!enterIsCorrect)
- {
- Console.WriteLine("Error. Try again");
- }
- } while (!enterIsCorrect);
- return output;
- }
- }
- class Character
- {
- public void AddNewItem(int price, int scale, string name, bool usability, ref Item[] items)
- {
- Item[] tempItems = new Item[items.Length + 1];
- for (int i = 0; i < tempItems.Length - 1; i++)
- {
- tempItems[i] = items[i];
- }
- tempItems[tempItems.Length - 1] = new Item(price, scale, name, usability);
- items = tempItems;
- }
- public void RemoveItem(int id, ref Item[] items)
- {
- items[id] = null;
- Item[] tempItems = new Item[items.Length - 1];
- for (int i = 0; i < items.Length - 1; i++)
- {
- if (items[i] != null)
- {
- tempItems[i] = items[i];
- }
- else
- {
- tempItems[i] = items[i + 1];
- }
- }
- items = tempItems;
- }
- public void TradeItem(ref Item[] items,ref Item[] itemsSecond, int id)
- {
- AddNewItem(0,0,null,false, ref itemsSecond);
- itemsSecond[itemsSecond.Length - 1] = items[id];
- RemoveItem(id, ref items);
- }
- public void ShowItems(Item[] items)
- {
- for (int i = 0; i < items.Length; i++)
- {
- Console.WriteLine($"ID: {i} Название: {items[i].Name} Цена: {items[i].Price} " +
- $"Размер: {items[i].Scale} Юзабльность: {items[i].Usability}");
- }
- }
- }
- class Trader : Character
- {
- public Item[] traderItems = new Item[0];
- }
- class Player : Character
- {
- public Item[] playerItems = new Item[0];
- }
- class Item
- {
- public int Price;
- public int Scale;
- public string Name;
- public bool Usability;
- public Item(int price, int scale, string name, bool usability)
- {
- Price = price;
- Scale = scale;
- Name = name;
- Usability = usability;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement