Advertisement
RedFlys

Home Work 4.4

Nov 8th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.03 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 FifthProject
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.CursorVisible = false;
  14.             int level = 1;
  15.  
  16.             char[,] map1 =
  17.             {
  18.                 {'#','#','#','#','#','#','#','#','#','#','#' },
  19.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  20.                 {'#',' ',' ',' ',' ',' ','$',' ',' ',' ','#' },
  21.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  22.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  23.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  24.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  25.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  26.                 {'#',' ',' ',' ',' ',' ','$',' ',' ',' ','#' },
  27.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  28.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  29.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  30.                 {'#','#','#','#','#','#','#','#','#','#','#' }
  31.             };
  32.  
  33.             char[,] map2 =
  34.             {
  35.                 {'#','#','#','#','#','#','#','#','#','#' },
  36.                 {'#',' ',' ','!',' ',' ',' ','!','!','#' },
  37.                 {'#','!',' ','!',' ','!','$','!','!','#' },
  38.                 {'#','!',' ','!',' ','!','!','!','!','#' },
  39.                 {'#','!',' ','!',' ',' ',' ',' ','!','#' },
  40.                 {'#','!',' ','!','!','!','!',' ','!','#' },
  41.                 {'#','!',' ','!',' ',' ',' ',' ','!','#' },
  42.                 {'#','!',' ','!',' ','!','!','!','!','#' },
  43.                 {'#',' ',' ','!',' ',' ','$','!','!','#' },
  44.                 {'#',' ','!','!','!','!',' ','!','!','#' },
  45.                 {'#',' ','!','!','!','!',' ','!','!','#' },
  46.                 {'#',' ',' ',' ',' ',' ',' ','!','!','#' },
  47.                 {'#','#','#','#','#','#','#','#','#','#' }
  48.             };
  49.  
  50.             char[,] map3 =
  51.             {
  52.                 {'#','#','#','#','#','#','#','#','#','#','#' },
  53.                 {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
  54.                 {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
  55.                 {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
  56.                 {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
  57.                 {'#',' ',' ',' ','|','|',' ',' ','!','$','#' },
  58.                 {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
  59.                 {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
  60.                 {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
  61.                 {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
  62.                 {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
  63.                 {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
  64.                 {'#','#','#','#','#','#','#','#','#','#','#' }
  65.             };
  66.  
  67.             char[] bag = new char[0];
  68.  
  69.             while (true)
  70.             {
  71.                 int userX = 1, userY = 1;
  72.                 if (level == 1)
  73.                 {
  74.                     while (true)
  75.                     {
  76.                         DrawMap(map1);
  77.  
  78.                         Console.SetCursorPosition(0, 20);
  79.                         Console.WriteLine("Собранные сокровища:");
  80.                         for (int i = 0; i < bag.Length; i++)
  81.                         {
  82.                             Console.Write(bag[i] + ", ");
  83.                         }
  84.  
  85.                         Console.SetCursorPosition(userY, userX);
  86.                         Console.Write('X');
  87.  
  88.                         PlayerControl(map1, ref userY, ref userX);
  89.  
  90.                         bag = Bag(map1, userX, userY, bag);
  91.  
  92.                         if (bag.Length == 2)
  93.                         {
  94.                             level = Finish(level);
  95.                             break;
  96.                         }
  97.                     }
  98.                 }
  99.                 else if (level == 2)
  100.                 {
  101.                     while (true)
  102.                     {
  103.                         DrawMap(map2);
  104.  
  105.                         Console.SetCursorPosition(0, 23);
  106.                         Console.WriteLine("Не касайтесь шипов!\n");
  107.                         Console.WriteLine("Собранные сокровища:");
  108.                         for (int i = 0; i < bag.Length; i++)
  109.                         {
  110.                             Console.Write(bag[i] + ", ");
  111.                         }
  112.  
  113.                         Console.SetCursorPosition(userY, userX);
  114.                         Console.Write('X');
  115.  
  116.                         PlayerControl(map2, ref userY, ref userX);
  117.  
  118.                         bag = Bag(map2, userX, userY, bag);
  119.  
  120.                         if (map2[userX, userY] == '!')
  121.                         {
  122.                             Spikes(ref userX, ref userY);
  123.                             continue;
  124.                         }
  125.  
  126.                         if (bag.Length == 4)
  127.                         {
  128.                             level = Finish(level);
  129.                             break;
  130.                         }
  131.                     }
  132.                 }
  133.                 else if (level == 3)
  134.                 {
  135.                     while (true)
  136.                     {
  137.                         DrawMap(map3);
  138.  
  139.                         Console.SetCursorPosition(0, 23);
  140.                         Console.WriteLine("Что бы перепрыгнуть пропасть - встаньте у края и нажмите Space\n");
  141.                         Console.WriteLine("Собранные сокровища:");
  142.                         for (int i = 0; i < bag.Length; i++)
  143.                         {
  144.                             Console.Write(bag[i] + ", ");
  145.                         }
  146.  
  147.                         Console.SetCursorPosition(userY, userX);
  148.                         Console.Write('X');
  149.  
  150.                         PlayerControl(map3, ref userY, ref userX);
  151.  
  152.                         bag = Bag(map3, userX, userY, bag);
  153.  
  154.                         if (map3[userX, userY] == '!')
  155.                         {
  156.                             Spikes(ref userX, ref userY);
  157.                             continue;
  158.                         }
  159.  
  160.                         if (bag.Length == 5)
  161.                         {
  162.                             level = Finish(level);
  163.                             break;
  164.                         }
  165.                     }
  166.                 }
  167.                 if (level == 4)
  168.                 {
  169.                     Console.WriteLine("Спасибо за то, что играли в демо-версию");
  170.                     Console.ReadKey();
  171.                     break;                
  172.                 }
  173.             }
  174.         }
  175.  
  176.         static void DrawMap(char[,] map)
  177.         {
  178.             Console.SetCursorPosition(0, 0);
  179.             for (int i = 0; i < map.GetLength(0); i++)
  180.             {
  181.                 for (int j = 0; j < map.GetLength(1); j++)
  182.                 {
  183.                     Console.Write(map[i, j]);
  184.                 }
  185.                 Console.WriteLine();
  186.             }
  187.         }
  188.  
  189.         static void PlayerControl(char[,] map, ref int userY, ref int userX)
  190.         {
  191.             ConsoleKeyInfo consoleKey = Console.ReadKey();
  192.  
  193.             switch (consoleKey.Key)
  194.             {
  195.                 case ConsoleKey.LeftArrow:
  196.                     if (map[userX, userY - 1] != '#')
  197.                     {
  198.                         userY--;
  199.                     }
  200.                     break;
  201.                 case ConsoleKey.RightArrow:
  202.                     if (map[userX, userY + 1] != '#' && map[userX, userY + 1] != '|')
  203.                     {
  204.                         userY++;
  205.                     }
  206.                     break;
  207.                 case ConsoleKey.UpArrow:
  208.                     if (map[userX - 1, userY] != '#')
  209.                     {
  210.                         userX--;
  211.                     }
  212.                     break;
  213.                 case ConsoleKey.DownArrow:
  214.                     if (map[userX + 1, userY] != '#')
  215.                     {
  216.                         userX++;
  217.                     }
  218.                     break;
  219.                 case ConsoleKey.Spacebar:
  220.                     if (map[userX, userY + 1] == '|')
  221.                     {
  222.                         userY += 3;
  223.                     }
  224.                     break;
  225.             }
  226.         }
  227.  
  228.         static char[] Bag(char[,] map, int userX, int userY, char[] bag)
  229.         {
  230.             if (map[userX, userY] == '$')
  231.             {
  232.                 map[userX, userY] = 'o';
  233.  
  234.                 char[] tempBag = new char[bag.Length + 1];
  235.                 for (int i = 0; i < bag.Length; i++)
  236.                 {
  237.                     tempBag[i] = bag[i];
  238.                 }
  239.                 tempBag[tempBag.Length - 1] = '$';
  240.  
  241.                 bag = tempBag;
  242.             }
  243.             return bag;
  244.         }
  245.  
  246.         static int Finish (int level)
  247.         {
  248.             Console.Clear();
  249.             level++;
  250.             return level;
  251.         }
  252.  
  253.         static void Spikes(ref int userX, ref int userY)
  254.         {
  255.             Console.Clear();
  256.             Console.WriteLine("Вы проиграли, не касайтесь шипов!");
  257.             Console.ReadKey();
  258.             userX = 1;
  259.             userY = 1;
  260.             Console.Clear();
  261.         }
  262.     }
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement