OwlyOwl

ПРИМИ_ПОЖАЛУЙСТА_АЛЕКСЕЙ

Apr 1st, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.50 KB | None | 0 0
  1. using System;
  2.  
  3. namespace GameWithMap
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.CursorVisible = false;
  10.             int userX = 13, userY = 1;
  11.             char userSymb = '@';
  12.             char[] bag = new char[0];
  13.             char[,] map =
  14.             {
  15.                 {'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*', },
  16.                 {'*',' ','$','*',' ',' ',' ','$','*',' ','$',' ',' ','*',' ','*',' ','*', },
  17.                 {'*',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ','$','*', },
  18.                 {'*',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ','*','*', },
  19.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ','*', },
  20.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ','*', },
  21.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ','*', },
  22.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  23.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  24.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  25.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  26.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  27.                 {'*',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  28.                 {'*',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  29.                 {'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*', },
  30.             };
  31.             while (true)
  32.             {
  33.                 {
  34.                     DrawBag(bag);
  35.                     DrawMap(map);
  36.                     DrawUser(userY, userX, userSymb);
  37.                     ConsoleKeyInfo charKey = Console.ReadKey();
  38.                     switch (charKey.Key)
  39.                     {
  40.                         case ConsoleKey.UpArrow:
  41.                             if (map[userX - 1, userY] != '*')
  42.                             {
  43.                                 userX--;
  44.                             }
  45.                             break;
  46.                         case ConsoleKey.DownArrow:
  47.                             if (map[userX + 1, userY] != '*')
  48.                             {
  49.                                 userX++;
  50.                             }
  51.                             break;
  52.                         case ConsoleKey.LeftArrow:
  53.                             if (map[userX, userY - 1] != '*')
  54.                             {
  55.                                 userY--;
  56.                             }
  57.                             break;
  58.                         case ConsoleKey.RightArrow:
  59.                             if (map[userX, userY + 1] != '*')
  60.                             {
  61.                                 userY++;
  62.                             }
  63.                             break;
  64.                     }
  65.                     if (map[userX, userY] == '$')
  66.                     {
  67.                         map[userX, userY] = '^';
  68.                         bag = PutIntoBag(bag);
  69.                     }
  70.                     Console.Clear();
  71.                 }
  72.             }
  73.             static void DrawMap(char[,] map1)
  74.             {
  75.                 Console.SetCursorPosition(0, 0);
  76.                 for (int i = 0; i < map1.GetLength(0); i++)
  77.                 {
  78.                     for (int j = 0; j < map1.GetLength(1); j++)
  79.                     {
  80.                         Console.Write(map1[i, j]);
  81.                     }
  82.                     Console.WriteLine();
  83.                 }
  84.             }
  85.         }
  86.         static void DrawBag(char[] bag)
  87.         {
  88.             Console.SetCursorPosition(0, 18);
  89.             Console.Write("Bag:");
  90.             for (int i = 0; i < bag.Length; i++)
  91.             {
  92.                 Console.Write(bag[i] + " ");
  93.             }
  94.         }
  95.         static void DrawUser(int userY, int userX, char userSymb)
  96.         {
  97.             Console.SetCursorPosition(userY, userX);
  98.             Console.Write(userSymb);
  99.         }
  100.         static char[] PutIntoBag(char[] addToBag)
  101.         {
  102.             char[] tempBag = new char[addToBag.Length + 1];
  103.             for (int i = 0; i < addToBag.Length; i++)
  104.             {
  105.                 tempBag[i] = addToBag[i];
  106.             }
  107.             tempBag[tempBag.Length - 1] = '!';
  108.             return tempBag;
  109.         }
  110.     }
  111. }
Add Comment
Please, Sign In to add comment