Advertisement
Vadim_Rogulev

Untitled

Apr 25th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace Творческое_задание
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int counter = 0;
  15.             int Gold = 100;
  16.             int Tree = 100;
  17.             int Stone = 100;
  18.             int Metal = 100;
  19.             int People = 100;
  20.             int Food = 100;
  21.             while (true)
  22.             {
  23.                 Console.Clear();
  24.                 Frame("frame.txt");
  25.                 Console.SetCursorPosition(18, 2);
  26.                 Console.WriteLine("Золото: " + Gold + " Дерево: " + Tree + " Камень: " + Stone + " Метал: " + Metal + "             Крестьяне: " + People + " Еда: " + Food);
  27.                 ConsoleKeyInfo key;
  28.                 if (Console.KeyAvailable)
  29.                 {
  30.                     key = Console.ReadKey(true);
  31.                     switch (key.Key)
  32.                     {
  33.                         case ConsoleKey.Escape:
  34.                             int Item_Selection = 0;
  35.                             Menu(ref Item_Selection, "interface_4");
  36.                             switch (Item_Selection)
  37.                             {
  38.                                 case 1:
  39.                                     break;
  40.                             }
  41.                             break;
  42.                     }
  43.                 }
  44.                             System.Threading.Thread.Sleep(10000);//1секунда = 1000 милисекунд
  45.                 Gold += 1;
  46.                 Tree += 1;
  47.                 Stone += 1;
  48.                 Metal += 1;
  49.                 People += 1;
  50.                 Food += 1;
  51.             }
  52.         }
  53.         static void Frame(string Input_File)
  54.         {
  55.             Console.CursorVisible = false;//прячем мигающий курсор
  56.             string[] Frame = File.ReadAllLines(Input_File, System.Text.Encoding.GetEncoding(1251));//вызывается массив из файла и переводится в Unicode
  57.             char[,] FrameChar = new char[Frame.Length, Frame[1].Length];
  58.             for (int i = 0; i < FrameChar.GetLength(0); i++)
  59.                 for (int j = 0; j < FrameChar.GetLength(1); j++)
  60.                     FrameChar[i, j] = Frame[i][j];//присвоение всех элементов массива нового файла массиву интерфейса
  61.             for (int i = 0; i < FrameChar.GetLength(0); i++)
  62.             {
  63.                 for (int j = 0; j < FrameChar.GetLength(1); j++)
  64.                 {
  65.                     Console.Write(FrameChar[i, j]);
  66.                 }
  67.                 Console.WriteLine();
  68.             }
  69.         }
  70.         static void Menu(ref int Item_Selection, string Input_File)
  71.         {
  72.             bool Input = true;//запуск стика
  73.             Item_Selection = 1;//выбираемый элемент
  74.             Console.CursorVisible = false;//прячем мигающий курсор
  75.             string[] newFile = File.ReadAllLines(Input_File, System.Text.Encoding.GetEncoding(1251));//вызывается массив из файла и переводится в Unicode
  76.             char[,] Interface = new char[newFile.Length, newFile[1].Length];
  77.  
  78.             int CursorX = 0, CursorY = 0;//ввод положения курсора
  79.             int DY = 0;//изминение положение курсора (вертикальное)
  80.             for (int i = 0; i < Interface.GetLength(0); i++)
  81.                 for (int j = 0; j < Interface.GetLength(1); j++)
  82.                     Interface[i, j] = newFile[i][j];//присвоение всех элементов массива нового файла массиву интерфейса
  83.             for (int i = 0; i < Interface.GetLength(0); i++)
  84.             {
  85.                 for (int j = 0; j < Interface.GetLength(1); j++)
  86.                 {
  87.                     if (Interface[i, j] == 'O')
  88.                     {
  89.                         CursorX = j;
  90.                         CursorY = i;
  91.                         Interface[i, j] = ' ';
  92.                     }
  93.                     Console.Write(Interface[i, j]);
  94.                 }
  95.                 Console.WriteLine();
  96.             }
  97.             Console.SetCursorPosition(4, CursorY - 2);
  98.             Console.Write(' ');//убираем верхний блок
  99.             Console.SetCursorPosition(4, Interface.GetLength(0) - 1);
  100.             Console.Write(' ');//убираем нижний блок
  101.             Console.SetCursorPosition(CursorX, CursorY);
  102.             Console.Write('O');
  103.             ConsoleKeyInfo key;
  104.             while (Input == true)
  105.             {
  106.                 key = Console.ReadKey(true);
  107.                 switch (key.Key)
  108.                 {
  109.                     case ConsoleKey.UpArrow:
  110.                         DY -= 2;
  111.                         if (Interface[CursorY + DY, CursorX] != '#')
  112.                         {
  113.                             Item_Selection--;
  114.                         }
  115.                         break;
  116.                     case ConsoleKey.DownArrow:
  117.                         DY += 2;
  118.                         if (Interface[CursorY + DY, CursorX] != '#')
  119.                         {
  120.                             Item_Selection++;
  121.                         }
  122.                         break;
  123.                     case ConsoleKey.Enter:
  124.                         Input = false;
  125.                         break;
  126.                 }
  127.  
  128.                 //Console.SetCursorPosition(10, 20);
  129.                 //Console.Write($"Выбор элемента {Item_Selection}"); //проверка выводимого значения
  130.  
  131.                 if (Interface[CursorY + DY, CursorX] != '#')
  132.                 {
  133.                     Console.SetCursorPosition(CursorX, CursorY);
  134.                     Console.Write(' ');//затираем курсор
  135.                     CursorY = CursorY + DY;//передвигаем его на новое положение
  136.                     Console.SetCursorPosition(CursorX, CursorY);
  137.                     Console.Write('O');//отображаем курсор вновь
  138.                 }
  139.                 DY = 0;
  140.  
  141.             }
  142.         }
  143.  
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement