Advertisement
Frostyy22

chatgpt3

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