Benjail

3.2

Aug 30th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.92 KB | None | 0 0
  1. using System;
  2.  
  3. namespace IMJunior
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.CursorVisible = false;
  10.             char[,] map =
  11.             {
  12.                 {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' },
  13.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  14.                 {'#',' ',' ','X',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  15.                 {'#',' ',' ',' ',' ',' ','X',' ',' ',' ',' ','X',' ',' ','#' },
  16.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  17.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  18.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  19.                 {'#',' ','X',' ',' ',' ',' ',' ',' ',' ',' ','X',' ',' ','#' },
  20.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  21.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  22.                 {'#',' ',' ',' ',' ',' ','X',' ',' ',' ',' ',' ',' ',' ','#' },
  23.                 {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' }
  24.             };
  25.  
  26.             char[] bag = new char[0];
  27.             bool gameopen = true;
  28.             int userX = 4, userY = 4;
  29.             int shetchik = 0;            
  30.             for (int i=0;i<map.GetLength(0);i++)
  31.             {
  32.                 for (int j = 0; j < map.GetLength(0); j++)
  33.                 {
  34.                     if (map[i,j] =='X')
  35.                     {
  36.                         shetchik+= 1;
  37.                     }
  38.                 }
  39.             }
  40.  
  41.             while (gameopen==true)
  42.             {
  43.                 Console.SetCursorPosition(0, 0);
  44.                 for (int i = 0; i < map.GetLength(0); i++)
  45.                 {
  46.                     for (int j = 0; j < map.GetLength(1); j++)
  47.                     {
  48.                         Console.Write(map[i, j]);
  49.                     }
  50.                     Console.WriteLine();
  51.                 }
  52.  
  53.                 Console.SetCursorPosition(0, 15);
  54.                 Console.Write("Сумка: ");
  55.                 for (int i = 0; i < bag.Length; i++)
  56.                 {
  57.                     Console.Write(bag[i] + " ");
  58.                 }
  59.  
  60.                 Console.SetCursorPosition(userY, userX);
  61.                 Console.Write('@');
  62.  
  63.                 ConsoleKeyInfo charKey = Console.ReadKey();
  64.  
  65.                 switch (charKey.Key)
  66.                 {
  67.                     case ConsoleKey.UpArrow:
  68.                         if (map[userX - 1, userY] != '#')
  69.                             userX--;
  70.                         break;
  71.                     case ConsoleKey.DownArrow:
  72.                         if (map[userX + 1, userY] != '#')
  73.                             userX++;
  74.                         break;
  75.                     case ConsoleKey.LeftArrow:
  76.                         if (map[userX, userY - 1] != '#')
  77.                             userY--;
  78.                         break;
  79.                     case ConsoleKey.RightArrow:
  80.                         if (map[userX, userY + 1] != '#')
  81.                             userY++;
  82.                         break;
  83.                 }
  84.  
  85.                 if (map[userX, userY] == 'X')
  86.                 {
  87.                     map[userX, userY] = 'o';
  88.  
  89.                     char[] tempBag = new char[bag.Length + 1];
  90.                     for (int i = 0; i < bag.Length; i++)
  91.                     {
  92.                         tempBag[i] = bag[i];  
  93.                     }
  94.                     tempBag[tempBag.Length - 1] = 'X';  
  95.  
  96.                     bag = tempBag;
  97.                 }
  98.                 if(bag.Length== shetchik)
  99.                 {
  100.                     gameopen = false;
  101.                 }
  102.             }
  103.             Console.SetCursorPosition(0,20 );
  104.             Console.WriteLine("Игра окончена! Вы собрали все сокровища!\n");
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment