Advertisement
xlix

Задача 3.2

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