Advertisement
simonradev

TrifonsQuest

Feb 19th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.55 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace TrifonsQuest
  5. {
  6.     public class TrifonsQuest
  7.     {
  8.         public static void Main()
  9.         {
  10.             long trifonsHealth = long.Parse(Console.ReadLine());
  11.             int[] rowsAndCols = Console.ReadLine()
  12.                                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  13.                                 .Select(int.Parse)
  14.                                 .ToArray();
  15.  
  16.             char[,] matrix = new char[rowsAndCols[0], rowsAndCols[1]];
  17.             for (int currRow = 0; currRow < rowsAndCols[0]; currRow++)
  18.             {
  19.                 string rowLayout = Console.ReadLine().ToLower();
  20.  
  21.                 for (int currCol = 0; currCol < rowLayout.Length; currCol++)
  22.                 {
  23.                     matrix[currRow, currCol] = rowLayout[currCol];
  24.                 }
  25.             }
  26.  
  27.             int countOfTurns = 0;
  28.             int row = 0;
  29.             int col = 0;
  30.             bool trifonIsDead = false;
  31.             while (col < matrix.GetLength(1))
  32.             {
  33.                 while (row != matrix.GetLength(0))
  34.                 {
  35.                     char symbol = matrix[row, col];
  36.  
  37.                     if (symbol == 'f')
  38.                     {
  39.                         int hpLost = countOfTurns / 2;
  40.  
  41.                         trifonsHealth -= hpLost;
  42.  
  43.                         if (trifonsHealth <= 0)
  44.                         {
  45.                             trifonIsDead = true;
  46.  
  47.                             break;
  48.                         }
  49.                     }
  50.                     else if (symbol == 'h')
  51.                     {
  52.                         int hpGained = countOfTurns / 3;
  53.  
  54.                         trifonsHealth += hpGained;
  55.                     }
  56.                     else if (symbol == 't')
  57.                     {
  58.                         countOfTurns += 2;
  59.                     }
  60.  
  61.                     countOfTurns++;
  62.                     row++;
  63.                 }
  64.  
  65.                 if (trifonIsDead)
  66.                 {
  67.                     break;
  68.                 }
  69.  
  70.                 row--;
  71.                 col++;
  72.  
  73.                 while (row != -1 && col != matrix.GetLength(1))
  74.                 {
  75.                     char symbol = matrix[row, col];
  76.  
  77.                     if (symbol == 'f')
  78.                     {
  79.                         int hpLost = countOfTurns / 2;
  80.  
  81.                         trifonsHealth -= hpLost;
  82.  
  83.                         if (trifonsHealth <= 0)
  84.                         {
  85.                             trifonIsDead = true;
  86.  
  87.                             break;
  88.                         }
  89.                     }
  90.                     else if (symbol == 'h')
  91.                     {
  92.                         int hpGained = countOfTurns / 3;
  93.  
  94.                         trifonsHealth += hpGained;
  95.                     }
  96.                     else if (symbol == 't')
  97.                     {
  98.                         countOfTurns += 2;
  99.                     }
  100.  
  101.                     countOfTurns++;
  102.                     row--;
  103.                 }
  104.  
  105.                 if (trifonIsDead)
  106.                 {
  107.                     break;
  108.                 }
  109.  
  110.                 row = 0;
  111.                 col++;
  112.             }
  113.  
  114.             if (trifonIsDead)
  115.             {
  116.                 Console.WriteLine($"Died at: [{row}, {col}]");
  117.  
  118.                 return;
  119.             }
  120.  
  121.             Console.WriteLine("Quest completed!");
  122.             Console.WriteLine($"Health: {trifonsHealth}");
  123.             Console.WriteLine($"Turns: {countOfTurns}");
  124.         }
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement