Advertisement
OwlyOwl

ssaassafasf

Apr 1st, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.62 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.  
  35.                     DrawBag(bag);
  36.                     DrawMap(map);
  37.                     DrawUser(userY, userX, userSymb);
  38.                     ConsoleKeyInfo charKey = Console.ReadKey();
  39.                     switch (charKey.Key)
  40.                     {
  41.                         case ConsoleKey.UpArrow:
  42.                             if (map[userX - 1, userY] != '*')
  43.                             {
  44.                                 userX--;
  45.                             }
  46.                             break;
  47.                         case ConsoleKey.DownArrow:
  48.                             if (map[userX + 1, userY] != '*')
  49.                             {
  50.                                 userX++;
  51.                             }
  52.                             break;
  53.                         case ConsoleKey.LeftArrow:
  54.                             if (map[userX, userY - 1] != '*')
  55.                             {
  56.                                 userY--;
  57.                             }
  58.                             break;
  59.                         case ConsoleKey.RightArrow:
  60.                             if (map[userX, userY + 1] != '*')
  61.                             {
  62.                                 userY++;
  63.                             }
  64.                             break;
  65.  
  66.                     }
  67.                     if (map[userX, userY] == '$')
  68.                     {
  69.                         map[userX, userY] = '^';
  70.                         AddtoBag(bag);
  71.  
  72.                         Console.Clear();
  73.                     }
  74.                 }
  75.  
  76.                 static void DrawMap(char[,] map1)
  77.                 {
  78.                     Console.SetCursorPosition(0, 0);
  79.                     for (int i = 0; i < map1.GetLength(0); i++)
  80.                     {
  81.                         for (int j = 0; j < map1.GetLength(1); j++)
  82.                         {
  83.                             Console.Write(map1[i, j]);
  84.                         }
  85.                         Console.WriteLine();
  86.                     }
  87.                 }
  88.             }
  89.             static void DrawBag(char[] bag)
  90.             {
  91.                 Console.SetCursorPosition(0, 18);
  92.                 Console.Write("Bag:");
  93.                 for (int i = 0; i < bag.Length; i++)
  94.                 {
  95.                     Console.Write(bag[i] + " ");
  96.                 }
  97.             }
  98.             static void DrawUser(int userY, int userX, char userSymb)
  99.             {
  100.                 Console.SetCursorPosition(userY, userX);
  101.                 Console.Write(userSymb);
  102.             }
  103.         }
  104.  
  105.         static char[] AddtoBag(char[] bag)
  106.         {
  107.             char[] tempBag = new char[bag.Length + 1];
  108.             for (int i = 0; i < bag.Length; i++)
  109.             {
  110.                 tempBag[i] = bag[i];
  111.             }
  112.             tempBag[tempBag.Length - 1] = '!';
  113.             bag = tempBag;
  114.             return bag;
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement