Advertisement
Guest User

420

a guest
Feb 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02.Sneaking
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             //Initial setup and room(matrix) setup
  12.             var rows = int.Parse(Console.ReadLine());
  13.             var room = new char[rows][];
  14.  
  15.             var samRow = 0;
  16.             var samIndex = 0;
  17.  
  18.             for (int i = 0; i < rows; i++)
  19.             {
  20.                 char[] layout = Console.ReadLine().ToArray();
  21.                 room[i] = layout;
  22.  
  23.                 for (int j = 0; j < room[i].Length; j++)
  24.                 {
  25.                     if (room[i][j] == 'S')
  26.                     {
  27.                         samRow = i;
  28.                         samIndex = j;
  29.                     }
  30.                 }
  31.             }
  32.  
  33.             //Getting the moves and starting the game
  34.             var moves = Console.ReadLine();
  35.            
  36.             var nRow = 0;
  37.             var nIndex = 0;
  38.  
  39.             foreach (var move in moves)
  40.             {
  41.                 for (int i = 0; i < rows; i++)
  42.                 {
  43.                     //Move enemies and set Nikoladze's position
  44.                     for (int j = 0; j < room[i].Length; j++)
  45.                     {
  46.                         //Set Nikoladze's position
  47.                         if (room[i].ElementAt(j) == 'N')
  48.                         {
  49.                             nRow = i;
  50.                             nIndex = j;
  51.                         }
  52.  
  53.                         //Enemies 'd' Ai
  54.                         if (room[i].ElementAt(j) == 'd')
  55.                         {
  56.                             var enemyRow = i;
  57.                             var enemyIndex = j;
  58.                             if (enemyIndex == 0)
  59.                             {
  60.                                 room[i][j] = 'b';
  61.                             }
  62.                             else
  63.                             {
  64.                                 room[i][j] = '.';
  65.                                 room[i][j - 1] = 'd';
  66.                             }
  67.  
  68.                             continue;
  69.                         }
  70.  
  71.                         //Enemies 'b' Ai
  72.                         if (room[i].ElementAt(j) == 'b')
  73.                         {
  74.                             var enemyRow = i;
  75.                             var enemyIndex = j;
  76.                             if (enemyIndex == room[i].Length - 1)
  77.                             {
  78.                                 room[i][j] = 'd';
  79.                             }
  80.                             else
  81.                             {
  82.                                 room[i][j] = '.';
  83.                                 room[i][j + 1] = 'b';
  84.                                 j++;
  85.                             }
  86.                         }
  87.                     }                  
  88.                 }
  89.  
  90.                 //Move Sam
  91.                 if (move == 'U')
  92.                 {
  93.                     for (int i = 0; i < samIndex; i++)
  94.                     {
  95.                         if (room[samRow][i] == 'b')
  96.                         {
  97.                             //tuka pravish console write line i resultati i laina shtoto Sam umira
  98.                             return;
  99.                         }
  100.                     }
  101.  
  102.                     for (int i = samIndex + 1; i < room[samRow].Length; i++)
  103.                     {
  104.                         if (room[samRow][i] == 'd')
  105.                         {
  106.                             //tuka pravish console write line i resultati i laina shtoto Sam umira
  107.                             return;
  108.                         }
  109.                     }
  110.  
  111.                     room[samRow][samIndex] = '.';
  112.                     samRow--;
  113.                     room[samRow][samIndex] = 'S';
  114.  
  115.                     if (samRow == nRow)
  116.                     {
  117.                         room[nRow][nIndex] = 'X';
  118.                         //tuka umira Nikoladze i pak pishes resultata
  119.                         return;
  120.                     }
  121.                 }
  122.  
  123.                 if (move == 'D')
  124.                 {
  125.                     for (int i = 0; i < samIndex; i++)
  126.                     {
  127.                         if (room[samRow][i] == 'b')
  128.                         {
  129.                             //tuka pravish console write line i resultati i laina shtoto Sam umira
  130.                             return;
  131.                         }
  132.                     }
  133.  
  134.                     for (int i = samIndex + 1; i < room[samRow].Length; i++)
  135.                     {
  136.                         if (room[samRow][i] == 'd')
  137.                         {
  138.                             //tuka pravish console write line i resultati i laina shtoto Sam umira
  139.                             return;
  140.                         }
  141.                     }
  142.  
  143.                     room[samRow][samIndex] = '.';
  144.                     samRow++;
  145.                     room[samRow][samIndex] = 'S';
  146.  
  147.                     if (samRow == nRow)
  148.                     {
  149.                         room[nRow][nIndex] = 'X';
  150.                         //tuka umira Nikoladze i pak pishes resultata
  151.                         return;
  152.                     }
  153.                 }
  154.  
  155.                 if (move == 'L')
  156.                 {
  157.                     for (int i = 0; i < samIndex; i++)
  158.                     {
  159.                         if (room[samRow][i] == 'b')
  160.                         {
  161.                             //tuka pravish console write line i resultati i laina shtoto Sam umira
  162.                             return;
  163.                         }
  164.                     }
  165.  
  166.                     for (int i = samIndex + 1; i < room[samRow].Length; i++)
  167.                     {
  168.                         if (room[samRow][i] == 'd')
  169.                         {
  170.                             //tuka pravish console write line i resultati i laina shtoto Sam umira
  171.                             return;
  172.                         }
  173.                     }
  174.  
  175.                     room[samRow][samIndex] = '.';
  176.                     samIndex--;
  177.                     room[samRow][samIndex] = 'S';
  178.  
  179.                     if (samRow == nRow)
  180.                     {
  181.                         room[nRow][nIndex] = 'X';
  182.                         //tuka umira Nikoladze i pak pishes resultata
  183.                         return;
  184.                     }
  185.                 }
  186.  
  187.                 if (move == 'R')
  188.                 {
  189.                     for (int i = 0; i < samIndex; i++)
  190.                     {
  191.                         if (room[samRow][i] == 'b')
  192.                         {
  193.                             //tuka pravish console write line i resultati i laina shtoto Sam umira
  194.                             return;
  195.                         }
  196.                     }
  197.  
  198.                     for (int i = samIndex + 1; i < room[samRow].Length; i++)
  199.                     {
  200.                         if (room[samRow][i] == 'd')
  201.                         {
  202.                             //tuka pravish console write line i resultati i laina shtoto Sam umira
  203.                             return;
  204.                         }
  205.                     }
  206.  
  207.                     room[samRow][samIndex] = '.';
  208.                     samIndex++;
  209.                     room[samRow][samIndex] = 'S';
  210.  
  211.                     if (samRow == nRow)
  212.                     {
  213.                         room[nRow][nIndex] = 'X';
  214.                         //tuka umira Nikoladze i pak pishes resultata
  215.                         return;
  216.                     }
  217.                 }
  218.  
  219.                 if (move == 'W')
  220.                 {
  221.                     for (int i = 0; i < samIndex; i++)
  222.                     {
  223.                         if (room[samRow][i] == 'b')
  224.                         {
  225.                             //tuka pravish console write line i resultati i laina shtoto Sam umira
  226.                             return;
  227.                         }
  228.                     }
  229.  
  230.                     for (int i = samIndex + 1; i < room[samRow].Length; i++)
  231.                     {
  232.                         if (room[samRow][i] == 'd')
  233.                         {
  234.                             //tuka pravish console write line i resultati i laina shtoto Sam umira
  235.                             return;
  236.                         }
  237.                     }
  238.  
  239.                     if (samRow == nRow)
  240.                     {
  241.                         room[nRow][nIndex] = 'X';
  242.                         //tuka umira Nikoladze i pak pishes resultata
  243.                         return;
  244.                     }
  245.                 }
  246.             }
  247.  
  248.             /* TUK SA METODITE KOITO AKO BESHE POGLEDNAL ZA 1MINUTA SHTESHE DA RAZBERESH
  249.             //Print Result function
  250.             void PrintResult()
  251.             {
  252.                 foreach (var row in room)
  253.                 {
  254.                     if (row.Contains('S'))
  255.                     {
  256.                         Console.WriteLine("Nikoladze killed!");
  257.                         break;
  258.                     }
  259.                     if (row.Contains('N'))
  260.                     {
  261.                         Console.WriteLine($"Sam died at {samRow}, {samIndex}");
  262.                         break;
  263.                     }
  264.                 }
  265.                 foreach (var row in room)
  266.                 {
  267.                     Console.WriteLine(row);
  268.                 }
  269.                 return;
  270.             }
  271.  
  272.             //Caugth by enemy
  273.             bool CaughtByEnemy(char[][] field, int rowSam, int colSam)
  274.             {
  275.                 for (int col = 0; col < colSam; col++)
  276.                 {
  277.                     if (field[rowSam][col] == 'b')
  278.                     {
  279.                         return true;
  280.                     }
  281.                 }
  282.  
  283.                 for (int col = colSam + 1; col < field[rowSam].Length; col++)
  284.                 {
  285.                     if (field[rowSam][col] == 'd')
  286.                     {
  287.                         return true;
  288.                     }
  289.                 }
  290.  
  291.                 return false;
  292.             }
  293.  
  294.             //Nikoladze killed
  295.             bool NikoladzeKilled()
  296.             {
  297.                 if (samRow == nRow)
  298.                 {
  299.                     room[nRow][nIndex] = 'X';
  300.                     return true;
  301.                 }
  302.  
  303.                 return false;
  304.             }*/
  305.         }
  306.     }
  307. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement