Advertisement
EvgeniVT

Radioactive Mutant Vampire Bunnies V.2

Sep 27th, 2019
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.86 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Radioactive_Mutant_Vampire_Bunnies
  5. {
  6.     class Program
  7.     {
  8.         static byte rows;
  9.         static byte cols;      
  10.         static char[][][] matrix;
  11.         static byte pRow;
  12.         static byte pCol;
  13.         static bool live = true;
  14.         static bool win = false;
  15.         static void Main()
  16.         {
  17.             var nxm = Console.ReadLine()
  18.                 .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  19.                 .Select(byte.Parse)
  20.                 .ToArray();
  21.             rows = nxm[0];
  22.             cols = nxm[1];          
  23.             matrix = new char[rows][][];
  24.             for (byte row = 0; row < rows; row++)
  25.             {
  26.                 matrix[row] = new char[cols][];
  27.                 var input = Console.ReadLine()                  
  28.                     .ToCharArray();        
  29.                 for (byte col = 0; col < cols; col++)
  30.                 {
  31.                     matrix[row][col] = new char[2];
  32.                     matrix[row][col][0] = input[col];
  33.                     if (input[col] == 'P')
  34.                     {
  35.                         pRow = row;
  36.                         pCol = col;
  37.                     }
  38.                     else if (input[col] == 'B')
  39.                     {
  40.                         matrix[row][col][1] = input[col];
  41.                     }
  42.                 }
  43.             }
  44.             var comm= Console.ReadLine();
  45.             foreach (var cha in comm)
  46.             {
  47.                 Move(cha);
  48.                 Spare();
  49.                 OldB();
  50.                 if (win)
  51.                 {
  52.                     Print();
  53.                     Console.WriteLine($"won: {pRow} {pCol}");
  54.                     break;
  55.                 }
  56.                 if (!live)
  57.                 {
  58.                     Print();
  59.                     Console.WriteLine($"dead: {pRow} {pCol}");
  60.                     break;
  61.                 }                
  62.             }
  63.         }
  64.         private static void OldB()
  65.         {
  66.             for (byte row = 0; row < rows; row++)
  67.             {
  68.                 for (byte col = 0; col < cols; col++)
  69.                 {
  70.                     if (matrix[row][col][0] == 'B')
  71.                     {
  72.                         matrix[row][col][1] = 'B';
  73.                     }
  74.                 }              
  75.             }
  76.         }
  77.         private static void Spare()
  78.         {
  79.             for (byte row = 0; row < rows; row++)
  80.             {
  81.                 for (byte col = 0; col < cols; col++)
  82.                 {
  83.                     if (matrix[row][col][1] == 'B')
  84.                     {
  85.                         var ro = row;
  86.                         var co = col;
  87.                         Buni(--ro, co);
  88.                         ro = row;
  89.                         Buni(ro, ++co);
  90.                         co = col;
  91.                         Buni(++ro, co);
  92.                         ro = row;
  93.                         Buni(ro, --co);
  94.                     }
  95.                 }
  96.             }
  97.         }
  98.         private static void Buni(byte r, byte c)
  99.         {
  100.             if (IsIn(r, c))
  101.             {
  102.                 if (matrix[r][c][0] == 'P') live = false;
  103.                 matrix[r][c][0] = 'B';              
  104.             }
  105.         }
  106.         private static void Move(char ch)
  107.         {
  108.             switch (ch)
  109.             {
  110.                 case 'U':
  111.                     var ro = pRow;
  112.                     Direkt(--ro, pCol);
  113.                     break;
  114.                 case 'D':
  115.                     ro = pRow;
  116.                     Direkt(++ro, pCol);
  117.                     break;
  118.                 case 'R':
  119.                     var co = pCol;
  120.                     Direkt(pRow, ++co);
  121.                     break;
  122.                 case 'L':
  123.                     co = pCol;
  124.                     Direkt(pRow,--co);
  125.                     break;              
  126.             }          
  127.         }
  128.         private static void Direkt(byte r, byte c)
  129.         {
  130.             matrix[pRow][pCol][0] = '.';
  131.             if (IsIn(r, c))
  132.             {
  133.                 if (matrix[r][c][0] == 'B')
  134.                     live = false;
  135.                 else
  136.                     matrix[r][c][0] = 'P';
  137.                 pRow = r;
  138.                 pCol = c;
  139.             }
  140.             else
  141.                 win = true;                    
  142.         }
  143.         static bool IsIn(byte r, byte c)
  144.         {
  145.             if (r >= 0 && r < rows && c >= 0 && c < cols)
  146.                 return true;
  147.             else
  148.                 return false;
  149.         }
  150.         private static void Print()
  151.         {
  152.             for (byte row = 0; row < rows; row++)
  153.             {
  154.                 for (byte col = 0; col < cols; col++)
  155.                 {
  156.                     Console.Write($"{matrix[row][col][0]}");
  157.                 }
  158.                 Console.WriteLine();
  159.             }
  160.         }
  161.     }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement