Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class MatrixProblem
- {
- public static double heiganHealth = 3000000;
- public static int playerHealth = 18500;
- //Player
- public static int playerRow = 7;
- public static int playerCol = 7;
- //Damage to player
- public static int damageCloud = 3500;
- public static int damageEruption = 6000;
- public static void Main()
- {
- SortedDictionary<int, List<int>> damagedCells = new SortedDictionary<int, List<int>>();
- double damageOnHeigan = double.Parse(Console.ReadLine());
- bool endGame = false;
- bool hasCloud = false;
- bool hasEruption = false;
- bool hasDiedBySecondCloud = false;
- bool hasEscaped = false;
- while (true)
- {
- string[] line = Console.ReadLine().Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- string spell = line[0];
- int hitRow = int.Parse(line[1]);
- int hitCol = int.Parse(line[2]);
- heiganHealth -= damageOnHeigan;
- if (heiganHealth <= 0)
- {
- endGame = true;
- }
- if (hasCloud && !hasEscaped)
- {
- playerHealth -= damageCloud;
- if (playerHealth <= 0)
- {
- hasDiedBySecondCloud = true;
- endGame = true;
- }
- }
- hasEscaped = false;
- if (spell.Equals("Cloud") && !hasDiedBySecondCloud)
- {
- if (damagedCells.Count != 0)
- {
- damagedCells = new SortedDictionary<int, List<int>>();
- }
- //damaged cells by Cloud
- for (int r = hitRow - 1; r <= hitRow + 1; r++)
- {
- for (int c = hitCol - 1; c <= hitCol + 1; c++)
- {
- if (r >= 0 && r < 15 && c >= 0 && c < 15)
- {
- if (!damagedCells.ContainsKey(r))
- {
- damagedCells.Add(r, new List<int>());
- }
- damagedCells[r].Add(c);
- }
- }
- }
- hasCloud = true;
- hasEruption = false;
- }
- //damaged cells by Eruption
- else if (!hasDiedBySecondCloud)
- {
- if (damagedCells.Count != 0)
- {
- damagedCells = new SortedDictionary<int, List<int>>();
- }
- for (int r = hitRow - 1; r <= hitRow + 1; r++)
- {
- for (int c = hitCol - 1; c <= hitCol + 1; c++)
- {
- if (r >= 0 && r < 15 && c >= 0 && c < 15)
- {
- if (!damagedCells.ContainsKey(r))
- {
- damagedCells.Add(r, new List<int>());
- }
- damagedCells[r].Add(c);
- }
- }
- }
- hasCloud = false;
- hasEruption = true;
- }
- if (damagedCells.ContainsKey(playerRow) && damagedCells[playerRow].Contains(playerCol) && !hasDiedBySecondCloud && !endGame)
- {
- //Goes up
- if (playerRow - 1 >= 0)
- {
- if (!damagedCells.ContainsKey(playerRow - 1) && !hasEscaped)
- {
- playerRow--;
- hasEscaped = true;
- }
- }
- if (playerCol + 1 < 15) //Goes to the right
- {
- if (damagedCells.ContainsKey(playerRow) && !damagedCells[playerRow].Contains(playerCol + 1) && !hasEscaped)
- {
- playerCol++;
- hasEscaped = true;
- }
- }
- if (playerRow + 1 < 15) //Goes down
- {
- if (!damagedCells.ContainsKey(playerRow + 1) && !hasEscaped)
- {
- playerRow++;
- hasEscaped = true;
- }
- }
- //Goes to the left
- if (playerCol - 1 >= 0)
- {
- if (damagedCells.ContainsKey(playerRow) && !damagedCells[playerRow].Contains(playerCol - 1) && !hasEscaped)
- {
- playerCol--;
- hasEscaped = true;
- }
- }
- if (hasCloud && !hasEscaped)
- {
- playerHealth -= damageCloud;
- if (playerHealth <= 0)
- {
- endGame = true;
- }
- }
- else if (hasEruption && !hasEscaped)
- {
- playerHealth -= damageEruption;
- if (playerHealth <= 0)
- {
- endGame = true;
- }
- }
- }
- else
- {
- hasEscaped = true;
- }
- //Game is over
- if (endGame)
- {
- break;
- }
- }
- if (heiganHealth <= 0 && playerHealth > 0)
- {
- Console.WriteLine("Heigan: Defeated!");
- Console.WriteLine($"Player: {playerHealth}");
- Console.WriteLine($"Final position: {playerRow}, {playerCol}");
- }
- else
- {
- if (hasCloud && heiganHealth > 0)
- {
- Console.WriteLine("Heigan: {0:0.00}", heiganHealth);
- Console.WriteLine("Player: Killed by Plague Cloud");
- Console.WriteLine($"Final position: {playerRow}, {playerCol}");
- }
- else if (heiganHealth > 0)
- {
- Console.WriteLine("Heigan: {0:0.00}", heiganHealth);
- Console.WriteLine("Player: Killed by Eruption");
- Console.WriteLine($"Final position: {playerRow}, {playerCol}");
- }
- else
- {
- Console.WriteLine("Heigan: Defeated!");
- Console.WriteLine($"Player: Killed by Plague Cloud");
- Console.WriteLine($"Final position: {playerRow}, {playerCol}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment