Advertisement
Seeptim

Lesson_3_2

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