Advertisement
OwlyOwl

brodilka_huilka

Mar 28th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.24 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[] bag = new char[0];
  12.             char[,] map =
  13.             {
  14.                 {'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*', },
  15.                 {'*',' ','$','*',' ',' ',' ','$','*',' ','$',' ',' ','*',' ','*',' ','*', },
  16.                 {'*',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ','$','*', },
  17.                 {'*',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ','*','*', },
  18.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ','*', },
  19.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ','*', },
  20.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ','*', },
  21.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  22.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  23.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  24.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  25.                 {'*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  26.                 {'*',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  27.                 {'*',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*', },
  28.                 {'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*', },
  29.             };
  30.             while (true)
  31.             {
  32.                 {
  33.                     Console.SetCursorPosition(0, 18);
  34.                     Console.Write("Bag:");
  35.                     for (int i = 0; i < bag.Length; i++)
  36.                     {
  37.                         Console.Write(bag[i] + " ");
  38.                     }
  39.                     DrawMap(map);
  40.                     Console.SetCursorPosition(userY, userX);
  41.                     Console.Write('@');
  42.                     ConsoleKeyInfo charKey = Console.ReadKey();
  43.                     switch (charKey.Key)
  44.                     {
  45.                         case ConsoleKey.UpArrow:
  46.                             if (map[userX - 1, userY] != '*')
  47.                             {
  48.                                 userX--;
  49.                             }
  50.                             break;
  51.                         case ConsoleKey.DownArrow:
  52.                             if (map[userX + 1, userY] != '*')
  53.                             {
  54.                                 userX++;
  55.                             }
  56.                             break;
  57.                         case ConsoleKey.LeftArrow:
  58.                             if (map[userX, userY - 1] != '*')
  59.                             {
  60.                                 userY--;
  61.                             }
  62.                             break;
  63.                         case ConsoleKey.RightArrow:
  64.                             if (map[userX, userY + 1] != '*')
  65.                             {
  66.                                 userY++;
  67.                             }
  68.                             break;
  69.                     }
  70.                     if (map[userX, userY] == '$')
  71.                     {
  72.                         map[userX, userY] = '^';
  73.                         char[] tempBag = new char[bag.Length + 1];
  74.                         for (int i = 0; i < bag.Length; i++)
  75.                         {
  76.                             tempBag[i] = bag[i];
  77.                         }
  78.                         tempBag[tempBag.Length - 1] = '$';
  79.                         bag = tempBag;
  80.                     }
  81.                     Console.Clear();
  82.                 }
  83.             }
  84.             static void DrawMap(char[,] map1)
  85.             {
  86.                 Console.SetCursorPosition(0, 0);
  87.                 for (int i = 0; i < map1.GetLength(0); i++)
  88.                 {
  89.                     for (int j = 0; j < map1.GetLength(1); j++)
  90.                     {
  91.                         Console.Write(map1[i, j]);
  92.                     }
  93.                     Console.WriteLine();
  94.                 }
  95.             }
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement