Advertisement
Frostyy22

chatgpt4

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