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.IO;
- namespace Творческое_задание
- {
- class Program
- {
- static void Main(string[] args)
- {
- int counter = 0;
- int Gold = 100;
- int Tree = 100;
- int Stone = 100;
- int Metal = 100;
- int People = 100;
- int Food = 100;
- while (true)
- {
- Console.Clear();
- Frame("frame.txt");
- Console.SetCursorPosition(18, 2);
- Console.WriteLine("Золото: " + Gold + " Дерево: " + Tree + " Камень: " + Stone + " Метал: " + Metal + " Крестьяне: " + People + " Еда: " + Food);
- ConsoleKeyInfo key;
- if (Console.KeyAvailable)
- {
- key = Console.ReadKey(true);
- switch (key.Key)
- {
- case ConsoleKey.Escape:
- int Item_Selection = 0;
- Menu(ref Item_Selection, "interface_4");
- switch (Item_Selection)
- {
- case 1:
- break;
- }
- break;
- }
- }
- System.Threading.Thread.Sleep(10000);//1секунда = 1000 милисекунд
- Gold += 1;
- Tree += 1;
- Stone += 1;
- Metal += 1;
- People += 1;
- Food += 1;
- }
- }
- static void Frame(string Input_File)
- {
- Console.CursorVisible = false;//прячем мигающий курсор
- string[] Frame = File.ReadAllLines(Input_File, System.Text.Encoding.GetEncoding(1251));//вызывается массив из файла и переводится в Unicode
- char[,] FrameChar = new char[Frame.Length, Frame[1].Length];
- for (int i = 0; i < FrameChar.GetLength(0); i++)
- for (int j = 0; j < FrameChar.GetLength(1); j++)
- FrameChar[i, j] = Frame[i][j];//присвоение всех элементов массива нового файла массиву интерфейса
- for (int i = 0; i < FrameChar.GetLength(0); i++)
- {
- for (int j = 0; j < FrameChar.GetLength(1); j++)
- {
- Console.Write(FrameChar[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void Menu(ref int Item_Selection, string Input_File)
- {
- bool Input = true;//запуск стика
- Item_Selection = 1;//выбираемый элемент
- Console.CursorVisible = false;//прячем мигающий курсор
- string[] newFile = File.ReadAllLines(Input_File, System.Text.Encoding.GetEncoding(1251));//вызывается массив из файла и переводится в Unicode
- char[,] Interface = new char[newFile.Length, newFile[1].Length];
- int CursorX = 0, CursorY = 0;//ввод положения курсора
- int DY = 0;//изминение положение курсора (вертикальное)
- for (int i = 0; i < Interface.GetLength(0); i++)
- for (int j = 0; j < Interface.GetLength(1); j++)
- Interface[i, j] = newFile[i][j];//присвоение всех элементов массива нового файла массиву интерфейса
- for (int i = 0; i < Interface.GetLength(0); i++)
- {
- for (int j = 0; j < Interface.GetLength(1); j++)
- {
- if (Interface[i, j] == 'O')
- {
- CursorX = j;
- CursorY = i;
- Interface[i, j] = ' ';
- }
- Console.Write(Interface[i, j]);
- }
- Console.WriteLine();
- }
- Console.SetCursorPosition(4, CursorY - 2);
- Console.Write(' ');//убираем верхний блок
- Console.SetCursorPosition(4, Interface.GetLength(0) - 1);
- Console.Write(' ');//убираем нижний блок
- Console.SetCursorPosition(CursorX, CursorY);
- Console.Write('O');
- ConsoleKeyInfo key;
- while (Input == true)
- {
- key = Console.ReadKey(true);
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- DY -= 2;
- if (Interface[CursorY + DY, CursorX] != '#')
- {
- Item_Selection--;
- }
- break;
- case ConsoleKey.DownArrow:
- DY += 2;
- if (Interface[CursorY + DY, CursorX] != '#')
- {
- Item_Selection++;
- }
- break;
- case ConsoleKey.Enter:
- Input = false;
- break;
- }
- //Console.SetCursorPosition(10, 20);
- //Console.Write($"Выбор элемента {Item_Selection}"); //проверка выводимого значения
- if (Interface[CursorY + DY, CursorX] != '#')
- {
- Console.SetCursorPosition(CursorX, CursorY);
- Console.Write(' ');//затираем курсор
- CursorY = CursorY + DY;//передвигаем его на новое положение
- Console.SetCursorPosition(CursorX, CursorY);
- Console.Write('O');//отображаем курсор вновь
- }
- DY = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement