/// <summary> /// Перемещение влево. /// </summary> /// <param name="A"> Объект перемещения. </param> private static void MoveLeft(PlayInterface A) { if (A.XBySpace - 1 > 2) { A.Clear(); A.PositionSet(A.XBySpace - 1, A.YBySpace); } }
/// <summary> /// Перемещение вверх. /// </summary> /// <param name="A"> Объект перемещения. </param> private static void MoveUp(PlayInterface A) { if (A.YBySpace - 1 > 1) { A.Clear(); A.PositionSet(A.XBySpace, A.YBySpace - 1); } }
/// <summary> /// Перемещение вниз. /// </summary> /// <param name="A"> Объект перемещения. </param> private static void MoveDown(PlayInterface A) { if (A.YBySpace + 1 < Console.WindowHeight - 1) { A.Clear(); A.PositionSet(A.XBySpace, A.YBySpace + 1); } }
/// <summary> /// Перемещение вправо. /// </summary> /// <param name="A"> Объект перемещения. </param> private static void MoveRight(PlayInterface A) { if (A.XBySpace + 1 < Console.WindowWidth - 3) { A.Clear(); A.PositionSet(A.XBySpace + 1, A.YBySpace); } }
public WorldLogic(World world, WorldGrid grid, Vector2i startInIndices, Vector2i finishInIndices, PlayInterface playInterface) { this.world = world; this.grid = grid; this.playInterface = playInterface; cells = grid.Cells as Cell[, ]; this.startInIndices = startInIndices; this.finishInIndices = finishInIndices; graph = new Graph(); for (var y = 0; y < grid.CellCount.Y; y++) { for (var x = 0; x < grid.CellCount.X; x++) { var neighbors = GetNeighbors(new Vector2i(x, y)); if (neighbors != null) { switch (neighbors.Count) { case 1: graph.AddVertex(cells[y, x], new Dictionary <Cell, int>() { { neighbors[0], neighbors[0].Weight } }); break; case 2: graph.AddVertex(cells[y, x], new Dictionary <Cell, int>() { { neighbors[0], neighbors[0].Weight }, { neighbors[1], neighbors[1].Weight } }); break; case 3: graph.AddVertex(cells[y, x], new Dictionary <Cell, int>() { { neighbors[0], neighbors[0].Weight }, { neighbors[1], neighbors[1].Weight }, { neighbors[2], neighbors[2].Weight } }); break; case 4: graph.AddVertex(cells[y, x], new Dictionary <Cell, int>() { { neighbors[0], neighbors[0].Weight }, { neighbors[1], neighbors[1].Weight }, { neighbors[2], neighbors[2].Weight }, { neighbors[3], neighbors[3].Weight } }); break; } } } } path = new List <Cell>(); SpawnStart(cells[startInIndices.Y, startInIndices.X]); SpawnMan(cells[startInIndices.Y, startInIndices.X]); SpawnFinish(cells[finishInIndices.Y, finishInIndices.X]); logicState = WorldLogicState.FindingPath; }
/// <summary> /// Команды выполняемые при удержании альт и е (т.е. добавление элементов в коллекцию вручную) /// </summary> /// <param name="A"> Ссылка на интерфейс объекта.ы</param> public static void PressAltAndE(PlayInterface A) { ItemsCollections = LoadData(); Console.Clear(); Console.SetCursorPosition(0, 0); Console.WriteLine("Создание нового элемента инвентаря"); Console.WriteLine("Введите имя:"); Console.CursorVisible = true; string name = Console.ReadLine(); Console.WriteLine("Введите цену:"); double price = double.Parse(Console.ReadLine()); Console.WriteLine("Введите описание:"); string Describe = Console.ReadLine(); int ID = ItemsCollections.Count + 1; ItemsCollections.Add(new Item(name, price, Describe, ID)); if (UserController.ReturnCurentUser(UserController.CurentUserName).Count == null) { UserController.ReturnCurentUser(UserController.CurentUserName).Count = new int[1]; } else { int[] a = new int[UserController.ReturnCurentUser(UserController.CurentUserName).Count.Length + 1]; int i = 0; foreach (var s in UserController.ReturnCurentUser(UserController.CurentUserName).Count) { a[i++] = s; } UserController.ReturnCurentUser(UserController.CurentUserName).Count = a; } SaveData(); UserController.SaveData(); Console.CursorVisible = false; Console.WriteLine("Элемент успешно создан. Для продолжения нажмите любую клавишу."); Console.ReadKey(); A.CreateBorder(); A.Draw(); }
/// <summary> /// Назначение клавиш при движении объекта. /// </summary> /// <param name="A"> Объект. </param> public static void KeyAssignment(PlayInterface A) { ConsoleKeyInfo cki; do { cki = Console.ReadKey(true); if (((cki.Modifiers & ConsoleModifiers.Alt) != 0) && (cki.Key == ConsoleKey.E)) { PressAltAndE(A); } else { switch (cki.Key) { case ConsoleKey.UpArrow: MoveUp(A); break; case ConsoleKey.DownArrow: MoveDown(A); break; case ConsoleKey.LeftArrow: MoveLeft(A); break; case ConsoleKey.RightArrow: MoveRight(A); break; case ConsoleKey.E: CallInventory(A); break; } } } while (cki.Key != ConsoleKey.Escape); }
public World(PlayInterface playInterface) { Grid = new WorldGrid(ResourceLoader.GridSize, CellSize); WorldLogic = new WorldLogic(this, Grid, ResourceLoader.StartPositionIndices, ResourceLoader.FinishPositionIndices, playInterface); }
/// <summary> /// Вызов инвентаря (по умолчанию кл E). /// </summary> /// <param name="A"> Объект вызова. </param> private static void CallInventory(PlayInterface A) { Console.Clear(); ItemsCollections = LoadData(); Element[,] ListElement = new Element[0, 0]; foreach (var s in ItemsCollections) { ListElement = TheLastElement(ListElement, s); } Element[,] AddListElement = new Element[ListElement.GetLength(0) + 2, ListElement.GetLength(1)]; for (int i = 0; i < ListElement.GetLength(0); i++) { for (int j = 0; j < ListElement.GetLength(1); j++) { AddListElement[i, j] = ListElement[i, j]; } } for (int i = 0; i < ListElement.GetLength(1) - 1; i++) { AddListElement[ListElement.GetLength(0), i] = new Element(" "); } AddListElement[ListElement.GetLength(0), ListElement.GetLength(1) - 1] = new Element("Выход"); AddListElement[ListElement.GetLength(0) + 1, 0] = new Element("Balance"); AddListElement[ListElement.GetLength(0) + 1, 1] = new Element(UserController.ReturnCurentUser(UserController.CurentUserName).Balance.ToString()); for (int i = 2; i < ListElement.GetLength(1); i++) { AddListElement[ListElement.GetLength(0) + 1, i] = new Element(" "); } ListElement = AddListElement; ChoseMenu ListOfItems = new ChoseMenu(ListElement) { IndexX = Item.Number - 1 }; ListOfItems.Elements[0, 0].IsSelected = false; ListOfItems.Elements[0, Item.Number - 1].IsSelected = true; ListOfItems.MenuButtonSet(); while (ListOfItems.IndexY < ItemsCollections.Count) { if (ListOfItems.IndexX == Item.Number - 1) { if (UserController.ReturnCurentUser(UserController.CurentUserName).Count[ListOfItems.IndexY] > 0) { UserController.ReturnCurentUser(UserController.CurentUserName).Count[ListOfItems.IndexY]--; ListOfItems.Elements[ListOfItems.IndexY, 0].Text = (int.Parse(ListOfItems.Elements[ListOfItems.IndexY, 0].Text) - 1).ToString(); UserController.ReturnCurentUser(UserController.CurentUserName).Balance += int.Parse(ListOfItems.Elements[ListOfItems.IndexY, 3].Text); } } else { if (UserController.ReturnCurentUser(UserController.CurentUserName).Balance >= int.Parse(ListOfItems.Elements[ListOfItems.IndexY, 3].Text)) { UserController.ReturnCurentUser(UserController.CurentUserName).Count[ListOfItems.IndexY]++; ListOfItems.Elements[ListOfItems.IndexY, 0].Text = (int.Parse(ListOfItems.Elements[ListOfItems.IndexY, 0].Text) + 1).ToString(); UserController.ReturnCurentUser(UserController.CurentUserName).Balance -= int.Parse(ListOfItems.Elements[ListOfItems.IndexY, 3].Text); } } UserController.SaveData(); ListOfItems.Elements[ListElement.GetLength(0) - 1, 1] = new Element(UserController.ReturnCurentUser(UserController.CurentUserName).Balance.ToString()); ListOfItems.MenuButtonSet(); } A.CreateBorder(); A.Draw(); }
//Проблема с паролями. static void Main(string[] args) { Console.Title = "Первая игра"; UserController.Authorization(); string name = UserController.CurentUserName; Console.Clear(); User CurentUser = UserController.ReturnCurentUser(name); Console.WriteLine("Авторизация прошла успешно!"); Console.WriteLine($"Вы вошли под логином {CurentUser.Login}"); Console.WriteLine("Для продолжения нажмите любую клавишу..."); Console.ReadKey(); Console.Clear(); while (true) { const string PlayButton = "Играть."; const string StatisticsButton = "Статистика."; const string OptionButton = "Настройки."; const string ExitButton = "Выход."; Element[,] elements = new Element[, ] { { new Element(PlayButton) }, { new Element(StatisticsButton) }, { new Element(OptionButton) }, { new Element(ExitButton) } }; ChoseMenu MainMenu = new ChoseMenu(elements); MainMenu.MenuButtonSet(); switch (MainMenu.ChosenElement.Text) { case PlayButton: PlayInterface A = new PlayInterface(); A.CreateBorder(); A.PositionSet(50, 50); GameController.KeyAssignment(A); break; case StatisticsButton: StaticsController.StaticList(); break; case OptionButton: OptionController.OptionMenu(); break; case ExitButton: Thread.CurrentThread.Abort(); Thread.Sleep(1000); break; } Console.Clear(); } }
public PlayScene() { Background = new Background(); GUI = new PlayInterface(); World = new World(GUI as PlayInterface); }