Advertisement
bullit3189

Dungeonest Dark TF-MidExam 4Nov18

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