Alexander7337

MatrixProblem

May 28th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.76 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4.  
  5. class MatrixProblem
  6. {
  7.     public static double heiganHealth = 3000000;
  8.     public static int playerHealth = 18500;
  9.    
  10.     //Player
  11.     public static int playerRow = 7;
  12.     public static int playerCol = 7;
  13.  
  14.     //Damage to player
  15.     public static int damageCloud = 3500;
  16.     public static int damageEruption = 6000;
  17.  
  18.     public static void Main()
  19.     {
  20.         SortedDictionary<int, List<int>> damagedCells = new SortedDictionary<int, List<int>>();
  21.         double damageOnHeigan = double.Parse(Console.ReadLine());
  22.  
  23.         bool endGame = false;
  24.         bool hasCloud = false;
  25.         bool hasEruption = false;
  26.         bool hasDiedBySecondCloud = false;
  27.         bool hasEscaped = false;
  28.        
  29.         while (true)
  30.         {
  31.             string[] line = Console.ReadLine().Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  32.             string spell = line[0];
  33.             int hitRow = int.Parse(line[1]);
  34.             int hitCol = int.Parse(line[2]);
  35.  
  36.             heiganHealth -= damageOnHeigan;
  37.             if (heiganHealth <= 0)
  38.             {
  39.                 endGame = true;
  40.             }
  41.  
  42.             if (hasCloud && !hasEscaped)
  43.             {
  44.                 playerHealth -= damageCloud;
  45.                 if (playerHealth <= 0)
  46.                 {
  47.                     hasDiedBySecondCloud = true;
  48.                     endGame = true;
  49.                 }
  50.             }
  51.  
  52.             hasEscaped = false;
  53.  
  54.             if (spell.Equals("Cloud") && !hasDiedBySecondCloud)
  55.             {
  56.                 if (damagedCells.Count != 0)
  57.                 {
  58.                     damagedCells = new SortedDictionary<int, List<int>>();
  59.                 }
  60.                 //damaged cells by Cloud
  61.                 for (int r = hitRow - 1; r <= hitRow + 1; r++)
  62.                 {
  63.                     for (int c = hitCol - 1; c <= hitCol + 1; c++)
  64.                     {
  65.                         if (r >= 0 && r < 15 && c >= 0 && c < 15)
  66.                         {
  67.                             if (!damagedCells.ContainsKey(r))
  68.                             {
  69.                                 damagedCells.Add(r, new List<int>());
  70.                             }
  71.                             damagedCells[r].Add(c);
  72.                         }
  73.                     }
  74.                 }
  75.                 hasCloud = true;
  76.                 hasEruption = false;
  77.  
  78.             }
  79.             //damaged cells by Eruption
  80.             else if (!hasDiedBySecondCloud)
  81.             {
  82.                 if (damagedCells.Count != 0)
  83.                 {
  84.                     damagedCells = new SortedDictionary<int, List<int>>();
  85.                 }
  86.                 for (int r = hitRow - 1; r <= hitRow + 1; r++)
  87.                 {
  88.                     for (int c = hitCol - 1; c <= hitCol + 1; c++)
  89.                     {
  90.                         if (r >= 0 && r < 15 && c >= 0 && c < 15)
  91.                         {
  92.                             if (!damagedCells.ContainsKey(r))
  93.                             {
  94.                                 damagedCells.Add(r, new List<int>());
  95.                             }
  96.                             damagedCells[r].Add(c);
  97.                         }
  98.                     }
  99.                 }
  100.                 hasCloud = false;
  101.                 hasEruption = true;
  102.             }        
  103.  
  104.             if (damagedCells.ContainsKey(playerRow) && damagedCells[playerRow].Contains(playerCol) && !hasDiedBySecondCloud && !endGame)
  105.             {
  106.                 //Goes up
  107.                 if (playerRow - 1 >= 0)
  108.                 {
  109.                     if (!damagedCells.ContainsKey(playerRow - 1) && !hasEscaped)
  110.                     {
  111.                         playerRow--;
  112.                         hasEscaped = true;                    
  113.                     }
  114.                 }            
  115.                 if (playerCol + 1 < 15) //Goes to the right
  116.                 {
  117.                     if (damagedCells.ContainsKey(playerRow) && !damagedCells[playerRow].Contains(playerCol + 1) && !hasEscaped)
  118.                     {
  119.                         playerCol++;
  120.                         hasEscaped = true;
  121.                     }
  122.                 }              
  123.                 if (playerRow + 1 < 15)    //Goes down
  124.                 {
  125.                     if (!damagedCells.ContainsKey(playerRow + 1) && !hasEscaped)
  126.                     {
  127.                         playerRow++;
  128.                         hasEscaped = true;
  129.                     }
  130.                 }
  131.                 //Goes to the left
  132.                 if (playerCol - 1 >= 0)
  133.                 {
  134.                     if (damagedCells.ContainsKey(playerRow) && !damagedCells[playerRow].Contains(playerCol - 1) && !hasEscaped)
  135.                     {
  136.                         playerCol--;
  137.                         hasEscaped = true;
  138.                     }
  139.                 }
  140.  
  141.                 if (hasCloud && !hasEscaped)
  142.                 {
  143.                     playerHealth -= damageCloud;
  144.                     if (playerHealth <= 0)
  145.                     {
  146.                         endGame = true;
  147.                     }
  148.                 }
  149.  
  150.                 else if (hasEruption && !hasEscaped)
  151.                 {
  152.                     playerHealth -= damageEruption;
  153.                     if (playerHealth <= 0)
  154.                     {
  155.                         endGame = true;
  156.                     }
  157.                 }
  158.             }
  159.             else
  160.             {
  161.                 hasEscaped = true;
  162.             }
  163.  
  164.             //Game is over
  165.             if (endGame)
  166.             {
  167.                 break;
  168.             }
  169.         }
  170.  
  171.  
  172.         if (heiganHealth <= 0 && playerHealth > 0)
  173.         {
  174.             Console.WriteLine("Heigan: Defeated!");
  175.             Console.WriteLine($"Player: {playerHealth}");
  176.             Console.WriteLine($"Final position: {playerRow}, {playerCol}");
  177.  
  178.         }
  179.         else
  180.  
  181.         {
  182.             if (hasCloud && heiganHealth > 0)
  183.             {
  184.                 Console.WriteLine("Heigan: {0:0.00}", heiganHealth);
  185.                 Console.WriteLine("Player: Killed by Plague Cloud");
  186.                 Console.WriteLine($"Final position: {playerRow}, {playerCol}");
  187.             }
  188.             else if (heiganHealth > 0)
  189.             {
  190.                 Console.WriteLine("Heigan: {0:0.00}", heiganHealth);
  191.                 Console.WriteLine("Player: Killed by Eruption");
  192.                 Console.WriteLine($"Final position: {playerRow}, {playerCol}");
  193.             }
  194.             else
  195.             {
  196.                 Console.WriteLine("Heigan: Defeated!");
  197.                 Console.WriteLine($"Player: Killed by Plague Cloud");
  198.                 Console.WriteLine($"Final position: {playerRow}, {playerCol}");
  199.             }
  200.            
  201.         }
  202.  
  203.     }
  204.    
  205. }
Advertisement
Add Comment
Please, Sign In to add comment