Guest User

Untitled

a guest
Feb 20th, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8. public class Character
  9. {
  10. static Random random = new Random(Environment.TickCount); // Static -- each instance of Character class uses this same variable.
  11. static int attackRoll;
  12.  
  13. // Member variables. Each instance of the Character class gets a copy of all.
  14. public string Name;
  15. public int Strength, Dexterity, Intelligence, Health, MaxHitPoints, HitPoints, WeaponSkill, Armor, Gold;
  16. public float Speed, SwingDamageType, ThrustDamageType;
  17. public bool Alive;
  18.  
  19. public Character(string name, int strength, int dexterity, int intelligence, int health, int maxHitPoints, int hitPoints, int weaponSkill,
  20. int armor, int gold, float speed, float swingDamageType, float thrustDamageType, bool alive) // Constructor.
  21. {
  22. // Begin initializing member variables:
  23. Name = name;
  24. Strength = strength;
  25. Dexterity = dexterity;
  26. Intelligence = intelligence;
  27. MaxHitPoints = maxHitPoints;
  28. HitPoints = hitPoints;
  29. Speed = speed;
  30. WeaponSkill = weaponSkill;
  31. Armor = armor;
  32. Gold = gold;
  33. Speed = speed;
  34. SwingDamageType = swingDamageType;
  35. ThrustDamageType = thrustDamageType;
  36. Alive = alive;
  37. } // End constructor.
  38.  
  39. public void Combat(Character target) //Combat function.
  40. {
  41. Console.WriteLine("\nDo you wish to (A)ttack, (D)efend, Attack to (H)it Location, or chose a (T)actical Option?\n");
  42. string combatChoice = Console.ReadLine();
  43. switch (combatChoice.ToUpper())
  44. {
  45. case "A":
  46. Console.WriteLine("\nDo you wish to (S)wing or (T)hrust?\n");
  47. string swingOrThrust = Console.ReadLine();
  48. switch (swingOrThrust.ToUpper())
  49. {
  50. case "S":
  51. Swing(target);
  52. break;
  53.  
  54. case "T":
  55. Thrust(target);
  56. break;
  57.  
  58. default:
  59. break; // Break from swingOrThrust block.
  60.  
  61. } // End swingOrThrust block.
  62.  
  63. break; // Break from case "A" and combatChoice block.
  64.  
  65. default:
  66. Console.WriteLine("\nNot a valid option!\n Press any key to continue...\n");
  67. Console.ReadKey();
  68. Console.Clear();
  69. break; // Break from combatChoice block.
  70.  
  71. } //End combatChoice swtich block.
  72.  
  73. } // End Combat function.
  74.  
  75. public void Swing(Character target)
  76. {
  77. attackRoll = random.Next(3, 18);
  78. Console.WriteLine("\nDebug: Roll = {0}.\n", attackRoll);
  79.  
  80. if (attackRoll <= WeaponSkill)
  81. {
  82. Console.WriteLine("\n{0}'s attack was successfull!\n", Name);
  83. SwingDamageRoll(target);
  84. Console.WriteLine("\nDebug: {0} has {1} HP!\n", target.Name, target.HitPoints);
  85. Console.WriteLine("\nPress any key to continue...\n");
  86. Console.ReadKey();
  87. Console.Clear();
  88. }
  89.  
  90. else
  91. {
  92. Console.WriteLine("\nThe attack misses!\n");
  93. Console.WriteLine("\nPress any key to continue...\n");
  94. Console.ReadKey();
  95. Console.Clear();
  96. }
  97.  
  98. } // End Swing function.
  99.  
  100. public void Thrust(Character target)
  101. {
  102. attackRoll = random.Next(3, 18);
  103. Console.WriteLine("\nDebug: Roll = {0}.\n", attackRoll);
  104.  
  105. if (attackRoll <= WeaponSkill)
  106. {
  107. Console.WriteLine("\n{0}'s attack was successfull!\n", Name);
  108. ThrustDamageRoll(target);
  109. Console.WriteLine("\nDebug: {0} has {1} HP!\n", target.Name, target.HitPoints);
  110. Console.WriteLine("\nPress any key to continue...\n");
  111. Console.ReadKey();
  112. Console.Clear();
  113. }
  114.  
  115. else
  116. {
  117. Console.WriteLine("\nThe attack misses!\n");
  118. Console.WriteLine("\nPress any key to continue...\n");
  119. Console.ReadKey();
  120. Console.Clear();
  121. }
  122.  
  123. } // End Thrust function.
  124.  
  125. public void SwingDamageRoll(Character target)
  126. {
  127. int damageRoll, basicDamage, injury;
  128.  
  129. if (Strength <= 2)
  130. {
  131. damageRoll = Math.Max((random.Next(1, 6) - 5), 0);
  132. }
  133.  
  134. else if (Strength == 3)
  135. {
  136. damageRoll = Math.Max((random.Next(1, 6) - 4), 0);
  137. }
  138.  
  139. else if (Strength == 4)
  140. {
  141. damageRoll = Math.Max((random.Next(1, 6) - 4), 0);
  142. }
  143.  
  144. else if (Strength == 5)
  145. {
  146. damageRoll = Math.Max((random.Next(1, 6) - 3), 0);
  147. }
  148.  
  149. else if (Strength == 6)
  150. {
  151. damageRoll = Math.Max((random.Next(1, 6) - 3), 0);
  152. }
  153.  
  154. else if (Strength == 7)
  155. {
  156. damageRoll = Math.Max((random.Next(1, 6) - 2), 0);
  157. }
  158.  
  159. else if (Strength == 8)
  160. {
  161. damageRoll = Math.Max((random.Next(1, 6) - 2), 0);
  162. }
  163.  
  164. else if (Strength == 9)
  165. {
  166. damageRoll = Math.Max((random.Next(1, 6) - 1), 0);
  167. }
  168.  
  169. else if (Strength == 10)
  170. {
  171. damageRoll = random.Next(1, 6);
  172. }
  173.  
  174. else if (Strength == 11)
  175. {
  176. damageRoll = (random.Next(1, 6)) + 1;
  177. }
  178.  
  179. else if (Strength == 12)
  180. {
  181. damageRoll = (random.Next(1, 6)) + 2;
  182. }
  183.  
  184. else if (Strength == 13)
  185. {
  186. damageRoll = (random.Next(2, 12)) - 1;
  187. }
  188.  
  189. else if (Strength == 14)
  190. {
  191. damageRoll = random.Next(2, 12);
  192. }
  193.  
  194. else if (Strength >= 15)
  195. {
  196. damageRoll = (random.Next(2, 12)) + 1;
  197. }
  198.  
  199. else
  200. {
  201. damageRoll = 0;
  202. }
  203.  
  204. basicDamage = Math.Max((damageRoll - target.Armor), 0);
  205. injury = (int)(basicDamage * SwingDamageType);
  206. target.HitPoints -= injury;
  207. Console.WriteLine("\nRolling for damage... {0} rolled {1} and did {2} damage.\n", Name, damageRoll, injury);
  208. AliveOrDead(target);
  209.  
  210. } // End Swing Damage Roll function.
  211.  
  212. public void ThrustDamageRoll(Character target)
  213. {
  214. int damageRoll, basicDamage, injury;
  215.  
  216. if (Strength <= 2)
  217. {
  218. damageRoll = Math.Max((random.Next(1, 6) - 6), 0);
  219. }
  220.  
  221. else if (Strength == 3)
  222. {
  223. damageRoll = Math.Max((random.Next(1, 6) - 5), 0);
  224. }
  225.  
  226. else if (Strength == 4)
  227. {
  228. damageRoll = Math.Max((random.Next(1, 6) - 5), 0);
  229. }
  230.  
  231. else if (Strength == 5)
  232. {
  233. damageRoll = Math.Max((random.Next(1, 6) - 4), 0);
  234. }
  235.  
  236. else if (Strength == 6)
  237. {
  238. damageRoll = Math.Max((random.Next(1, 6) - 4), 0);
  239. }
  240.  
  241. else if (Strength == 7)
  242. {
  243. damageRoll = Math.Max((random.Next(1, 6) - 3), 0);
  244. }
  245.  
  246. else if (Strength == 8)
  247. {
  248. damageRoll = Math.Max((random.Next(1, 6) - 3), 0);
  249. }
  250.  
  251. else if (Strength == 9)
  252. {
  253. damageRoll = Math.Max((random.Next(1, 6) - 2), 0);
  254. }
  255.  
  256. else if (Strength == 10)
  257. {
  258. damageRoll = Math.Max((random.Next(1, 6) - 2), 0);
  259. }
  260.  
  261. else if (Strength == 11)
  262. {
  263. damageRoll = Math.Max((random.Next(1, 6) - 1), 0);
  264. }
  265.  
  266. else if (Strength == 12)
  267. {
  268. damageRoll = Math.Max((random.Next(1, 6) - 1), 0);
  269. }
  270.  
  271. else if (Strength == 13)
  272. {
  273. damageRoll = random.Next(1, 6);
  274. }
  275.  
  276. else if (Strength == 14)
  277. {
  278. damageRoll = random.Next(1, 6);
  279. }
  280.  
  281. else if (Strength >= 15)
  282. {
  283. damageRoll = (random.Next(1, 6)) + 1;
  284. }
  285.  
  286. else
  287. {
  288. damageRoll = 0;
  289. }
  290.  
  291. basicDamage = Math.Max((damageRoll - target.Armor), 0);
  292. injury = (int) (basicDamage * ThrustDamageType);
  293. target.HitPoints -= injury;
  294. Console.WriteLine("\nRolling for damage... {0} rolled {1} and did {2} damage.\n", Name, damageRoll, injury);
  295. AliveOrDead(target);
  296.  
  297. } // End Thrust Damage Roll function.
  298.  
  299. public void AliveOrDead(Character target)
  300. {
  301. if (target.HitPoints <= 0)
  302. {
  303. target.Alive = false;
  304. Console.WriteLine("\n{0} was slain!\n", target.Name);
  305. }
  306.  
  307. } // End Alive Or Dead function.
  308.  
  309. } // End Character class.
  310.  
  311. class Program
  312. {
  313. // Declare the Random class, give it the name "random," then make a new instance of the Random class:
  314. static Random random = new Random(Environment.TickCount);
  315. static bool gameRunning = true;
  316.  
  317. static void EndFight(Character player, Character target)
  318. {
  319. if (player.Alive == false)
  320. {
  321. Console.Clear();
  322. Console.WriteLine(@"
  323. ________ ________
  324. / _____/_____ _____ ____ \_____ \___ __ ___________
  325. ╔══/ \ ___\__ \══/ \_/ __ \═══/ | \ \/ // __ \_ __ \══╗
  326. ║ \ \_\ \/ __ \| Y Y \ ___/ / | \ /\ ___/| | \/ ║
  327. ║ \______ (____ /__|_| /\___ > \_______ /\_/ \___ >__| ║
  328. ╚══════════\/═════\/══════\/═════\/══════════\/══════════\/═════════╝
  329.  
  330.  
  331.  
  332. YOU DIED IN THE ARENA!");
  333.  
  334. Console.ReadKey();
  335. Console.Clear();
  336. gameRunning = false;
  337. }
  338.  
  339. if (target.Alive == false)
  340. {
  341. player.Gold += target.Gold;
  342. }
  343.  
  344. } // End End Fight function.
  345.  
  346. static void Main(string[] args) //The Main function.
  347. {
  348. // Create instances of the Character class:
  349. // (string name, int strength, int dexterity, int intelligence, int health, int maxHitPoints, int hitPoints, int speed, int weaponSkill, int armor, float speed, bool alive)
  350. Character player = new Character("", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0F, 1F, 1F, true);
  351.  
  352.  
  353. // Begin game:
  354.  
  355. Console.WriteLine(@"
  356. ENTER...
  357. ___________ __ _____
  358. \__ ___/| |__ ____ / _ \_______ ____ ____ _____
  359. ╔═══| |═══| | \_/ __ \═══/ /_\ \_ __ \_/ __ \ / \\__ \════╗
  360. ║ | | | Y \ ___/ / | \ | \/\ ___/| | \/ __ \_ ║
  361. ║ |____| |___| /\___ > \____|__ /__| \___ >___| (____ / ║
  362. ╚═════════════════\/═════\/══════════\/════════════\/═════\/═════\/═══╝
  363.  
  364. ...IF YOU DARE!
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373. Press any key...
  374.  
  375. ''The Arena'' by Richard D. Sharpe
  376. camaro_driver@hotmail.com
  377. *** Special thanks to GameDev.net! ***
  378. version 0.102611.01");
  379. Console.ReadKey();
  380. Console.Clear();
  381.  
  382. while (gameRunning)
  383. {
  384. Console.WriteLine(@"
  385.  
  386. ╔═════════════════ MAIN MENU ═════════════════╗
  387. ║ (C)reate a Character ╔═══ Character ═══╗ ║
  388. ║ (D)isplay Character ║ Name:{0} ║ ║
  389. ║ (E)quipment ║ Hit Points: {1} ║ ║
  390. ║ (S)leep ║ Level: ║ ║
  391. ║ (H)ealer ║ EXP: ║ ║
  392. ║ (A)rmory ║ Gold: {2} ║ ║
  393. ║ (F)ight in the arena! ╚═════════════════╝ ║
  394. ╚═════════════════════════════════════════════╝", player.Name.PadLeft(10), player.HitPoints.ToString().PadLeft(3), player.Gold.ToString().PadLeft(6));
  395.  
  396. Console.WriteLine("\n");
  397.  
  398. Console.WriteLine(" Make your selection: \n");
  399. string menuChoice = Console.ReadLine();
  400. switch (menuChoice.ToUpper())
  401. {
  402. case "C":
  403. Console.Clear();
  404.  
  405. if (player.Name == "")
  406. {
  407. Console.WriteLine("\nCurrently, no character creation functions are available in this version.\n");
  408. Console.WriteLine("\nName your character: \n");
  409. player.Name = Console.ReadLine();
  410. player.Strength = 14;
  411. player.Dexterity = 12;
  412. player.Intelligence = 10;
  413. player.Health = 12;
  414. player.MaxHitPoints = 14;
  415. player.HitPoints = 14;
  416. player.WeaponSkill = 12;
  417. player.Gold = 250;
  418. player.Speed = 6.00F;
  419. Console.WriteLine("\nCharacter created!\n");
  420. }
  421. else
  422. {
  423. Console.WriteLine("You have already created a character named {0}.\n", player.Name);
  424. }
  425.  
  426. Console.WriteLine("\nPress any key to continue... ");
  427. Console.ReadKey();
  428.  
  429. Console.Clear();
  430. break; // End 'C' case.
  431.  
  432. case "D":
  433. Console.Clear();
  434. Console.WriteLine(@"
  435.  
  436. ╔═══════════════ CHARACTER SHEET ═══════════════╗
  437. ║ ║
  438. ║ Name: {0} ║
  439. ║ Species: ║
  440. ║ Class: ║
  441. ║ ║
  442. ║ ╔═══ Attributes ════╗╔══ Characteristics ═══╗ ║
  443. ║ ║ Strength: {1} ║║ Hit Points: {5} ║ ║
  444. ║ ║ Dexterity: {2} ║║ Willpower: ║ ║
  445. ║ ║ Intelligence: {3} ║║ Perception: ║ ║
  446. ║ ║ Health: {4} ║║ Fatigue Points: ║ ║
  447. ║ ╚═══════════════════╝╚══════════════════════╝ ║
  448. ║ ╔═══════ Armor ════════╦════ Equipment ═════╗ ║
  449. ║ ║ Helmet: ║ R. Hand: ║ ║
  450. ║ ║ Body: ║ L. Hand: ║ ║
  451. ║ ║ Arms: ╠════════════════════╣ ║
  452. ║ ║ Hands: ║ Gold: ║ ║
  453. ║ ║ Legs: ║ Ring: ║ ║
  454. ║ ║ Feet: ║ Necklace: ║ ║
  455. ║ ╚══════════════════════╩════════════════════╝ ║
  456. ╚═══════════════════════════════════════════════╝", player.Name.PadRight(10),
  457. player.Strength.ToString().PadLeft(3),
  458. player.Dexterity.ToString().PadLeft(3),
  459. player.Intelligence.ToString().PadLeft(3),
  460. player.Health.ToString().PadLeft(3),
  461. player.MaxHitPoints.ToString().PadLeft(3));
  462.  
  463. Console.WriteLine("\nPress any key to continue... ");
  464. Console.ReadKey();
  465.  
  466. Console.Clear();
  467. break;
  468.  
  469. case "E":
  470. Console.Clear();
  471. Console.WriteLine("This selection not yet implemented.");
  472. Console.WriteLine("\nPress any key...");
  473. Console.ReadKey();
  474. Console.Clear();
  475. break;
  476.  
  477. case "S":
  478. Console.Clear();
  479. Console.WriteLine("This selection not yet implemented.");
  480. Console.WriteLine("\nPress any key...");
  481. Console.ReadKey();
  482. Console.Clear();
  483. break;
  484.  
  485. case "H":
  486. Console.Clear();
  487. Console.WriteLine("This selection not yet implemented.");
  488. Console.WriteLine("\nPress any key...");
  489. Console.ReadKey();
  490. Console.Clear();
  491. break;
  492.  
  493. case "A":
  494. bool shopping = true;
  495. Console.Clear();
  496. do
  497. {
  498. Console.WriteLine(@"
  499.  
  500. ╔══════════════════ ARMORY ═══════════════════╗
  501. ║ ║
  502. ║╔═══════ Armor ════════╗ ╔═══ Character ═══╗ ║
  503. ║║ 1. Leather $ 250 ║ ║ Name:{0} ║ ║
  504. ║║ 2. Chain $ 1000 ║ ║ Gold: {1} ║ ║
  505. ║╠══════ Weapons ═══════╣ ║ ║ ║
  506. ║║ 3. Club $ 100 ║ ║ ║ ║
  507. ║║ 4. Sword $ 450 ║ ║ ║ ║
  508. ║╚══════════════════════╝ ╚═════════════════╝ ║
  509. ╚═════════════════════════════════════════════╝", player.Name.PadLeft(10), player.Gold.ToString().PadLeft(6));
  510.  
  511. Console.WriteLine("\nSelect a number of the item you wish to purchace, or '0' to exit.\n");
  512.  
  513. int armoryChoice = int.Parse(Console.ReadLine());
  514. switch (armoryChoice)
  515. {
  516. case 1:
  517. {
  518. Console.WriteLine("\nDo you wish to purchace the Leather Armor for $250?\n");
  519. Console.WriteLine("(Y)es or (N)o.\n");
  520.  
  521. string yesOrNo = Console.ReadLine().ToUpper();
  522.  
  523. if (yesOrNo == "Y")
  524. {
  525. if (player.Gold >= 250)
  526. {
  527. player.Gold -= 250;
  528. player.Armor = 2;
  529. Console.WriteLine("\nPleasure do'n business with ya.\n");
  530. Console.WriteLine("\nPress any key to continue...\n");
  531. Console.ReadKey();
  532. Console.Clear();
  533. } // End check for enough gold = yes.
  534.  
  535. else
  536. {
  537. Console.WriteLine("\nBegone! Come back when you get the gold!\n");
  538. Console.WriteLine("\nPress any key to continue...\n");
  539. Console.ReadKey();
  540. Console.Clear();
  541. } // End check for enough gold = no.
  542.  
  543. } // End "Yes" if block.
  544.  
  545. else if (yesOrNo == "N")
  546. {
  547. Console.WriteLine("\nQuit wasting my time then!\n");
  548. Console.WriteLine("\nPress any key to continue...\n");
  549. Console.ReadKey();
  550. Console.Clear();
  551.  
  552. } // End "No" if block.
  553.  
  554. else
  555. {
  556. Console.WriteLine("\nNot a valid option.\n");
  557. Console.WriteLine("\nPress any key to continue...\n");
  558. Console.ReadKey();
  559. Console.Clear();
  560.  
  561. } // End catch if block.
  562.  
  563. break; // Break from Case '1.'
  564.  
  565. } // End Case '1.'
  566.  
  567. default:
  568. {
  569. shopping = false;
  570. break;
  571. }
  572.  
  573. } // End Armory Choice swtich block.
  574.  
  575. } while (shopping == true);
  576.  
  577. Console.Clear();
  578. break; // Break from 'A' case.
  579.  
  580. case "F":
  581. Console.Clear();
  582. Console.WriteLine("\nChose your opponent: (G)oblin, (O)rc.\n");
  583. string opponentChoice = Console.ReadLine();
  584. switch (opponentChoice.ToUpper())
  585. {
  586. case "G":
  587. Character goblin = new Character("the goblin", 10, 13, 9, 12, 10, 10, 14, 1, 250, 6.25F, 1.5F, 2F, true);
  588. Console.Clear();
  589. Console.WriteLine("\nYou're fighting a goblin!\n");
  590. do
  591. {
  592. if (player.Speed >= goblin.Speed)
  593. {
  594. if (player.Alive == true)
  595. {
  596. player.Combat(goblin);
  597. }
  598.  
  599. if (goblin.Alive == true)
  600. {
  601. Console.WriteLine("\nThe goblin is attacking!\n");
  602. goblin.Swing(player);
  603. }
  604.  
  605. }
  606.  
  607. else
  608. {
  609. if (goblin.Alive == true)
  610. {
  611. Console.WriteLine("\nThe goblin is attacking!\n");
  612. goblin.Swing(player);
  613. }
  614.  
  615. if (player.Alive == true)
  616. {
  617. player.Combat(goblin);
  618. }
  619.  
  620. }
  621.  
  622. } while (player.Alive == true && goblin.Alive == true);
  623.  
  624. EndFight(player, goblin);
  625.  
  626. break; // Break from combat with the goblin.
  627.  
  628. case "O":
  629. Character orc = new Character("the orc", 12, 11, 8, 12, 12, 12, 13, 2, 500, 5.75F, 1.5F, 2F, true);
  630. Console.Clear();
  631. Console.WriteLine("\nYou're fighting an orc!\n");
  632. do
  633. {
  634. if (player.Speed >= orc.Speed)
  635. {
  636. if (player.Alive == true)
  637. {
  638. player.Combat(orc);
  639. }
  640.  
  641. if (orc.Alive == true)
  642. {
  643. Console.WriteLine("\nThe orc is attacking!\n");
  644. orc.Swing(player);
  645. }
  646.  
  647. }
  648.  
  649. else
  650. {
  651. if (orc.Alive == true)
  652. {
  653. Console.WriteLine("\nThe orc is attacking!\n");
  654. orc.Swing(player);
  655. }
  656.  
  657. if (player.Alive == true)
  658. {
  659. player.Combat(orc);
  660. }
  661.  
  662. }
  663.  
  664. } while (player.Alive == true && orc.Alive == true);
  665.  
  666. EndFight(player, orc);
  667.  
  668. break; // Break from combat with the orc.
  669.  
  670. default:
  671. Console.Clear();
  672. Console.WriteLine("Not a valid choice.");
  673. break;
  674.  
  675. } // End opponenet choice.
  676.  
  677. break;
  678.  
  679. default:
  680. Console.Clear();
  681. Console.WriteLine("Not a valid selection.");
  682. Console.WriteLine("\nPress any key...");
  683. Console.ReadKey();
  684. Console.Clear();
  685. break;
  686.  
  687. } // End main menu switch.
  688.  
  689. } // End game running loop.
  690.  
  691. } // End Main.
  692.  
  693. } // End Program class.
  694.  
  695. } // End namespace.
Add Comment
Please, Sign In to add comment