petyaminkova91

Untitled

Oct 27th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02_DungeonestDark
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string[] rooms = Console.ReadLine()
  11. .Split("|");
  12.  
  13. int health = 100;
  14. int coins = 0;
  15.  
  16. for (int i = 0; i < rooms.Length; i++)
  17. {
  18. string[] room = rooms[i].Split().ToArray();
  19.  
  20. string firstPart = room[0];
  21. int number = int.Parse(room[1]);
  22.  
  23. if (firstPart == "potion")
  24. {
  25. int diff = 0;
  26.  
  27. if (health < 100)
  28. {
  29. if (health + number <= 100)
  30. {
  31. diff = number;
  32. health = health + number;
  33. }
  34. else if (health + number > 100)
  35. {
  36. diff = 100 - health;
  37. health = 100;
  38. }
  39.  
  40. Console.WriteLine($"You healed for {diff} hp.");
  41. }
  42. Console.WriteLine($"Current health: {health} hp.");
  43. }
  44. else if (firstPart == "chest")
  45. {
  46. coins += number;
  47. Console.WriteLine($"You found {number} coins.");
  48. }
  49. else
  50. {
  51. health -= number;
  52. if (health > 0)
  53. {
  54. Console.WriteLine($"You slayed {firstPart}.");
  55. }
  56. else
  57. {
  58. Console.WriteLine($"You died! Killed by {firstPart}.");
  59. Console.WriteLine($"Best room: {i + 1}");
  60. break;
  61. }
  62. }
  63.  
  64. }
  65.  
  66. if (health > 0)
  67. {
  68. Console.WriteLine($"You've made it!");
  69. Console.WriteLine($"Coins: {coins}");
  70. Console.WriteLine($"Health: { health}");
  71. }
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment