Advertisement
Frostyy22

chatgpt9

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