IPetrov007

01_RabbitHole

Feb 26th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _01_RabbitHole
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<string> input = Console.ReadLine().Split(' ').ToList();
  14. int allPower = int.Parse(Console.ReadLine());
  15.  
  16. string comand = string.Empty;
  17. int energy = 0;
  18. string startValue = string.Empty;
  19.  
  20. do
  21. {
  22. startValue = input[0];
  23. if (startValue == "RabbitHole")
  24. {
  25. Console.WriteLine("You have 5 years to save Kennedy!");
  26. break;
  27. }
  28. else
  29. {
  30. //ExtractComandsAndEnergy(startValue, comand, energy);
  31. string[] comandsAndEnerges = new string[2];
  32. comandsAndEnerges = startValue.Split('|');
  33. comand = comandsAndEnerges[0].ToString();
  34. energy = int.Parse(comandsAndEnerges[1]);
  35.  
  36. int currentIndex = 0;
  37. switch (comand)
  38. {
  39. case "Right":
  40. currentIndex = (energy + currentIndex) % input.Count;
  41. allPower -= energy;
  42. startValue = input[currentIndex];
  43. break;
  44. case "Left":
  45. currentIndex = (energy - currentIndex) % input.Count;
  46. allPower -= energy;
  47. startValue = input[currentIndex];
  48. break;
  49. case "Bomb":
  50. input.RemoveAt(currentIndex);
  51. allPower -= energy;
  52. if (allPower <= 0)
  53. {
  54. Console.WriteLine("You are dead due to bomb explosion!");
  55. }
  56. break;
  57. }
  58. if (input[input.Count - 1] == "RubbitHole")
  59. {
  60. string newElement = "Bomb|" + allPower.ToString();
  61. input.Add(newElement);
  62. }
  63. else
  64. {
  65. input.RemoveAt(input.Count - 1);
  66. string newElement = "Bomb|" + allPower.ToString();
  67. input.Add(newElement);
  68. }
  69.  
  70. }
  71. } while (allPower > 0);
  72. if (allPower <= 0 && comand != "Bomb" && comand != "RabbitHole")
  73. {
  74. Console.WriteLine("You are tired. You can't continue the mission.");
  75. }
  76.  
  77. }
  78.  
  79. private static void ExtractComandsAndEnergy(string startValue, string comand, int energy)
  80. {
  81. string[] comandsAndEnerges = new string[2];
  82. comandsAndEnerges = startValue.Split('|');
  83. comand = comandsAndEnerges[0].ToString();
  84. energy = int.Parse(comandsAndEnerges[1]);
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment