Advertisement
OwlyOwl

@vs$

Mar 28th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.45 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.                         char[] tempBag = new char[bag.Length + 1];
  69.                         for (int i = 0; i < bag.Length; i++)
  70.                         {
  71.                             tempBag[i] = bag[i];
  72.                         }
  73.                         tempBag[tempBag.Length - 1] = '$';
  74.                         bag = tempBag;
  75.                     }
  76.                     Console.Clear();
  77.                 }
  78.             }
  79.             static void DrawMap(char[,] map1)
  80.             {
  81.                 Console.SetCursorPosition(0, 0);
  82.                 for (int i = 0; i < map1.GetLength(0); i++)
  83.                 {
  84.                     for (int j = 0; j < map1.GetLength(1); j++)
  85.                     {
  86.                         Console.Write(map1[i, j]);
  87.                     }
  88.                     Console.WriteLine();
  89.                 }
  90.             }
  91.         }
  92.         static void DrawBag(char[] bag)
  93.         {
  94.             Console.SetCursorPosition(0, 18);
  95.             Console.Write("Bag:");
  96.             for (int i = 0; i < bag.Length; i++)
  97.             {
  98.                 Console.Write(bag[i] + " ");
  99.             }
  100.         }
  101.         static void DrawUser(int userY, int userX, char userSymb)
  102.         {
  103.             Console.SetCursorPosition(userY, userX);
  104.             Console.Write(userSymb);
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement