Advertisement
MrVeiran

braw new world

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