Advertisement
RedFlys

Home Work 3.1

Nov 5th, 2019
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.80 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.                         Console.SetCursorPosition(0, 0);
  77.                         for (int i = 0; i < map1.GetLength(0); i++)
  78.                         {
  79.                             for (int j = 0; j < map1.GetLength(1); j++)
  80.                             {
  81.                                 Console.Write(map1[i, j]);
  82.                             }
  83.                             Console.WriteLine();
  84.                         }
  85.  
  86.                         Console.SetCursorPosition(0, 20);
  87.                         Console.WriteLine("Собранные сокровища:");
  88.                         for (int i = 0; i < bag.Length; i++)
  89.                         {
  90.                             Console.Write(bag[i] + ", ");
  91.                         }
  92.  
  93.                         Console.SetCursorPosition(userY, userX);
  94.                         Console.Write('X');
  95.  
  96.                         ConsoleKeyInfo consoleKey = Console.ReadKey();
  97.  
  98.                         switch (consoleKey.Key)
  99.                         {
  100.                             case ConsoleKey.LeftArrow:
  101.                                 if (map1[userX, userY - 1] != '#')
  102.                                 {
  103.                                     userY--;
  104.                                 }
  105.                                 break;
  106.                             case ConsoleKey.RightArrow:
  107.                                 if (map1[userX, userY + 1] != '#')
  108.                                 {
  109.                                     userY++;
  110.                                 }
  111.                                 break;
  112.                             case ConsoleKey.UpArrow:
  113.                                 if (map1[userX - 1, userY] != '#')
  114.                                 {
  115.                                     userX--;
  116.                                 }
  117.                                 break;
  118.                             case ConsoleKey.DownArrow:
  119.                                 if (map1[userX + 1, userY] != '#')
  120.                                 {
  121.                                     userX++;
  122.                                 }
  123.                                 break;
  124.                         }
  125.  
  126.                         if (map1[userX, userY] == '$')
  127.                         {
  128.                             map1[userX, userY] = 'o';
  129.  
  130.                             char[] tempBag = new char[bag.Length + 1];
  131.                             for (int i = 0; i < bag.Length; i++)
  132.                             {
  133.                                 tempBag[i] = bag[i];
  134.                             }
  135.                             tempBag[tempBag.Length - 1] = '$';
  136.  
  137.                             bag = tempBag;
  138.                         }
  139.  
  140.                         if (bag.Length == 2)
  141.                         {
  142.                             Console.Clear();
  143.                             level++;
  144.                             break;
  145.                         }
  146.                     }
  147.                 }
  148.                 else if (level == 2)
  149.                 {
  150.                     while (true)
  151.                     {
  152.                         Console.SetCursorPosition(0, 0);
  153.                         for (int i = 0; i < map2.GetLength(0); i++)
  154.                         {
  155.                             for (int j = 0; j < map2.GetLength(1); j++)
  156.                             {
  157.                                 Console.Write(map2[i, j]);
  158.                             }
  159.                             Console.WriteLine();
  160.                         }
  161.  
  162.                         Console.SetCursorPosition(0, 23);
  163.                         Console.WriteLine("Не касайтесь шипов!\n");
  164.                         Console.WriteLine("Собранные сокровища:");
  165.                         for (int i = 0; i < bag.Length; i++)
  166.                         {
  167.                             Console.Write(bag[i] + ", ");
  168.                         }
  169.  
  170.                         Console.SetCursorPosition(userY, userX);
  171.                         Console.Write('X');
  172.  
  173.                         ConsoleKeyInfo consoleKey = Console.ReadKey();
  174.  
  175.                         switch (consoleKey.Key)
  176.                         {
  177.                             case ConsoleKey.LeftArrow:
  178.                                 if (map1[userX, userY - 1] != '#')
  179.                                 {
  180.                                     userY--;
  181.                                 }
  182.                                 break;
  183.                             case ConsoleKey.RightArrow:
  184.                                 if (map1[userX, userY + 1] != '#')
  185.                                 {
  186.                                     userY++;
  187.                                 }
  188.                                 break;
  189.                             case ConsoleKey.UpArrow:
  190.                                 if (map1[userX - 1, userY] != '#')
  191.                                 {
  192.                                     userX--;
  193.                                 }
  194.                                 break;
  195.                             case ConsoleKey.DownArrow:
  196.                                 if (map1[userX + 1, userY] != '#')
  197.                                 {
  198.                                     userX++;
  199.                                 }
  200.                                 break;
  201.                         }
  202.  
  203.                         if (map2[userX, userY] == '$')
  204.                         {
  205.                             map2[userX, userY] = 'o';
  206.  
  207.                             char[] tempBag = new char[bag.Length + 1];
  208.                             for (int i = 0; i < bag.Length; i++)
  209.                             {
  210.                                 tempBag[i] = bag[i];
  211.                             }
  212.                             tempBag[tempBag.Length - 1] = '$';
  213.  
  214.                             bag = tempBag;
  215.                         }
  216.  
  217.                         if (map2[userX, userY] == '!')
  218.                         {
  219.                             Console.Clear();
  220.                             Console.WriteLine("Вы проиграли, не касайтесь шипов!");
  221.                             Console.ReadKey();
  222.                             userX = 1;
  223.                             userY = 1;
  224.                             Console.Clear();
  225.                             continue;
  226.                         }
  227.  
  228.                             if (bag.Length == 4)
  229.                         {
  230.                             Console.Clear();
  231.                             level++;
  232.                             break;
  233.                         }
  234.                     }
  235.                 }
  236.                 else if (level == 3)
  237.                 {
  238.                     while (true)
  239.                     {
  240.                         Console.SetCursorPosition(0, 0);
  241.                         for (int i = 0; i < map3.GetLength(0); i++)
  242.                         {
  243.                             for (int j = 0; j < map3.GetLength(1); j++)
  244.                             {
  245.                                 Console.Write(map3[i, j]);
  246.                             }
  247.                             Console.WriteLine();
  248.                         }
  249.  
  250.                         Console.SetCursorPosition(0, 23);
  251.                         Console.WriteLine("Что бы перепрыгнуть пропасть - встаньте у края и нажмите Space\n");
  252.                         Console.WriteLine("Собранные сокровища:");
  253.                         for (int i = 0; i < bag.Length; i++)
  254.                         {
  255.                             Console.Write(bag[i] + ", ");
  256.                         }
  257.  
  258.                         Console.SetCursorPosition(userY, userX);
  259.                         Console.Write('X');
  260.  
  261.                         ConsoleKeyInfo consoleKey = Console.ReadKey();
  262.  
  263.                         switch (consoleKey.Key)
  264.                         {
  265.                             case ConsoleKey.LeftArrow:
  266.                                 if (map3[userX, userY - 1] != '#')
  267.                                 {
  268.                                     userY--;
  269.                                 }
  270.                                 break;
  271.                             case ConsoleKey.RightArrow:
  272.                                 if (map3[userX, userY + 1] != '#' && map3[userX, userY + 1] != '|')
  273.                                 {
  274.                                     userY++;
  275.                                 }
  276.                                 break;
  277.                             case ConsoleKey.UpArrow:
  278.                                 if (map3[userX - 1, userY] != '#')
  279.                                 {
  280.                                     userX--;
  281.                                 }
  282.                                 break;
  283.                             case ConsoleKey.DownArrow:
  284.                                 if (map3[userX + 1, userY] != '#')
  285.                                 {
  286.                                     userX++;
  287.                                 }
  288.                                 break;
  289.                             case ConsoleKey.Spacebar:
  290.                                 if (map3[userX, userY + 1] == '|')
  291.                                 {
  292.                                     userY += 3;
  293.                                 }
  294.                                 break;
  295.                         }
  296.  
  297.                         if (map3[userX, userY] == '$')
  298.                         {
  299.                             map3[userX, userY] = 'o';
  300.  
  301.                             char[] tempBag = new char[bag.Length + 1];
  302.                             for (int i = 0; i < bag.Length; i++)
  303.                             {
  304.                                 tempBag[i] = bag[i];
  305.                             }
  306.                             tempBag[tempBag.Length - 1] = '$';
  307.  
  308.                             bag = tempBag;
  309.                         }
  310.  
  311.                         if (map3[userX, userY] == '!')
  312.                         {
  313.                             Console.Clear();
  314.                             Console.WriteLine("Вы проиграли, не касайтесь шипов!");
  315.                             Console.ReadKey();
  316.                             userX = 1;
  317.                             userY = 1;
  318.                             Console.Clear();
  319.                             continue;
  320.                         }
  321.  
  322.                         if (bag.Length == 5)
  323.                         {
  324.                             Console.Clear();
  325.                             level++;
  326.                             break;
  327.                         }
  328.                     }
  329.                     if (level == 4)
  330.                     {
  331.                         Console.WriteLine("Спасибо за то, что играли в демо-версию");
  332.                         Console.ReadKey();
  333.                         break;
  334.                     }
  335.                 }
  336.             }
  337.         }
  338.     }
  339. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement