Advertisement
Frostyy22

chatgpt6

Mar 29th, 2023
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.71 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.  
  95. static int ammo = 10;
  96. static int bandages = 1;
  97. static int marks = 5;
  98.  
  99. static int foodCount = 0;
  100. static int waterCount = 0;
  101.  
  102. static bool inInventory = false;
  103. static bool inCombat = false;
  104. static bool inShop = false;
  105.  
  106.  
  107. static void Main(string[] args)
  108. {
  109. inventory.Add(new Item("Ammunition", 10));
  110. inventory.Add(new Item("Bandages", 1));
  111. inventory.Add(new Item("Marks", 5));
  112.  
  113. Console.Write("Welcome to the ");
  114. Console.ForegroundColor = ConsoleColor.DarkGreen;
  115. Console.Write("Behind Enemy Lines: WW2 Survival" + Environment.NewLine);
  116. Console.ResetColor();
  117.  
  118. while (health > 0 && inCombat == false && inShop == false)
  119. {
  120. StatusMenu();
  121.  
  122. string? choice = Console.ReadLine();
  123. if (!int.TryParse(choice, out int menuChoice))
  124. {
  125. Console.ForegroundColor = ConsoleColor.DarkRed;
  126. Console.WriteLine("Invalid choice. Please try again.");
  127. Console.ResetColor();
  128. continue;
  129. }
  130.  
  131. bool validChoice = true;
  132. switch (menuChoice)
  133. {
  134. case 1:
  135. if (HasEnoughEnergy(1))
  136. {
  137. KeepMoving();
  138. }
  139. break;
  140. case 2:
  141. if (HasEnoughEnergy(1))
  142. {
  143. SearchForEquipment();
  144. }
  145. break;
  146. case 3:
  147. if (HasEnoughEnergy(1))
  148. {
  149. SearchForFood();
  150. }
  151. break;
  152. case 4:
  153. if (HasEnoughEnergy(1))
  154. {
  155. SearchForWater();
  156. }
  157. break;
  158. case 5:
  159. if (HasEnoughEnergy(1))
  160. {
  161. CheckInventory();
  162. }
  163. break;
  164. case 6:
  165. Rest();
  166. break;
  167. case 7:
  168. break;
  169. case 9:
  170. Console.ForegroundColor = ConsoleColor.DarkRed;
  171. Console.WriteLine("Quitting game..");
  172. Console.ResetColor();
  173. Environment.Exit(1);
  174. break;
  175. default:
  176. Console.ForegroundColor = ConsoleColor.DarkRed;
  177. Console.WriteLine("Invalid choice. Please try again.");
  178. Console.ResetColor();
  179. validChoice = false;
  180. break;
  181. }
  182. if (validChoice)
  183. {
  184. UpdateStatus();
  185. }
  186. energy = Math.Clamp(energy, 0, 100);
  187. }
  188. }
  189.  
  190. #region Menus
  191. static void StatusMenu()
  192. {
  193. Console.WriteLine("########################");
  194. CheckStatus();
  195. Console.WriteLine("########################");
  196. Console.WriteLine("1. Keep moving towards allied lines");
  197. Console.WriteLine("2. Scavange for equpiment");
  198. Console.WriteLine("3. Scavange for food");
  199. Console.WriteLine("4. Scavange for water");
  200. Console.WriteLine("5. Check your inventory");
  201. Console.WriteLine("6. Rest");
  202. Console.WriteLine("9. Quit the game");
  203. Console.WriteLine("########################");
  204. }
  205.  
  206. static void CombatMenu()
  207. {
  208. Console.WriteLine("##############################");
  209. Console.WriteLine("What do you want to do?" + Environment.NewLine);
  210. Console.WriteLine("1. Attempt to fire at the enemy again.");
  211. Console.WriteLine("2. Attempt to take cover.");
  212. Console.WriteLine("3. Attempt to retreat away.");
  213. Console.WriteLine("4. Use a bandage.");
  214. Console.WriteLine("##############################");
  215. }
  216.  
  217. static void ShopMenu()
  218. {
  219. Console.WriteLine("##############################");
  220. Console.WriteLine("What do you want to do?" + Environment.NewLine);
  221. Console.WriteLine("1. Purchase some ammunition. Price: 10 marks / 5 bullets");
  222. Console.WriteLine("2. Sell some ammunition. Price: 5 bullets / 5 marks");
  223. Console.WriteLine("3. Purchase some food. Price: 15 marks / 1 meal");
  224. Console.WriteLine("4. Purchase some water. Price: 15 marks / 1 drink");
  225. Console.WriteLine("5. Sell some food. Price: 1 meal / 10 marks");
  226. Console.WriteLine("6. Sell some water. Price: 1 drink / 10 marks");
  227. Console.WriteLine("##############################");
  228. }
  229.  
  230. static void AnimalMenu()
  231. {
  232. Console.WriteLine("##############################");
  233. Console.WriteLine("What do you want to do?" + Environment.NewLine);
  234. Console.WriteLine("1. Attempt to fire at the animal.");
  235. Console.WriteLine("2. Retreat.");
  236. Console.WriteLine("##############################");
  237. }
  238. #endregion
  239.  
  240. static bool HasEnoughEnergy(int requiredEnergy)
  241. {
  242. if (energy < requiredEnergy)
  243. {
  244. Console.WriteLine("Not enough energy. Take some rest.");
  245. energy = 0;
  246. return false;
  247. }
  248. else
  249. {
  250. return true;
  251. }
  252. }
  253.  
  254. static void KeepMoving()
  255. {
  256. Random rand = new Random();
  257. int eventChance = rand.Next(0, 101);
  258.  
  259. if (eventChance > 75)
  260. {
  261. Console.WriteLine("You encounter an enemy!" + Environment.NewLine);
  262. Combat();
  263. }
  264. else if (eventChance > 45)
  265. {
  266. Villager();
  267. }
  268. else if (eventChance > 20)
  269. {
  270. Animal();
  271. }
  272. }
  273.  
  274. static void SearchForEquipment()
  275. {
  276. Console.WriteLine("You search for equipment.." + Environment.NewLine);
  277.  
  278. Random rand = new Random();
  279. int eventChance = rand.Next(0, 101);
  280. int lootChance = rand.Next(1, 13); // Generate a random number between 1 and 10
  281.  
  282. if (lootChance <= 3) // 30% chance of finding bandages
  283. {
  284. bandages++;
  285. Console.WriteLine("You find a bandage!");
  286.  
  287. Item? bandagesItem = inventory.Find(item => item.Name == "Bandages");
  288. if (bandagesItem != null)
  289. {
  290. // If the food item already exists, add the quantity
  291. bandagesItem.Quantity += 1;
  292. }
  293. else
  294. {
  295. // If the food item does not exist, create a new item in the inventory
  296. inventory.Add(new Item("Bandages", 1));
  297. }
  298. }
  299. else if (lootChance <= 6) // 30% chance of finding ammo
  300. {
  301. int numAmmo = rand.Next(1, 4); // Generate a random number of ammo between 1 and 5
  302. ammo += numAmmo;
  303. Console.WriteLine($"You find {numAmmo} bullets!");
  304.  
  305. Item? ammoItem = inventory.Find(item => item.Name == "Ammunition");
  306. if (ammoItem != null)
  307. {
  308. // If the food item already exists, add the quantity
  309. ammoItem.Quantity += numAmmo;
  310. }
  311. else
  312. {
  313. // If the food item does not exist, create a new item in the inventory
  314. inventory.Add(new Item("Ammunition", numAmmo));
  315. }
  316. }
  317. else if (lootChance <= 9) // 30% chance of finding marks
  318. {
  319. int numMarks = rand.Next(1, 6); // Generate a random number of marks between 1 and 5
  320. marks += numMarks;
  321. Console.WriteLine($"You find {numMarks} marks!");
  322.  
  323. Item? marksItem = inventory.Find(item => item.Name == "Marks");
  324. if (marksItem != null)
  325. {
  326. // If the food item already exists, add the quantity
  327. marksItem.Quantity += numMarks;
  328. }
  329. else
  330. {
  331. // If the food item does not exist, create a new item in the inventory
  332. inventory.Add(new Item("Marks", numMarks));
  333. }
  334. }
  335. else // 30% chance of finding nothing
  336. {
  337. Console.WriteLine("You didn't find anything.");
  338. }
  339.  
  340. if (eventChance > 85)
  341. {
  342. Console.WriteLine("You encounter an enemy!" + Environment.NewLine);
  343. Combat();
  344. }
  345. }
  346.  
  347. static void SearchForFood()
  348. {
  349. Console.WriteLine("You search for food.." + Environment.NewLine);
  350.  
  351. List<string> messages = new List<string>()
  352. {
  353. "You find some canned food!",
  354. "You find some chocolate!",
  355. "You find some bread!",
  356. "You find some meat!",
  357. "You find some fat!"
  358. };
  359.  
  360. // Random
  361. Random rand = new Random();
  362.  
  363. // Random foot chance
  364. int result = rand.Next(1, 6);
  365.  
  366. // Random message
  367. int index = rand.Next(messages.Count);
  368. string randomMessage = messages[index];
  369.  
  370. if (result == 1)
  371. {
  372. Console.ForegroundColor = ConsoleColor.Green;
  373. Console.WriteLine(randomMessage + Environment.NewLine);
  374. Console.ResetColor();
  375.  
  376. foodCount += 1;
  377.  
  378. // Check if the food item already exists in the inventory
  379. Item? foodItem = inventory.Find(item => item.Name == "Food");
  380. if (foodItem != null)
  381. {
  382. // If the food item already exists, add the quantity
  383. foodItem.Quantity += 1;
  384. }
  385. else
  386. {
  387. // If the food item does not exist, create a new item in the inventory
  388. inventory.Add(new Item("Food", 1));
  389. }
  390. }
  391. else
  392. {
  393. Console.WriteLine("You fail to find any food." + Environment.NewLine);
  394. }
  395. }
  396.  
  397. static void SearchForWater()
  398. {
  399. Console.WriteLine("You search for water.." + Environment.NewLine);
  400.  
  401. List<string> messages = new List<string>()
  402. {
  403. "You find some water!",
  404. "You find some juice!",
  405. "You find some wine!",
  406. "You find some vodka!"
  407. };
  408.  
  409. // Random
  410. Random rand = new Random();
  411.  
  412. // Random foot chance
  413. int result = rand.Next(1, 6);
  414.  
  415. // Random message
  416. int index = rand.Next(messages.Count);
  417. string randomMessage = messages[index];
  418.  
  419. if (result == 1)
  420. {
  421. Console.ForegroundColor = ConsoleColor.Green;
  422. Console.WriteLine(randomMessage + Environment.NewLine);
  423. Console.ResetColor();
  424.  
  425. waterCount += 1;
  426.  
  427. // Check if the water item already exists in the inventory
  428. Item? waterItem = inventory.Find(item => item.Name == "Water");
  429. if (waterItem != null)
  430. {
  431. // If the water item already exists, add the quantity
  432. waterItem.Quantity += 1;
  433. }
  434. else
  435. {
  436. // If the water item does not exist, create a new item in the inventory
  437. inventory.Add(new Item("Water", 1));
  438. }
  439. }
  440. else
  441. {
  442. Console.WriteLine("You fail to find any water." + Environment.NewLine);
  443. }
  444. }
  445.  
  446. static void Eat()
  447. {
  448. Item? foodItem = inventory.Find(item => item.Name == "Food");
  449. if (foodItem != null && foodItem.Quantity > 0)
  450. {
  451. foodItem.Quantity -= 1;
  452. foodCount -= 1;
  453. Console.ForegroundColor = ConsoleColor.Green;
  454. Console.WriteLine("You eat some food and restore some hunger." + Environment.NewLine);
  455. Console.ResetColor();
  456. hunger += 30;
  457. hunger = Math.Clamp(hunger, 0, 100);
  458. }
  459. else
  460. {
  461. Console.WriteLine("You do not have any food to eat." + Environment.NewLine);
  462. }
  463. }
  464.  
  465. static void Drink()
  466. {
  467. Item? waterItem = inventory.Find(item => item.Name == "Water");
  468. if (waterItem != null && waterItem.Quantity > 0)
  469. {
  470. waterItem.Quantity -= 1;
  471. waterCount -= 1;
  472. Console.ForegroundColor = ConsoleColor.Green;
  473. Console.WriteLine("You drink some water and restore some thirst." + Environment.NewLine);
  474. Console.ResetColor();
  475. thirst += 30;
  476. thirst = Math.Clamp(thirst, 0, 100);
  477. }
  478. else
  479. {
  480. Console.WriteLine("You do not have any water to drink." + Environment.NewLine);
  481. }
  482. }
  483.  
  484. static void Bandage()
  485. {
  486. if (bandages >= 1)
  487. {
  488. Item? healthItem = inventory.Find(item => item.Name == "Bandages");
  489. if (healthItem != null && healthItem.Quantity > 0)
  490. {
  491. healthItem.Quantity -= 1;
  492. bandages -= 1;
  493. Console.ForegroundColor = ConsoleColor.Green;
  494. Console.WriteLine("You use a bandage to heal.");
  495. Console.ResetColor();
  496. health += 30;
  497. health = Math.Clamp(health ,0, 100);
  498. }
  499. }
  500. else
  501. {
  502. Console.WriteLine("Not enough bandages.");
  503. }
  504. }
  505.  
  506. static void CheckInventory()
  507. {
  508. inInventory = true;
  509.  
  510. while (inInventory)
  511. {
  512. Console.Write(Environment.NewLine);
  513. Console.WriteLine("Inventory:");
  514. foreach (Item item in inventory)
  515. {
  516. Console.WriteLine(item.Name + " x" + item.Quantity);
  517. }
  518. Console.Write(Environment.NewLine);
  519.  
  520. Console.WriteLine("########################");
  521. Console.WriteLine("1. Eat some food");
  522. Console.WriteLine("2. Drink some water");
  523. Console.WriteLine("3. Use a bandage");
  524. Console.WriteLine("4. Close inventory");
  525. Console.WriteLine("########################");
  526.  
  527. string? choice = Console.ReadLine();
  528.  
  529. switch (choice)
  530. {
  531. case "1":
  532. Eat();
  533. break;
  534. case "2":
  535. Drink();
  536. break;
  537. case "3":
  538. Bandage();
  539. break;
  540. case "4":
  541. inInventory = false;
  542. break;
  543. default:
  544. Console.ForegroundColor = ConsoleColor.DarkRed;
  545. Console.WriteLine("Invalid choice. Please try again.");
  546. Console.ResetColor();
  547. break;
  548. }
  549. }
  550. }
  551.  
  552. static void Rest()
  553. {
  554. Console.WriteLine("You rest and regain some energy.");
  555.  
  556. energy += 50;
  557. energy = Math.Clamp(energy, 0, 100);
  558. thirst -= 20;
  559. hunger -= 20;
  560. }
  561.  
  562. static void UpdateStatus()
  563. {
  564. Console.WriteLine("One turn passes..");
  565.  
  566. hunger -= 5;
  567. thirst -= 5;
  568. energy -= 10;
  569.  
  570. if (health < 0)
  571. {
  572. GameOver();
  573. }
  574.  
  575. if (hunger <= 0)
  576. {
  577. Console.ForegroundColor = ConsoleColor.Red;
  578. Console.WriteLine("You died of hunger.");
  579. Console.ResetColor();
  580. Environment.Exit(2);
  581. }
  582.  
  583. if (thirst <= 0)
  584. {
  585. Console.ForegroundColor = ConsoleColor.Red;
  586. Console.WriteLine("You died of thirst.");
  587. Console.ResetColor();
  588. Environment.Exit(2);
  589. }
  590. }
  591.  
  592. static void CheckStatus()
  593. {
  594. Console.WriteLine("Current status:");
  595. Console.ForegroundColor = ConsoleColor.Red;
  596. Console.WriteLine("Health: {0}", health);
  597. Console.ResetColor();
  598. Console.ForegroundColor = ConsoleColor.DarkYellow;
  599. Console.WriteLine("Energy: {0}", energy);
  600. Console.WriteLine("Hunger: {0}", hunger);
  601. Console.ResetColor();
  602. Console.ForegroundColor = ConsoleColor.Cyan;
  603. Console.WriteLine("Thirst: {0}", thirst);
  604. Console.ResetColor();
  605. }
  606.  
  607. static void Combat()
  608. {
  609. inCombat = true;
  610.  
  611. Console.WriteLine("You open fire on the enemy!" + Environment.NewLine);
  612.  
  613. while (health > 0 && inCombat && inShop == false)
  614. {
  615. ammo -= 1;
  616.  
  617. Item? ammoItem = inventory.Find(item => item.Name == "Ammunition");
  618. if (ammoItem != null && ammoItem.Quantity > 0)
  619. {
  620. ammoItem.Quantity -= 1;
  621. ammo -= 1;
  622. }
  623.  
  624. utils.SmallArms();
  625.  
  626. if (ammo <= 0)
  627. {
  628. Console.WriteLine("You have no ammunition left.");
  629.  
  630. Console.WriteLine("What do you want to do?" + Environment.NewLine);
  631. Console.WriteLine("1. Attempt to take cover.");
  632. Console.WriteLine("2. Attempt to retreat away.");
  633. Console.WriteLine("3. Use a bandage.");
  634. Console.WriteLine("##############################");
  635.  
  636. string? playerCombatAction = Console.ReadLine();
  637.  
  638. switch (playerCombatAction)
  639. {
  640. case "1":
  641. Console.WriteLine("You attempt to take cover." + Environment.NewLine);
  642.  
  643. int enemyHitChance = rand.Next(0, 3);
  644.  
  645. if (enemyHitChance == 0)
  646. {
  647. Console.WriteLine("The enemy missed you while you were in cover.");
  648. }
  649. else
  650. {
  651. utils.SmallArms();
  652.  
  653. health -= enemy.damage;
  654.  
  655. Console.Write("The enemy hits you while you were in cover and deals ");
  656. Console.ForegroundColor = ConsoleColor.Red;
  657. Console.Write(enemy.damage);
  658. Console.ResetColor();
  659. Console.Write(" damage.");
  660. Console.Write(Environment.NewLine);
  661.  
  662. if (health <= 0)
  663. {
  664. GameOver();
  665. }
  666. }
  667. break;
  668. case "2":
  669. Console.WriteLine("You attempt to retreat." + Environment.NewLine);
  670.  
  671. int retreatChance = rand.Next(0, 2);
  672.  
  673. if (retreatChance == 0)
  674. {
  675. Console.WriteLine("You successfully retreat." + Environment.NewLine);
  676. utils.Move();
  677. inCombat = false;
  678. }
  679. else
  680. {
  681. utils.SmallArms();
  682.  
  683. Console.WriteLine("You attempt to retreat but fail." + Environment.NewLine);
  684.  
  685. health -= enemy.damage;
  686.  
  687. Console.Write("The enemy hits you and deals ");
  688. Console.ForegroundColor = ConsoleColor.Red;
  689. Console.Write(enemy.damage);
  690. Console.ResetColor();
  691. Console.Write(" damage.");
  692. Console.Write(Environment.NewLine);
  693.  
  694. if (health <= 0)
  695. {
  696. GameOver();
  697. }
  698. }
  699. break;
  700. case "3":
  701. Bandage();
  702.  
  703. Console.ForegroundColor = ConsoleColor.Green;
  704. Console.WriteLine("You now have " + health + " health.");
  705. Console.ResetColor();
  706. break;
  707. default:
  708. utils.WriteColor("Invalid input.", ConsoleColor.Red, Environment.NewLine);
  709. break;
  710. }
  711. }
  712.  
  713. int dealDamage = rand.Next(50, 100);
  714. int hitChance = rand.Next(0, 2);
  715.  
  716. if (hitChance == 1)
  717. {
  718. enemy.health -= dealDamage;
  719.  
  720. Console.Write("You manage to hit the enemy and deal ");
  721. Console.ForegroundColor = ConsoleColor.Red;
  722. Console.Write(dealDamage);
  723. Console.ResetColor();
  724. Console.Write(" damage. ");
  725. Console.Write(Environment.NewLine);
  726.  
  727. if (enemy.health <= 0)
  728. {
  729. inCombat = false;
  730.  
  731. enemy.health = 100;
  732.  
  733. Console.Write("You successfully kill the enemy!" + Environment.NewLine);
  734. }
  735. else
  736. {
  737. CombatMenu();
  738.  
  739. string? playerCombatAction = Console.ReadLine();
  740.  
  741. switch (playerCombatAction)
  742. {
  743. case "1":
  744. Console.WriteLine("You open fire on the enemy!" + Environment.NewLine);
  745. break;
  746. case "2":
  747. Console.WriteLine("You attempt to take cover." + Environment.NewLine);
  748.  
  749. int enemyHitChance = rand.Next(0, 3);
  750.  
  751. if (enemyHitChance == 0)
  752. {
  753. Console.WriteLine("The enemy missed you while you were in cover.");
  754. }
  755. else
  756. {
  757. utils.SmallArms();
  758.  
  759. health -= enemy.damage;
  760.  
  761. Console.Write("The enemy hits you while you were in cover and deals ");
  762. Console.ForegroundColor = ConsoleColor.Red;
  763. Console.Write(enemy.damage);
  764. Console.ResetColor();
  765. Console.Write(" damage.");
  766. Console.Write(Environment.NewLine);
  767.  
  768. if (health <= 0)
  769. {
  770. GameOver();
  771. }
  772. }
  773. break;
  774. case "3":
  775. Console.WriteLine("You attempt to retreat." + Environment.NewLine);
  776.  
  777. int retreatChance = rand.Next(0, 2);
  778.  
  779. if (retreatChance == 0)
  780. {
  781. Console.WriteLine("You successfully retreat." + Environment.NewLine);
  782. utils.Move();
  783. inCombat = false;
  784. }
  785. else
  786. {
  787. utils.SmallArms();
  788.  
  789. Console.WriteLine("You attempt to retreat but fail." + Environment.NewLine);
  790.  
  791. health -= enemy.damage;
  792.  
  793. Console.Write("The enemy hits you and deals ");
  794. Console.ForegroundColor = ConsoleColor.Red;
  795. Console.Write(enemy.damage);
  796. Console.ResetColor();
  797. Console.Write(" damage.");
  798. Console.Write(Environment.NewLine);
  799.  
  800. if (health <= 0)
  801. {
  802. GameOver();
  803. }
  804. }
  805. break;
  806. case "4":
  807. Bandage();
  808.  
  809. Console.ForegroundColor = ConsoleColor.Green;
  810. Console.WriteLine("You now have " + health + " health.");
  811. Console.ResetColor();
  812. break;
  813. default:
  814. utils.WriteColor("Invalid input.", ConsoleColor.Red, Environment.NewLine);
  815. break;
  816. }
  817. }
  818. }
  819. else if (hitChance == 0)
  820. {
  821. Console.Write("You fire at the enemy but miss." + Environment.NewLine);
  822.  
  823. if (rand.Next(0, 2) == 0)
  824. {
  825. Console.WriteLine("The enemy fires but misses you.");
  826. }
  827. else
  828. {
  829. health -= enemy.damage;
  830.  
  831. Console.Write("The enemy hits you and deals ");
  832. Console.ForegroundColor = ConsoleColor.Red;
  833. Console.Write(enemy.damage);
  834. Console.ResetColor();
  835. Console.Write(" damage.");
  836. Console.Write(Environment.NewLine);
  837.  
  838. if (health <= 0)
  839. {
  840. GameOver();
  841. }
  842. else
  843. {
  844. CombatMenu();
  845.  
  846. string? playerCombatAction = Console.ReadLine();
  847.  
  848. switch (playerCombatAction)
  849. {
  850. case "1":
  851. Console.WriteLine("You open fire on the enemy!" + Environment.NewLine);
  852. break;
  853. case "2":
  854. Console.WriteLine("You attempt to take cover." + Environment.NewLine);
  855.  
  856. int enemyHitChance = rand.Next(0, 3);
  857.  
  858. if (enemyHitChance == 0)
  859. {
  860. Console.WriteLine("The enemy missed you while you were in cover.");
  861. }
  862. else
  863. {
  864. utils.SmallArms();
  865.  
  866. health -= enemy.damage;
  867.  
  868. Console.Write("The enemy hits you while you were in cover and deals ");
  869. Console.ForegroundColor = ConsoleColor.Red;
  870. Console.Write(enemy.damage);
  871. Console.ResetColor();
  872. Console.Write(" damage.");
  873. Console.Write(Environment.NewLine);
  874.  
  875. if (health <= 0)
  876. {
  877. GameOver();
  878. }
  879. }
  880. break;
  881. case "3":
  882. Console.WriteLine("You attempt to retreat." + Environment.NewLine);
  883.  
  884. int retreatChance = rand.Next(0, 2);
  885.  
  886. if (retreatChance == 0)
  887. {
  888. Console.WriteLine("You successfully retreat." + Environment.NewLine);
  889. utils.Move();
  890. inCombat = false;
  891. }
  892. else
  893. {
  894. utils.SmallArms();
  895.  
  896. Console.WriteLine("You attempt to retreat but fail." + Environment.NewLine);
  897.  
  898. health -= enemy.damage;
  899.  
  900. Console.Write("The enemy hits you and deals ");
  901. Console.ForegroundColor = ConsoleColor.Red;
  902. Console.Write(enemy.damage);
  903. Console.ResetColor();
  904. Console.Write(" damage.");
  905. Console.Write(Environment.NewLine);
  906.  
  907. if (health <= 0)
  908. {
  909. GameOver();
  910. }
  911. }
  912. break;
  913. case "4":
  914. Bandage();
  915.  
  916. Console.ForegroundColor = ConsoleColor.Green;
  917. Console.WriteLine("You now have " + health + " health.");
  918. Console.ResetColor();
  919. break;
  920. default:
  921. utils.WriteColor("Invalid input.", ConsoleColor.Red, Environment.NewLine);
  922. break;
  923. }
  924. }
  925. }
  926. }
  927. }
  928. }
  929.  
  930. static void Villager()
  931. {
  932. Console.WriteLine("You encounter a villager!" + Environment.NewLine);
  933. Console.WriteLine("He seems to have a few items to trade." + Environment.NewLine);
  934.  
  935. while (health > 0 && inShop && inCombat == false)
  936. {
  937. ShopMenu();
  938.  
  939. string? choice = Console.ReadLine();
  940. if (!int.TryParse(choice, out int menuChoice))
  941. {
  942. Console.ForegroundColor = ConsoleColor.DarkRed;
  943. Console.WriteLine("Invalid choice. Please try again.");
  944. Console.ResetColor();
  945. continue;
  946. }
  947.  
  948. switch (menuChoice)
  949. {
  950. case 1:
  951. if (HasEnoughEnergy(1))
  952. {
  953. BuyAmmo();
  954. }
  955. break;
  956. case 2:
  957. if (HasEnoughEnergy(1))
  958. {
  959. SellAmmo();
  960. }
  961. break;
  962. case 3:
  963. if (HasEnoughEnergy(1))
  964. {
  965. BuyFood();
  966. }
  967. break;
  968. case 4:
  969. if (HasEnoughEnergy(1))
  970. {
  971. BuyWater();
  972. }
  973. break;
  974. case 5:
  975. if (HasEnoughEnergy(1))
  976. {
  977. SellFood();
  978. }
  979. break;
  980. case 6:
  981. if (HasEnoughEnergy(1))
  982. {
  983. SellWater();
  984. }
  985. break;
  986. case 7:
  987. break;
  988. case 9:
  989. break;
  990. default:
  991. Console.ForegroundColor = ConsoleColor.DarkRed;
  992. Console.WriteLine("Invalid choice. Please try again.");
  993. Console.ResetColor();
  994. break;
  995. }
  996. }
  997. }
  998.  
  999. static void Animal()
  1000. {
  1001. inCombat = true;
  1002.  
  1003. Console.WriteLine("You encounter an animal!" + Environment.NewLine);
  1004. Console.WriteLine("It did not spot you yet, perhaps you can sneak up and kill it?" + Environment.NewLine);
  1005.  
  1006. while (health > 0 && inShop == false)
  1007. {
  1008.  
  1009. AnimalMenu();
  1010.  
  1011. string? choice = Console.ReadLine();
  1012. if (!int.TryParse(choice, out int menuChoice))
  1013. {
  1014. Console.ForegroundColor = ConsoleColor.DarkRed;
  1015. Console.WriteLine("Invalid choice. Please try again.");
  1016. Console.ResetColor();
  1017. continue;
  1018. }
  1019.  
  1020. switch (menuChoice)
  1021. {
  1022. case 1:
  1023. if (HasEnoughEnergy(1))
  1024. {
  1025. }
  1026. break;
  1027. case 2:
  1028. if (HasEnoughEnergy(1))
  1029. {
  1030. }
  1031. break;
  1032. case 3:
  1033. if (HasEnoughEnergy(1))
  1034. {
  1035. }
  1036. break;
  1037. case 4:
  1038. if (HasEnoughEnergy(1))
  1039. {
  1040. }
  1041. break;
  1042. case 5:
  1043. if (HasEnoughEnergy(1))
  1044. {
  1045. }
  1046. break;
  1047. case 6:
  1048. if (HasEnoughEnergy(1))
  1049. {
  1050. }
  1051. break;
  1052. case 7:
  1053. break;
  1054. case 9:
  1055. break;
  1056. default:
  1057. Console.ForegroundColor = ConsoleColor.DarkRed;
  1058. Console.WriteLine("Invalid choice. Please try again.");
  1059. Console.ResetColor();
  1060. break;
  1061. }
  1062. }
  1063. }
  1064.  
  1065. #region Buy/Sell
  1066. static void BuyAmmo()
  1067. {
  1068. Item? marksItem = inventory.Find(item => item.Name == "Marks");
  1069. if (marksItem != null && marksItem.Quantity >= 10)
  1070. {
  1071. marksItem.Quantity -= 10;
  1072. marks -= 10;
  1073.  
  1074. Item? ammoItem = inventory.Find(item => item.Name == "Ammunition");
  1075. if (ammoItem != null)
  1076. {
  1077. ammoItem.Quantity += 5;
  1078. ammo += 5;
  1079. }
  1080. else
  1081. {
  1082. inventory.Add(new Item("Ammunition", 5));
  1083. }
  1084.  
  1085. Console.ForegroundColor = ConsoleColor.Green;
  1086. Console.WriteLine("You purchase some ammunition." + Environment.NewLine);
  1087. Console.ResetColor();
  1088. }
  1089. else
  1090. {
  1091. Console.WriteLine("You do not have enough money." + Environment.NewLine);
  1092. }
  1093. }
  1094.  
  1095. static void SellAmmo()
  1096. {
  1097. Item? ammoItem = inventory.Find(item => item.Name == "Ammunition");
  1098. if (ammoItem != null && ammoItem.Quantity >= 5)
  1099. {
  1100. ammoItem.Quantity -= 5;
  1101. ammo -= 5;
  1102.  
  1103. Item? marksItem = inventory.Find(item => item.Name == "Marks");
  1104. if (marksItem != null)
  1105. {
  1106. marksItem.Quantity += 5;
  1107. marks += 5;
  1108. }
  1109. else
  1110. {
  1111. inventory.Add(new Item("Marks", 5));
  1112. }
  1113.  
  1114. Console.ForegroundColor = ConsoleColor.Green;
  1115. Console.WriteLine("You sell some ammunition." + Environment.NewLine);
  1116. Console.ResetColor();
  1117. }
  1118. else
  1119. {
  1120. Console.WriteLine("You do not have enough ammunition." + Environment.NewLine);
  1121. }
  1122. }
  1123.  
  1124. static void BuyFood()
  1125. {
  1126. Item? marksItem = inventory.Find(item => item.Name == "Marks");
  1127. if (marksItem != null && marksItem.Quantity >= 15)
  1128. {
  1129. marksItem.Quantity -= 15;
  1130. marks -= 15;
  1131.  
  1132. Item? foodItem = inventory.Find(item => item.Name == "Food");
  1133. if (foodItem != null)
  1134. {
  1135. foodItem.Quantity += 1;
  1136. foodCount += 1;
  1137. }
  1138. else
  1139. {
  1140. inventory.Add(new Item("Food", 1));
  1141. }
  1142.  
  1143. Console.ForegroundColor = ConsoleColor.Green;
  1144. Console.WriteLine("You purchase some food." + Environment.NewLine);
  1145. Console.ResetColor();
  1146. }
  1147. else
  1148. {
  1149. Console.WriteLine("You do not have enough money." + Environment.NewLine);
  1150. }
  1151. }
  1152.  
  1153. static void BuyWater()
  1154. {
  1155. Item? marksItem = inventory.Find(item => item.Name == "Marks");
  1156. if (marksItem != null && marksItem.Quantity >= 15)
  1157. {
  1158. marksItem.Quantity -= 15;
  1159. marks -= 15;
  1160.  
  1161. Item? waterItem = inventory.Find(item => item.Name == "Water");
  1162. if (waterItem != null)
  1163. {
  1164. waterItem.Quantity += 1;
  1165. waterCount += 1;
  1166. }
  1167. else
  1168. {
  1169. inventory.Add(new Item("Water", 1));
  1170. }
  1171.  
  1172. Console.ForegroundColor = ConsoleColor.Green;
  1173. Console.WriteLine("You purchase some water." + Environment.NewLine);
  1174. Console.ResetColor();
  1175. }
  1176. else
  1177. {
  1178. Console.WriteLine("You do not have enough money." + Environment.NewLine);
  1179. }
  1180. }
  1181.  
  1182. static void SellFood()
  1183. {
  1184. Item? foodItem = inventory.Find(item => item.Name == "Food");
  1185. if (foodItem != null && foodItem.Quantity >= 1)
  1186. {
  1187. foodItem.Quantity -= 1;
  1188. foodCount -= 1;
  1189.  
  1190. Item? marksItem = inventory.Find(item => item.Name == "Marks");
  1191. if (marksItem != null)
  1192. {
  1193. marksItem.Quantity += 10;
  1194. marks += 10;
  1195. }
  1196. else
  1197. {
  1198. inventory.Add(new Item("Marks", 10));
  1199. }
  1200.  
  1201. Console.ForegroundColor = ConsoleColor.Green;
  1202. Console.WriteLine("You sell some food." + Environment.NewLine);
  1203. Console.ResetColor();
  1204. }
  1205. else
  1206. {
  1207. Console.WriteLine("You do not have enough food." + Environment.NewLine);
  1208. }
  1209. }
  1210.  
  1211. static void SellWater()
  1212. {
  1213. Item? waterItem = inventory.Find(item => item.Name == "Water");
  1214. if (waterItem != null && waterItem.Quantity >= 1)
  1215. {
  1216. waterItem.Quantity -= 1;
  1217. waterCount -= 1;
  1218.  
  1219. Item? marksItem = inventory.Find(item => item.Name == "Marks");
  1220. if (marksItem != null)
  1221. {
  1222. marksItem.Quantity += 10;
  1223. marks += 10;
  1224. }
  1225. else
  1226. {
  1227. inventory.Add(new Item("Marks", 10));
  1228. }
  1229.  
  1230. Console.ForegroundColor = ConsoleColor.Green;
  1231. Console.WriteLine("You sell some water." + Environment.NewLine);
  1232. Console.ResetColor();
  1233. }
  1234. else
  1235. {
  1236. Console.WriteLine("You do not have enough water." + Environment.NewLine);
  1237. }
  1238. }
  1239. #endregion
  1240.  
  1241. static void GameOver()
  1242. {
  1243. if (health < 0)
  1244. {
  1245. Console.ForegroundColor = ConsoleColor.Red;
  1246. Console.WriteLine("You die from major injuries.");
  1247. Console.ResetColor();
  1248. Environment.Exit(2);
  1249. }
  1250. }
  1251. }
  1252.  
  1253. public class Item
  1254. {
  1255. public string Name { get; set; }
  1256. public int Quantity { get; set; }
  1257.  
  1258. public Item(string name, int quantity)
  1259. {
  1260. Name = name;
  1261. Quantity = quantity;
  1262. }
  1263. }
  1264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement