Advertisement
RedFlys

CSharpLight HomeWork22 - Brave new world

Nov 15th, 2020 (edited)
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.14 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSharpLight_HomeWork22_Brave_new_world
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.CursorVisible = false;
  10.  
  11.             int userX = 1;
  12.             int userY = 1;
  13.             int userDX = 0;
  14.             int userDY = 0;
  15.             char[,] map;
  16.             char[] bag = new char[0];
  17.  
  18.             map = SetMap1();
  19.  
  20.             while(true)
  21.             {        
  22.                 while(true)
  23.                 {
  24.                     Console.SetCursorPosition(0, 0);
  25.                     DrawMap(map);
  26.  
  27.                     Console.SetCursorPosition(0, 20);
  28.                     DrawBag(bag);
  29.  
  30.                     Console.SetCursorPosition(userX, userY);
  31.                     Console.Write('X');
  32.  
  33.                     MovePlayer(map, ref userY, ref  userX);
  34.  
  35.                     if (map[userY, userX] == '$')
  36.                     {
  37.                         map[userY, userX] = 'o';
  38.                         bag = AddMoney(bag);
  39.                     }
  40.  
  41.                     if (map[userY, userX] == '!')
  42.                     {
  43.                         TouchBlow(ref userY, ref userX);
  44.                         continue;
  45.                     }
  46.  
  47.                     if (bag.Length == 2)
  48.                     {
  49.                         map = SetMap2();
  50.                         continue;
  51.                     }
  52.                     else if (bag.Length == 4)
  53.                     {
  54.                         map = SetMap3();
  55.                         continue;
  56.                     }
  57.                     else if (bag.Length == 5)                      
  58.                     {
  59.                         break;
  60.                     }
  61.                 }
  62.  
  63.                 if (bag.Length == 5)
  64.                     break;
  65.             }
  66.             Console.Clear();
  67.             Console.WriteLine("Поздравляю, вы прошли игру!");
  68.             Console.ReadKey();
  69.         }
  70.  
  71.         static void DrawMap(char[,] map)
  72.         {
  73.             for (int i = 0; i < map.GetLength(0); i++)
  74.             {
  75.                 for (int j = 0; j < map.GetLength(1); j++)
  76.                 {
  77.                     Console.Write(map[i, j]);
  78.                 }
  79.                 Console.WriteLine();
  80.             }
  81.             Console.WriteLine();
  82.             Console.WriteLine("Двигайся на стрелочки. Не косайся шипов(!). Перепгнуть пропасть - space.");
  83.         }
  84.  
  85.         static void DrawBag(char[] bag)
  86.         {
  87.             Console.WriteLine("Собранные сокровища: ");
  88.             for(int i = 0; i < bag.Length; i++)
  89.             {
  90.                 Console.WriteLine(bag[i] + ", ");
  91.             }
  92.         }
  93.  
  94.         static void MovePlayer(char[,] map,  ref int userX, ref int userY)
  95.         {
  96.             int DX = 0;
  97.             int DY = 0;
  98.             ConsoleKeyInfo consoleKey = Console.ReadKey();
  99.  
  100.             switch (consoleKey.Key)
  101.             {
  102.                 case ConsoleKey.UpArrow:
  103.                     DX = -1;
  104.                     break;
  105.                 case ConsoleKey.DownArrow:
  106.                     DX = 1;
  107.                     break;
  108.                 case ConsoleKey.LeftArrow:
  109.                     DY = -1;
  110.                     break;
  111.                 case ConsoleKey.RightArrow:
  112.                     DY = 1;
  113.                     break;
  114.                 case ConsoleKey.Spacebar:
  115.                     DY = 3;
  116.                     break;
  117.             }
  118.  
  119.             if(map[userX + DX, userY + DY] != '#' && map[userX + DX, userY + DY] != '|')
  120.             {
  121.                 userX += DX;
  122.                 userY += DY;
  123.             }
  124.         }
  125.  
  126.         static char[] AddMoney(char[] bag)
  127.         {
  128.             char[] tempBag = new char[bag.Length + 1];
  129.             for (int i = 0; i < bag.Length; i++)
  130.             {
  131.                 tempBag[i] = bag[i];
  132.             }
  133.             tempBag[tempBag.Length - 1] = '$';
  134.  
  135.             return tempBag;
  136.         }
  137.  
  138.         static void TouchBlow(ref int userX, ref int userY)
  139.         {
  140.             Console.Clear();
  141.             Console.WriteLine("Вы проиграли, не касайтесь шипов!");
  142.             Console.ReadKey();
  143.             userX = 1;
  144.             userY = 1;
  145.             Console.Clear();
  146.         }
  147.  
  148.         static char[,] SetMap1()
  149.         {
  150.             char[,] map =
  151.             {
  152.                 {'#','#','#','#','#','#','#','#','#','#','#' },
  153.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  154.                 {'#',' ',' ',' ',' ',' ','$',' ',' ',' ','#' },
  155.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  156.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  157.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  158.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  159.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  160.                 {'#',' ',' ',' ',' ',' ','$',' ',' ',' ','#' },
  161.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  162.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  163.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  164.                 {'#','#','#','#','#','#','#','#','#','#','#' }
  165.             };
  166.  
  167.             return map;
  168.         }
  169.  
  170.         static char[,] SetMap2()
  171.         {
  172.             char[,] map =
  173.             {
  174.                 {'#','#','#','#','#','#','#','#','#','#' },
  175.                 {'#','$',' ','!',' ',' ',' ','!','!','#' },
  176.                 {'#','!',' ','!',' ','!','$','!','!','#' },
  177.                 {'#','!',' ','!',' ','!','!','!','!','#' },
  178.                 {'#','!',' ','!',' ',' ',' ',' ','!','#' },
  179.                 {'#','!',' ','!','!','!','!',' ','!','#' },
  180.                 {'#','!',' ','!',' ',' ',' ',' ','!','#' },
  181.                 {'#','!',' ','!',' ','!','!','!','!','#' },
  182.                 {'#',' ',' ','!',' ',' ',' ','!','!','#' },
  183.                 {'#',' ','!','!','!','!',' ','!','!','#' },
  184.                 {'#',' ','!','!','!','!',' ','!','!','#' },
  185.                 {'#',' ',' ',' ',' ',' ',' ','!','!','#' },
  186.                 {'#','#','#','#','#','#','#','#','#','#' }
  187.             };
  188.  
  189.             return map;
  190.         }
  191.  
  192.         static char[,] SetMap3()
  193.         {
  194.             char[,] map =
  195.             {
  196.                 {'#','#','#','#','#','#','#','#','#','#','#' },
  197.                 {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
  198.                 {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
  199.                 {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
  200.                 {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
  201.                 {'#',' ',' ',' ','|','|',' ',' ','!','$','#' },
  202.                 {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
  203.                 {'#',' ',' ',' ','|','|',' ',' ','!',' ','#' },
  204.                 {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
  205.                 {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
  206.                 {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
  207.                 {'#',' ',' ',' ','|','|',' ',' ',' ',' ','#' },
  208.                 {'#','#','#','#','#','#','#','#','#','#','#' }
  209.             };
  210.  
  211.             return map;
  212.         }
  213.     }
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement