Advertisement
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;
- using System.Threading;
- namespace inventory
- {
- public class Inventory
- {
- public string[] arrayItems = new string[6];
- int itemsCount = 0;
- public void AddItem(string item) // dodaje item
- {
- //ewentualnie
- //if (items.Contains(null))
- //{
- // items[Array.IndexOf(items, null)] = newItem;
- //}
- if (itemsCount == 6)
- {
- Console.WriteLine("Inventory full");
- Thread.Sleep(350);
- }
- else
- {
- arrayItems[Array.IndexOf(arrayItems, null)] = item;
- itemsCount++;
- Console.WriteLine("{0} has been added to your inventory. Number of items:{1}", item, itemsCount);
- Thread.Sleep(350);
- }
- }
- public void SwitchItem(int number, string item)
- {
- arrayItems[number - 1] = item;
- }
- public void DisplayItemInBorder(int a, int b) // wyświetla itemy w ramce
- {
- //item0
- Console.SetCursorPosition(2, 5);
- Console.Write(arrayItems[0]);
- //item1
- Console.SetCursorPosition(5+a, 5);
- Console.Write(arrayItems[1]);
- //item2
- Console.SetCursorPosition(8+a+b, 5);
- Console.Write(arrayItems[2]);
- //item3
- Console.SetCursorPosition(2, 9);
- Console.Write(arrayItems[3]);
- //item4
- Console.SetCursorPosition(5+a, 9);
- Console.Write(arrayItems[4]);
- //item5
- Console.SetCursorPosition(8+a+b, 9);
- Console.Write(arrayItems[5]);
- }
- public void DisplayItems() //to było zanim zrobiłem ramkę w ramach ćwiczeń
- {
- Console.SetCursorPosition(0, 1);
- Console.WriteLine("Your items are:");
- Console.SetCursorPosition(0, 2);
- Console.Write(new string(' ', Console.WindowWidth));
- Console.SetCursorPosition(0, 2);
- foreach (string item in arrayItems)
- {
- if (item == null)
- {
- Console.Write("Empty;");
- }
- else
- {
- Console.Write(item + ";");
- }
- }
- }
- public int FindLongerName(int a, int b) // to znajduje dłuższą nazwę z pary żeby skalować ramkę
- { // moze być zbędny kod
- int numberOfChars;
- if (arrayItems[a] == null)
- {
- numberOfChars = 1;
- return numberOfChars;
- }
- else
- {
- if (arrayItems[b] == null)
- {
- numberOfChars = arrayItems[a].Length;
- return numberOfChars;
- }
- else
- {
- if (arrayItems[a].Length > arrayItems[b].Length)
- {
- numberOfChars = arrayItems[a].Length;
- return numberOfChars;
- }
- else
- {
- numberOfChars = arrayItems[b].Length;
- return numberOfChars;
- }
- }
- }
- }
- }
- public class Border
- {
- Inventory inventory = new Inventory();
- public int row = Console.CursorTop;
- public int col = Console.CursorLeft;
- public void WriteFrame(string s, int x, int y) //pozwala całą ramkę przesunąć na raz
- {
- Console.SetCursorPosition(row + x, col + y);
- Console.Write(s);
- }
- public void DisplayFrame(int a, int b, int c)
- {
- Console.SetCursorPosition(0, 3);
- Console.Write(new string(' ', Console.WindowWidth));
- Console.Write(new string(' ', Console.WindowWidth));
- Console.Write(new string(' ', Console.WindowWidth));
- Console.Write(new string(' ', Console.WindowWidth));
- Console.Write(new string(' ', Console.WindowWidth)); //czyści konsole w obszarze ramki
- Console.Write(new string(' ', Console.WindowWidth));
- Console.Write(new string(' ', Console.WindowWidth));
- Console.Write(new string(' ', Console.WindowWidth));
- Console.Write(new string(' ', Console.WindowWidth));
- //top1 //kod ramki poniżej
- WriteFrame("-", 1, 3);
- WriteFrame("-", 3, 3);
- for (int i = 0; i <= a; i++)
- {
- WriteFrame("-", 2 + i, 3);
- }
- //mid1
- WriteFrame("-", 1, 7);
- WriteFrame("-", 3, 7);
- for (int i = 0; i <= a; i++)
- {
- WriteFrame("-", 2 + i, 7);
- }
- //bot1
- WriteFrame("-", 1, 11);
- WriteFrame("-", 3, 11);
- for (int i = 0; i <= a; i++)
- {
- WriteFrame("-", 2 + i, 11);
- }
- //top2
- for (int i = 0; i <= a + b; i++)
- {
- WriteFrame("-", 5 + i, 3);
- }
- //mid2
- for (int i = 0; i <= a + b; i++)
- {
- WriteFrame("-", 5 + i, 7);
- }
- //bot2
- for (int i = 0; i <= a + b; i++)
- {
- WriteFrame("-", 5 + i, 11);
- }
- //top3
- for (int i = 0; i <= a + b + c; i++)
- {
- WriteFrame("-", 8 + i, 3);
- }
- //mid3
- for (int i = 0; i <= a + b + c; i++)
- {
- WriteFrame("-", 8 + i, 7);
- }
- //bot3
- for (int i = 0; i <= a + b + c; i++)
- {
- WriteFrame("-", 8 + i, 11);
- }
- //vertical 1
- WriteFrame("1", 0, 3);
- WriteFrame("|", 0, 4);
- WriteFrame("|", 0, 5);
- WriteFrame("|", 0, 6);
- WriteFrame("4", 0, 7);
- WriteFrame("|", 0, 8);
- WriteFrame("|", 0, 9);
- WriteFrame("|", 0, 10);
- WriteFrame("+", 0, 11);
- //vertical 2
- WriteFrame("2", 3 + a, 3);
- WriteFrame("|", 3 + a, 4);
- WriteFrame("|", 3 + a, 5);
- WriteFrame("|", 3 + a, 6);
- WriteFrame("5", 3 + a, 7);
- WriteFrame("|", 3 + a, 8);
- WriteFrame("|", 3 + a, 9);
- WriteFrame("|", 3 + a, 10);
- WriteFrame("+", 3 + a, 11);
- //vertical 3
- WriteFrame("3", 6 + a + b, 3);
- WriteFrame("|", 6 + a + b, 4);
- WriteFrame("|", 6 + a + b, 5);
- WriteFrame("|", 6 + a + b, 6);
- WriteFrame("6", 6 + a + b, 7);
- WriteFrame("|", 6 + a + b, 8);
- WriteFrame("|", 6 + a + b, 9);
- WriteFrame("|", 6 + a + b, 10);
- WriteFrame("+", 6 + a + b, 11);
- //vertical 4
- WriteFrame("+", 9 + a + b + c, 3);
- WriteFrame("|", 9 + a + b + c, 4);
- WriteFrame("|", 9 + a + b + c, 5);
- WriteFrame("|", 9 + a + b + c, 6);
- WriteFrame("+", 9 + a + b + c, 7);
- WriteFrame("|", 9 + a + b + c, 8);
- WriteFrame("|", 9 + a + b + c, 9);
- WriteFrame("|", 9 + a + b + c, 10);
- WriteFrame("+", 9 + a + b + c, 11);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Inventory inventory = new Inventory();
- Border border = new Border();
- Console.WriteLine("Wpisz komende /add /swap /display /x.");
- while (true)
- {
- border.DisplayFrame(inventory.FindLongerName(0, 3), inventory.FindLongerName(1, 4), inventory.FindLongerName(2, 5));
- inventory.DisplayItemInBorder(inventory.FindLongerName(0, 3), inventory.FindLongerName(1, 4));
- Console.SetCursorPosition(0,12);
- Console.Write(new string(' ', Console.WindowWidth));
- Console.Write(new string(' ', Console.WindowWidth));
- inventory.DisplayItems();
- Console.SetCursorPosition(0, 12);
- string input = Console.ReadLine();
- string command = string.Empty;
- command = input.Split(' ')[0];
- switch (command)
- {
- case "/display": //to juz nic nie robi
- inventory.DisplayItems();
- break;
- case "/add":
- string item = input.Split(' ')[1]; //tutaj potrzebuję ulepszyć, żeby móc dodawać itemy z 2-3 członowymi nazwami np. Rod of Ages wywali program
- inventory.AddItem(item);
- inventory.DisplayItems();
- break;
- case "/swap": //zamienia item
- int numer = Convert.ToInt32(input.Split(' ')[1]);
- string newItem = input.Split(' ')[2];
- inventory.SwitchItem(numer, newItem);
- break;
- case "/x": //to było do testowania
- //int itemIndex = Int32.Parse(input.Split(' ')[1]);
- //inventory.DisplaySelectedItem(itemIndex);
- //Console.Write(inventory.FindLongerName());
- //Console.Write(inventory.FindLongerName(0, 3));
- Thread.Sleep(1000);
- break;
- }
- }
- //Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement