Advertisement
Frostyy22

chatgpt1

Mar 28th, 2023
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.98 KB | None | 0 0
  1. namespace Utils
  2. {
  3. using System;
  4. using System.Media;
  5.  
  6. class Utils
  7. {
  8. Random random = new Random();
  9.  
  10. #region Sounds
  11. //SmallArms sounds
  12. List<string> smallArms = new List<string> {
  13. @"C:\Users\Frostyy\source\repos\WW2SurvivalGame\Sounds\SmallArmsFire0.wav",
  14. @"C:\Users\Frostyy\source\repos\WW2SurvivalGame\Sounds\SmallArmsFire1.wav",
  15. @"C:\Users\Frostyy\source\repos\WW2SurvivalGame\Sounds\SmallArmsFire2.wav",
  16. };
  17.  
  18. //Move sounds
  19. List<string> move = new List<string> {
  20. @"C:\Users\Frostyy\source\repos\WW2SurvivalGame\Sounds\Move0.wav",
  21. @"C:\Users\Frostyy\source\repos\WW2SurvivalGame\Sounds\Move1.wav",
  22. @"C:\Users\Frostyy\source\repos\WW2SurvivalGame\Sounds\Move2.wav",
  23. };
  24. #endregion
  25.  
  26. public void SmallArms()
  27. {
  28. //Get a random sound
  29. int randomIndex = random.Next(smallArms.Count);
  30. string randomSmallArms = smallArms[randomIndex];
  31.  
  32. using (var smallArms = new SoundPlayer(randomSmallArms))
  33. {
  34. smallArms.PlaySync(); //Use PlaySync to play the sound synchronously
  35. }
  36. }
  37.  
  38. public void Move()
  39. {
  40. //Get a random sound
  41. int randomIndex = random.Next(move.Count);
  42. string randomMove = move[randomIndex];
  43.  
  44. using (var move = new SoundPlayer(randomMove))
  45. {
  46. move.PlaySync(); //Use PlaySync to play the sound synchronously
  47. }
  48. }
  49.  
  50. public void WriteColor(string message, ConsoleColor color, string lineEnding)
  51. {
  52. Console.ForegroundColor = color;
  53. Console.WriteLine(message);
  54. Console.ResetColor();
  55. Console.Write(lineEnding);
  56. }
  57. }
  58. }
  59.  
  60. namespace Enemy
  61. {
  62. class Enemy
  63. {
  64. public int health { get; set; }
  65. public int damage { get; set; }
  66.  
  67. public Enemy(int health, int damage)
  68. {
  69. this.health = health;
  70. this.damage = damage;
  71. }
  72. }
  73. }
  74.  
  75. namespace Core
  76. {
  77. using System;
  78. using Enemy;
  79. using Utils;
  80. class Logic
  81. {
  82. static List<Item> inventory = new List<Item>();
  83.  
  84. static Utils utils = new Utils();
  85.  
  86. static Random rand = new Random();
  87.  
  88. static Enemy enemy = new Enemy(100, rand.Next(50, 91));
  89.  
  90. static int health = 100;
  91. static int energy = 100;
  92. static int hunger = 100;
  93. static int thirst = 100;
  94. static int ammo = 10;
  95. static int bandages = 1;
  96. static int marks = 5;
  97.  
  98. static int foodCount = 0;
  99. static int waterCount = 0;
  100.  
  101. static bool inInventory = false;
  102. static bool inCombat = false;
  103.  
  104.  
  105. static void Main(string[] args)
  106. {
  107. inventory.Add(new Item("Ammunition", 10));
  108. inventory.Add(new Item("Bandages", 1));
  109. inventory.Add(new Item("Marks", 5));
  110.  
  111. Console.Write("Welcome to the ");
  112. Console.ForegroundColor = ConsoleColor.DarkGreen;
  113. Console.Write("Behind Enemy Lines: WW2 Survival" + Environment.NewLine);
  114. Console.ResetColor();
  115.  
  116. while (health > 0 && inCombat == false)
  117. {
  118. StatusMenu();
  119.  
  120. string? choice = Console.ReadLine();
  121. if (!int.TryParse(choice, out int menuChoice))
  122. {
  123. Console.ForegroundColor = ConsoleColor.DarkRed;
  124. Console.WriteLine("Invalid choice. Please try again.");
  125. Console.ResetColor();
  126. continue;
  127. }
  128.  
  129. bool validChoice = true;
  130. switch (menuChoice)
  131. {
  132. case 1:
  133. if (HasEnoughEnergy(1))
  134. {
  135. KeepMoving();
  136. }
  137. break;
  138. case 2:
  139. if (HasEnoughEnergy(1))
  140. {
  141. SearchForEquipment();
  142. }
  143. break;
  144. case 3:
  145. if (HasEnoughEnergy(1))
  146. {
  147. SearchForFood();
  148. }
  149. break;
  150. case 4:
  151. if (HasEnoughEnergy(1))
  152. {
  153. SearchForWater();
  154. }
  155. break;
  156. case 5:
  157. if (HasEnoughEnergy(1))
  158. {
  159. CheckInventory();
  160. }
  161. break;
  162. case 6:
  163. Rest();
  164. break;
  165. case 7:
  166. break;
  167. case 9:
  168. Console.ForegroundColor = ConsoleColor.DarkRed;
  169. Console.WriteLine("Quitting game..");
  170. Console.ResetColor();
  171. Environment.Exit(1);
  172. break;
  173. default:
  174. Console.ForegroundColor = ConsoleColor.DarkRed;
  175. Console.WriteLine("Invalid choice. Please try again.");
  176. Console.ResetColor();
  177. validChoice = false;
  178. break;
  179. }
  180. if (validChoice)
  181. {
  182. UpdateStatus();
  183. }
  184.  
  185. if (energy <= 0)
  186. {
  187. energy = 0;
  188. }
  189. }
  190. }
  191.  
  192. static void StatusMenu()
  193. {
  194. Console.WriteLine("########################");
  195. CheckStatus();
  196. Console.WriteLine("########################");
  197. Console.WriteLine("1. Keep moving towards allied lines");
  198. Console.WriteLine("2. Scavange for equpiment");
  199. Console.WriteLine("3. Scavange for food");
  200. Console.WriteLine("4. Scavange for water");
  201. Console.WriteLine("5. Check your inventory");
  202. Console.WriteLine("6. Rest");
  203. Console.WriteLine("9. Quit the game");
  204. Console.WriteLine("########################");
  205. }
  206.  
  207. static void CombatMenu()
  208. {
  209. Console.WriteLine("##############################");
  210. Console.WriteLine("What do you want to do?" + Environment.NewLine);
  211. Console.WriteLine("1. Attempt to fire at the enemy again.");
  212. Console.WriteLine("2. Attempt to take cover.");
  213. Console.WriteLine("3. Attempt to retreat away.");
  214. Console.WriteLine("4. Use a bandage.");
  215. Console.WriteLine("##############################");
  216. }
  217.  
  218. static bool HasEnoughEnergy(int requiredEnergy)
  219. {
  220. if (energy < requiredEnergy)
  221. {
  222. Console.WriteLine("Not enough energy. Take some rest.");
  223. energy = 0;
  224. return false;
  225. }
  226. else
  227. {
  228. return true;
  229. }
  230. }
  231.  
  232. static void KeepMoving()
  233. {
  234. Random rand = new Random();
  235. int eventChance = rand.Next(0, 101);
  236.  
  237. if (eventChance > 70)
  238. {
  239. Console.WriteLine("You encounter an enemy!" + Environment.NewLine);
  240. Combat();
  241. }
  242. else if (eventChance > 40)
  243. {
  244. Console.WriteLine("You encounter a villager!" + Environment.NewLine);
  245. }
  246. }
  247.  
  248. static void SearchForEquipment()
  249. {
  250. Console.WriteLine("You search for equipment.." + Environment.NewLine);
  251.  
  252. Random rand = new Random();
  253. int eventChance = rand.Next(0, 101);
  254. int lootChance = rand.Next(1, 13); // Generate a random number between 1 and 10
  255.  
  256. if (lootChance <= 3) // 30% chance of finding bandages
  257. {
  258. bandages++;
  259. Console.WriteLine("You find a bandage!");
  260.  
  261. Item? bandagesItem = inventory.Find(item => item.Name == "Bandages");
  262. if (bandagesItem != null)
  263. {
  264. // If the food item already exists, add the quantity
  265. bandagesItem.Quantity += 1;
  266. }
  267. else
  268. {
  269. // If the food item does not exist, create a new item in the inventory
  270. inventory.Add(new Item("Bandages", 1));
  271. }
  272. }
  273. else if (lootChance <= 6) // 30% chance of finding ammo
  274. {
  275. int numAmmo = rand.Next(1, 6); // Generate a random number of ammo between 1 and 5
  276. ammo += numAmmo;
  277. Console.WriteLine($"You find {numAmmo} bullets!");
  278.  
  279. Item? ammoItem = inventory.Find(item => item.Name == "Ammunition");
  280. if (ammoItem != null)
  281. {
  282. // If the food item already exists, add the quantity
  283. ammoItem.Quantity += numAmmo;
  284. }
  285. else
  286. {
  287. // If the food item does not exist, create a new item in the inventory
  288. inventory.Add(new Item("Ammunition", numAmmo));
  289. }
  290. }
  291. else if (lootChance <= 9) // 30% chance of finding marks
  292. {
  293. int numMarks = rand.Next(1, 6); // Generate a random number of marks between 1 and 5
  294. marks += numMarks;
  295. Console.WriteLine($"You find {numMarks} marks!");
  296.  
  297. Item? marksItem = inventory.Find(item => item.Name == "Marks");
  298. if (marksItem != null)
  299. {
  300. // If the food item already exists, add the quantity
  301. marksItem.Quantity += numMarks;
  302. }
  303. else
  304. {
  305. // If the food item does not exist, create a new item in the inventory
  306. inventory.Add(new Item("Marks", numMarks));
  307. }
  308. }
  309. else // 30% chance of finding nothing
  310. {
  311. Console.WriteLine("You didn't find anything.");
  312. }
  313.  
  314. if (eventChance > 85)
  315. {
  316. Console.WriteLine("You encounter an enemy!" + Environment.NewLine);
  317. Combat();
  318. }
  319. }
  320.  
  321. static void SearchForFood()
  322. {
  323. Console.WriteLine("You search for food.." + Environment.NewLine);
  324.  
  325. List<string> messages = new List<string>()
  326. {
  327. "You find some canned food!",
  328. "You find some chocolate!",
  329. "You find some bread!",
  330. "You find some meat!",
  331. "You find some fat!"
  332. };
  333.  
  334. // Random
  335. Random rand = new Random();
  336.  
  337. // Random foot chance
  338. int result = rand.Next(1, 9);
  339.  
  340. // Random message
  341. int index = rand.Next(messages.Count);
  342. string randomMessage = messages[index];
  343.  
  344. if (result == 1)
  345. {
  346. Console.ForegroundColor = ConsoleColor.Green;
  347. Console.WriteLine(randomMessage + Environment.NewLine);
  348. Console.ResetColor();
  349.  
  350. foodCount += 1;
  351.  
  352. // Check if the food item already exists in the inventory
  353. Item? foodItem = inventory.Find(item => item.Name == "Food");
  354. if (foodItem != null)
  355. {
  356. // If the food item already exists, add the quantity
  357. foodItem.Quantity += 1;
  358. }
  359. else
  360. {
  361. // If the food item does not exist, create a new item in the inventory
  362. inventory.Add(new Item("Food", 1));
  363. }
  364. }
  365. else
  366. {
  367. Console.WriteLine("You fail to find any food." + Environment.NewLine);
  368. }
  369. }
  370.  
  371. static void SearchForWater()
  372. {
  373. Console.WriteLine("You search for water.." + Environment.NewLine);
  374.  
  375. List<string> messages = new List<string>()
  376. {
  377. "You find some water!",
  378. "You find some juice!",
  379. "You find some wine!",
  380. "You find some vodka!"
  381. };
  382.  
  383. // Random
  384. Random rand = new Random();
  385.  
  386. // Random foot chance
  387. int result = rand.Next(1, 9);
  388.  
  389. // Random message
  390. int index = rand.Next(messages.Count);
  391. string randomMessage = messages[index];
  392.  
  393. if (result == 1)
  394. {
  395. Console.ForegroundColor = ConsoleColor.Green;
  396. Console.WriteLine(randomMessage + Environment.NewLine);
  397. Console.ResetColor();
  398.  
  399. waterCount += 1;
  400.  
  401. // Check if the water item already exists in the inventory
  402. Item? waterItem = inventory.Find(item => item.Name == "Water");
  403. if (waterItem != null)
  404. {
  405. // If the water item already exists, add the quantity
  406. waterItem.Quantity += 1;
  407. }
  408. else
  409. {
  410. // If the water item does not exist, create a new item in the inventory
  411. inventory.Add(new Item("Water", 1));
  412. }
  413. }
  414. else
  415. {
  416. Console.WriteLine("You fail to find any water." + Environment.NewLine);
  417. }
  418. }
  419.  
  420. static void Eat()
  421. {
  422. Item? foodItem = inventory.Find(item => item.Name == "Food");
  423. if (foodItem != null && foodItem.Quantity > 0)
  424. {
  425. foodItem.Quantity -= 1;
  426. foodCount -= 1;
  427. Console.ForegroundColor = ConsoleColor.Green;
  428. Console.WriteLine("You eat some food and restore some hunger." + Environment.NewLine);
  429. Console.ResetColor();
  430. hunger = Math.Min(100, hunger + 30);
  431. }
  432. else
  433. {
  434. Console.WriteLine("You do not have any food to eat." + Environment.NewLine);
  435. }
  436. }
  437.  
  438. static void Drink()
  439. {
  440. Item? waterItem = inventory.Find(item => item.Name == "Water");
  441. if (waterItem != null && waterItem.Quantity > 0)
  442. {
  443. waterItem.Quantity -= 1;
  444. waterCount -= 1;
  445. Console.ForegroundColor = ConsoleColor.Green;
  446. Console.WriteLine("You drink some water and restore some thirst." + Environment.NewLine);
  447. Console.ResetColor();
  448. thirst = Math.Min(100, thirst + 30);
  449. }
  450. else
  451. {
  452. Console.WriteLine("You do not have any water to drink." + Environment.NewLine);
  453. }
  454. }
  455.  
  456. static void Bandage()
  457. {
  458. if (bandages >= 1)
  459. {
  460. Item? healthItem = inventory.Find(item => item.Name == "Bandages");
  461. if (healthItem != null && healthItem.Quantity > 0)
  462. {
  463. healthItem.Quantity -= 1;
  464. bandages -= 1;
  465. Console.ForegroundColor = ConsoleColor.Green;
  466. Console.WriteLine("You use a bandage to heal.");
  467. Console.ResetColor();
  468. health = Math.Min(100, health + 30);
  469. }
  470. }
  471. else
  472. {
  473. Console.WriteLine("Not enough bandages.");
  474. }
  475. }
  476.  
  477. static void CheckInventory()
  478. {
  479. inInventory = true;
  480.  
  481. while (inInventory)
  482. {
  483. Console.Write(Environment.NewLine);
  484. Console.WriteLine("Inventory:");
  485. foreach (Item item in inventory)
  486. {
  487. Console.WriteLine(item.Name + " x" + item.Quantity);
  488. }
  489. Console.Write(Environment.NewLine);
  490.  
  491. Console.WriteLine("########################");
  492. Console.WriteLine("1. Eat some food");
  493. Console.WriteLine("2. Drink some water");
  494. Console.WriteLine("3. Use a bandage");
  495. Console.WriteLine("4. Close inventory");
  496. Console.WriteLine("########################");
  497.  
  498. string? choice = Console.ReadLine();
  499.  
  500. switch (choice)
  501. {
  502. case "1":
  503. Eat();
  504. break;
  505. case "2":
  506. Drink();
  507. break;
  508. case "3":
  509. Bandage();
  510. break;
  511. case "4":
  512. inInventory = false;
  513. break;
  514. default:
  515. Console.ForegroundColor = ConsoleColor.DarkRed;
  516. Console.WriteLine("Invalid choice. Please try again.");
  517. Console.ResetColor();
  518. break;
  519. }
  520. }
  521. }
  522.  
  523. static void Rest()
  524. {
  525. Console.WriteLine("You rest and regain some energy.");
  526.  
  527. energy = Math.Min(100, energy + 50);
  528. thirst -= 20;
  529. hunger -= 20;
  530. }
  531.  
  532. static void UpdateStatus()
  533. {
  534. Console.WriteLine("One turn passes..");
  535.  
  536. hunger -= 5;
  537. thirst -= 5;
  538. energy -= 10;
  539.  
  540. if (health < 0)
  541. {
  542. GameOver();
  543. }
  544.  
  545. if (hunger <= 0)
  546. {
  547. Console.ForegroundColor = ConsoleColor.Red;
  548. Console.WriteLine("You died of hunger.");
  549. Console.ResetColor();
  550. Environment.Exit(2);
  551. }
  552.  
  553. if (thirst <= 0)
  554. {
  555. Console.ForegroundColor = ConsoleColor.Red;
  556. Console.WriteLine("You died of thirst.");
  557. Console.ResetColor();
  558. Environment.Exit(2);
  559. }
  560. }
  561.  
  562. static void CheckStatus()
  563. {
  564. Console.WriteLine("Current status:");
  565. Console.ForegroundColor = ConsoleColor.Red;
  566. Console.WriteLine("Health: {0}", health);
  567. Console.ResetColor();
  568. Console.ForegroundColor = ConsoleColor.DarkYellow;
  569. Console.WriteLine("Energy: {0}", energy);
  570. Console.WriteLine("Hunger: {0}", hunger);
  571. Console.ResetColor();
  572. Console.ForegroundColor = ConsoleColor.Cyan;
  573. Console.WriteLine("Thirst: {0}", thirst);
  574. Console.ResetColor();
  575. }
  576.  
  577. static void Combat()
  578. {
  579. inCombat = true;
  580.  
  581. Console.WriteLine("You open fire on the enemy!" + Environment.NewLine);
  582.  
  583. while (health > 0 && inCombat)
  584. {
  585. ammo -= 1;
  586.  
  587. Item? ammoItem = inventory.Find(item => item.Name == "Ammunition");
  588. if (ammoItem != null && ammoItem.Quantity > 0)
  589. {
  590. ammoItem.Quantity -= 1;
  591. ammo -= 1;
  592. }
  593.  
  594. utils.SmallArms();
  595.  
  596. if (ammo <= 0)
  597. {
  598. Console.WriteLine("You have no ammunition left.");
  599.  
  600. Console.WriteLine("What do you want to do?" + Environment.NewLine);
  601. Console.WriteLine("1. Attempt to take cover.");
  602. Console.WriteLine("2. Attempt to retreat away.");
  603. Console.WriteLine("3. Use a bandage.");
  604. Console.WriteLine("##############################");
  605.  
  606. string? playerCombatAction = Console.ReadLine();
  607.  
  608. switch (playerCombatAction)
  609. {
  610. case "1":
  611. Console.WriteLine("You attempt to take cover." + Environment.NewLine);
  612.  
  613. int enemyHitChance = rand.Next(0, 3);
  614.  
  615. if (enemyHitChance == 0)
  616. {
  617. Console.WriteLine("The enemy missed you while you were in cover.");
  618. }
  619. else
  620. {
  621. utils.SmallArms();
  622.  
  623. health -= enemy.damage;
  624.  
  625. Console.Write("The enemy hits you while you were in cover and deals ");
  626. Console.ForegroundColor = ConsoleColor.Red;
  627. Console.Write(enemy.damage);
  628. Console.ResetColor();
  629. Console.Write(" damage.");
  630. Console.Write(Environment.NewLine);
  631.  
  632. if (health <= 0)
  633. {
  634. GameOver();
  635. }
  636. }
  637. break;
  638. case "2":
  639. Console.WriteLine("You attempt to retreat." + Environment.NewLine);
  640.  
  641. int retreatChance = rand.Next(0, 2);
  642.  
  643. if (retreatChance == 0)
  644. {
  645. Console.WriteLine("You successfully retreat." + Environment.NewLine);
  646. utils.Move();
  647. inCombat = false;
  648. }
  649. else
  650. {
  651. utils.SmallArms();
  652.  
  653. Console.WriteLine("You attempt to retreat but fail." + Environment.NewLine);
  654.  
  655. health -= enemy.damage;
  656.  
  657. Console.Write("The enemy hits you and deals ");
  658. Console.ForegroundColor = ConsoleColor.Red;
  659. Console.Write(enemy.damage);
  660. Console.ResetColor();
  661. Console.Write(" damage.");
  662. Console.Write(Environment.NewLine);
  663.  
  664. if (health <= 0)
  665. {
  666. GameOver();
  667. }
  668. }
  669. break;
  670. case "3":
  671. Bandage();
  672.  
  673. Console.ForegroundColor = ConsoleColor.Green;
  674. Console.WriteLine("You now have " + health + " health.");
  675. Console.ResetColor();
  676. break;
  677. default:
  678. utils.WriteColor("Invalid input.", ConsoleColor.Red, Environment.NewLine);
  679. break;
  680. }
  681. }
  682.  
  683. int dealDamage = rand.Next(50, 100);
  684. int hitChance = rand.Next(0, 2);
  685.  
  686. if (hitChance == 1)
  687. {
  688. enemy.health -= dealDamage;
  689.  
  690. Console.Write("You manage to hit the enemy and deal ");
  691. Console.ForegroundColor = ConsoleColor.Red;
  692. Console.Write(dealDamage);
  693. Console.ResetColor();
  694. Console.Write(" damage. ");
  695. Console.Write(Environment.NewLine);
  696.  
  697. if (enemy.health <= 0)
  698. {
  699. inCombat = false;
  700.  
  701. enemy.health = 100;
  702.  
  703. Console.Write("You successfully kill the enemy!" + Environment.NewLine);
  704. }
  705. else
  706. {
  707. CombatMenu();
  708.  
  709. string? playerCombatAction = Console.ReadLine();
  710.  
  711. switch (playerCombatAction)
  712. {
  713. case "1":
  714. Console.WriteLine("You open fire on the enemy!" + Environment.NewLine);
  715. break;
  716. case "2":
  717. Console.WriteLine("You attempt to take cover." + Environment.NewLine);
  718.  
  719. int enemyHitChance = rand.Next(0, 3);
  720.  
  721. if (enemyHitChance == 0)
  722. {
  723. Console.WriteLine("The enemy missed you while you were in cover.");
  724. }
  725. else
  726. {
  727. utils.SmallArms();
  728.  
  729. health -= enemy.damage;
  730.  
  731. Console.Write("The enemy hits you while you were in cover and deals ");
  732. Console.ForegroundColor = ConsoleColor.Red;
  733. Console.Write(enemy.damage);
  734. Console.ResetColor();
  735. Console.Write(" damage.");
  736. Console.Write(Environment.NewLine);
  737.  
  738. if (health <= 0)
  739. {
  740. GameOver();
  741. }
  742. }
  743. break;
  744. case "3":
  745. Console.WriteLine("You attempt to retreat." + Environment.NewLine);
  746.  
  747. int retreatChance = rand.Next(0, 2);
  748.  
  749. if (retreatChance == 0)
  750. {
  751. Console.WriteLine("You successfully retreat." + Environment.NewLine);
  752. utils.Move();
  753. inCombat = false;
  754. }
  755. else
  756. {
  757. utils.SmallArms();
  758.  
  759. Console.WriteLine("You attempt to retreat but fail." + Environment.NewLine);
  760.  
  761. health -= enemy.damage;
  762.  
  763. Console.Write("The enemy hits you and deals ");
  764. Console.ForegroundColor = ConsoleColor.Red;
  765. Console.Write(enemy.damage);
  766. Console.ResetColor();
  767. Console.Write(" damage.");
  768. Console.Write(Environment.NewLine);
  769.  
  770. if (health <= 0)
  771. {
  772. GameOver();
  773. }
  774. }
  775. break;
  776. case "4":
  777. Bandage();
  778.  
  779. Console.ForegroundColor = ConsoleColor.Green;
  780. Console.WriteLine("You now have " + health + " health.");
  781. Console.ResetColor();
  782. break;
  783. default:
  784. utils.WriteColor("Invalid input.", ConsoleColor.Red, Environment.NewLine);
  785. break;
  786. }
  787. }
  788. }
  789. else if (hitChance == 0)
  790. {
  791. Console.Write("You fire at the enemy but miss." + Environment.NewLine);
  792.  
  793. if (rand.Next(0, 2) == 0)
  794. {
  795. Console.WriteLine("The enemy fires but misses you.");
  796. }
  797. else
  798. {
  799. health -= enemy.damage;
  800.  
  801. Console.Write("The enemy hits you and deals ");
  802. Console.ForegroundColor = ConsoleColor.Red;
  803. Console.Write(enemy.damage);
  804. Console.ResetColor();
  805. Console.Write(" damage.");
  806. Console.Write(Environment.NewLine);
  807.  
  808. if (health <= 0)
  809. {
  810. GameOver();
  811. }
  812. else
  813. {
  814. CombatMenu();
  815.  
  816. string? playerCombatAction = Console.ReadLine();
  817.  
  818. switch (playerCombatAction)
  819. {
  820. case "1":
  821. Console.WriteLine("You open fire on the enemy!" + Environment.NewLine);
  822. break;
  823. case "2":
  824. Console.WriteLine("You attempt to take cover." + Environment.NewLine);
  825.  
  826. int enemyHitChance = rand.Next(0, 3);
  827.  
  828. if (enemyHitChance == 0)
  829. {
  830. Console.WriteLine("The enemy missed you while you were in cover.");
  831. }
  832. else
  833. {
  834. utils.SmallArms();
  835.  
  836. health -= enemy.damage;
  837.  
  838. Console.Write("The enemy hits you while you were in cover and deals ");
  839. Console.ForegroundColor = ConsoleColor.Red;
  840. Console.Write(enemy.damage);
  841. Console.ResetColor();
  842. Console.Write(" damage.");
  843. Console.Write(Environment.NewLine);
  844.  
  845. if (health <= 0)
  846. {
  847. GameOver();
  848. }
  849. }
  850. break;
  851. case "3":
  852. Console.WriteLine("You attempt to retreat." + Environment.NewLine);
  853.  
  854. int retreatChance = rand.Next(0, 2);
  855.  
  856. if (retreatChance == 0)
  857. {
  858. Console.WriteLine("You successfully retreat." + Environment.NewLine);
  859. utils.Move();
  860. inCombat = false;
  861. }
  862. else
  863. {
  864. utils.SmallArms();
  865.  
  866. Console.WriteLine("You attempt to retreat but fail." + Environment.NewLine);
  867.  
  868. health -= enemy.damage;
  869.  
  870. Console.Write("The enemy hits you and deals ");
  871. Console.ForegroundColor = ConsoleColor.Red;
  872. Console.Write(enemy.damage);
  873. Console.ResetColor();
  874. Console.Write(" damage.");
  875. Console.Write(Environment.NewLine);
  876.  
  877. if (health <= 0)
  878. {
  879. GameOver();
  880. }
  881. }
  882. break;
  883. case "4":
  884. Bandage();
  885.  
  886. Console.ForegroundColor = ConsoleColor.Green;
  887. Console.WriteLine("You now have " + health + " health.");
  888. Console.ResetColor();
  889. break;
  890. default:
  891. utils.WriteColor("Invalid input.", ConsoleColor.Red, Environment.NewLine);
  892. break;
  893. }
  894. }
  895. }
  896. }
  897. }
  898. }
  899.  
  900. static void GameOver()
  901. {
  902. if (health < 0)
  903. {
  904. Console.ForegroundColor = ConsoleColor.Red;
  905. Console.WriteLine("You die from major injuries.");
  906. Console.ResetColor();
  907. Environment.Exit(2);
  908. }
  909. }
  910. }
  911.  
  912. public class Item
  913. {
  914. public string Name { get; set; }
  915. public int Quantity { get; set; }
  916.  
  917. public Item(string name, int quantity)
  918. {
  919. Name = name;
  920. Quantity = quantity;
  921. }
  922. }
  923. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement