Guest User

Untitled

a guest
Feb 19th, 2018
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.85 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, Speed, WeaponSkill, Armor;
  16. public bool Alive;
  17.  
  18. public Character(string name, int strength, int dexterity, int intelligence, int health, int maxHitPoints, int hitPoints, int speed,
  19. int weaponSkill, int armor, bool alive) // Constructor.
  20. {
  21. // Begin initializing member variables:
  22. Name = name;
  23. Strength = strength;
  24. Dexterity = dexterity;
  25. Intelligence = intelligence;
  26. MaxHitPoints = maxHitPoints;
  27. HitPoints = hitPoints;
  28. Speed = speed;
  29. WeaponSkill = weaponSkill;
  30. Armor = armor;
  31. Alive = alive;
  32. } // End constructor.
  33.  
  34. public void Combat(Character target) //Combat function.
  35. {
  36. Console.WriteLine("\nDo you wish to (A)ttack, (D)efend, Attack to (H)it Location, or chose a (T)actical Option?\n");
  37. string combatChoice = Console.ReadLine();
  38. switch (combatChoice.ToUpper())
  39. {
  40. case "A":
  41. Console.WriteLine("\nDo you wish to (S)wing or (T)hrust?\n");
  42. string swingOrThrust = Console.ReadLine();
  43. switch (swingOrThrust.ToUpper())
  44. {
  45. case "S":
  46. Swing(target);
  47. break;
  48.  
  49. case "T":
  50. Thrust(target);
  51. break;
  52.  
  53. default:
  54. break; // Break from swingOrThrust block.
  55.  
  56. } // Break from swingOrThrust block.
  57.  
  58. break; // Break from case "A" and combatChoice block.
  59.  
  60. default:
  61. Console.WriteLine("\nNot a valid option!\n Press any key to continue...\n");
  62. Console.ReadKey();
  63. Console.Clear();
  64. break; // Break from combatChoice block.
  65.  
  66. } //End combatChoice swtich block.
  67.  
  68. } // End Combat function.
  69.  
  70. public void Swing(Character target)
  71. {
  72. attackRoll = random.Next(3, 18);
  73. Console.WriteLine("\nDebug: Roll = {0}.\n", attackRoll);
  74.  
  75. if (attackRoll <= WeaponSkill)
  76. {
  77. Console.WriteLine("\n{0}'s attack was successfull!\n", Name);
  78. SwingDamageRoll(target);
  79. Console.WriteLine("\n{0} has {1} HP!\n", target.Name, target.HitPoints);
  80. Console.WriteLine("\nPress any key to continue...\n");
  81. Console.ReadKey();
  82. Console.Clear();
  83. }
  84.  
  85. else
  86. {
  87. Console.WriteLine("\nThe attack misses!\n");
  88. Console.WriteLine("\nPress any key to continue...\n");
  89. Console.ReadKey();
  90. Console.Clear();
  91. }
  92.  
  93. } // End Swing function.
  94.  
  95. public void Thrust(Character target)
  96. {
  97. attackRoll = random.Next(3, 18);
  98. Console.WriteLine("\nDebug: Roll = {0}.\n", attackRoll);
  99.  
  100. if (attackRoll <= WeaponSkill)
  101. {
  102. Console.WriteLine("\n{0}'s attack was successfull!\n", Name);
  103. ThrustDamageRoll(target);
  104. Console.WriteLine("\n{0} has {1} HP!\n", target.Name, target.HitPoints);
  105. Console.WriteLine("\nPress any key to continue...\n");
  106. Console.ReadKey();
  107. Console.Clear();
  108. }
  109.  
  110. else
  111. {
  112. Console.WriteLine("\nThe attack misses!\n");
  113. Console.WriteLine("\nPress any key to continue...\n");
  114. Console.ReadKey();
  115. Console.Clear();
  116. }
  117.  
  118. } // End Thrust function.
  119.  
  120. public void SwingDamageRoll(Character target)
  121. {
  122. int damageRoll, basicDamage, injury;
  123.  
  124. if (Strength == 10)
  125. {
  126. damageRoll = random.Next(1, 6);
  127. basicDamage = Math.Max((damageRoll - target.Armor), 0);
  128. injury = basicDamage; // Injury will = basic damage * int damage type. Damage type is based on weapon.
  129. target.HitPoints -= injury;
  130. Console.WriteLine("\nRolling for damage... {0} rolled {1} and did {2} damage.\n", Name, damageRoll, injury);
  131. AliveOrDead(target);
  132. }
  133.  
  134. if (Strength == 22)
  135. {
  136. damageRoll = random.Next(4, 24);
  137. basicDamage = Math.Max((damageRoll - target.Armor), 0);
  138. injury = basicDamage; // Injury will = basic damage * int damage type. Damage type is based on weapon.
  139. target.HitPoints -= injury;
  140. Console.WriteLine("\nRolling for damage... {0} rolled {1} and did {2} damage.\n", Name, damageRoll, injury);
  141. AliveOrDead(target);
  142. }
  143.  
  144. else
  145. {
  146. }
  147.  
  148. } // End Swing Damage Roll function.
  149.  
  150. public void ThrustDamageRoll(Character target)
  151. {
  152. int damageRoll, basicDamage, injury;
  153.  
  154. if (Strength == 10)
  155. {
  156. damageRoll = Math.Max((random.Next(1, 6) - 2), 0);
  157. basicDamage = Math.Max((damageRoll - target.Armor), 0);
  158. injury = basicDamage; // Injury will = basic damage * int damage type. Damage type is based on weapon.
  159. target.HitPoints -= injury;
  160. Console.WriteLine("\nRolling for damage... {0} rolled {1} and did {2} damage.\n", Name, damageRoll, injury);
  161. AliveOrDead(target);
  162. }
  163.  
  164. if (Strength == 22)
  165. {
  166. damageRoll = random.Next(2, 12);
  167. basicDamage = Math.Max((damageRoll - target.Armor), 0);
  168. injury = basicDamage; // Injury will = basic damage * int damage type. Damage type is based on weapon.
  169. target.HitPoints -= injury;
  170. Console.WriteLine("\nRolling for damage... {0} rolled {1} and did {2} damage.\n", Name, damageRoll, injury);
  171. AliveOrDead(target);
  172. }
  173.  
  174. else
  175. {
  176. }
  177.  
  178. } // End Thrust Damage Roll function.
  179.  
  180. public void AliveOrDead(Character target)
  181. {
  182. if (target.HitPoints <= 0)
  183. {
  184. target.Alive = false;
  185. Console.WriteLine("\n{0} was slain!\n", target.Name);
  186. }
  187.  
  188. } // End Alive Or Dead function.
  189.  
  190. } // End Character class.
  191.  
  192. class Program
  193. {
  194. // Declare the Random class, give it the name "random," then make a new instance of the Random class:
  195. static Random random = new Random(Environment.TickCount);
  196.  
  197. static void Main(string[] args) //The Main function.
  198. {
  199. // Create instances of the Character class:
  200. // (string name, int strength, int dexterity, int intelligence, int health, int maxHitPoints, int hitPoints, int speed, int weaponSkill, int armor, bool alive)
  201. Character player = new Character("", 0, 0, 0, 0, 0, 0, 0, 0, 0, true);
  202. Character goblin = new Character("the goblin", 10, 0, 0, 0, 10, 10, 7, 12, 1, true);
  203. Character orc = new Character("the orc", 10, 0, 0, 0, 14, 14, 5, 12, 2, true);
  204.  
  205. // Begin game:
  206.  
  207. Console.WriteLine(@"
  208. ENTER...
  209. ___________ __ _____
  210. \__ ___/| |__ ____ / _ \_______ ____ ____ _____
  211. ╔═══| |═══| | \_/ __ \═══/ /_\ \_ __ \_/ __ \ / \\__ \════╗
  212. ║ | | | Y \ ___/ / | \ | \/\ ___/| | \/ __ \_ ║
  213. ║ |____| |___| /\___ > \____|__ /__| \___ >___| (____ / ║
  214. ╚═════════════════\/═════\/══════════\/════════════\/═════\/═════\/═══╝
  215.  
  216. ...IF YOU DARE!
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225. Press any key...
  226.  
  227. ''The Arena'' by Richard D. Sharpe
  228. camaro_driver@hotmail.com
  229. *** Special thanks to GameDev.net! ***
  230. version 0.102511.04");
  231. Console.ReadKey();
  232. Console.Clear();
  233.  
  234. bool gameRunning = true;
  235. while (gameRunning)
  236. {
  237. Console.WriteLine(@"
  238.  
  239. ╔═════════════════ MAIN MENU ═════════════════╗
  240. ║ (C)reate a Character ╔═══ Character ═══╗ ║
  241. ║ (D)isplay Character ║ Name:{0} ║ ║
  242. ║ (E)quipment ║ Hit Points: {1} ║ ║
  243. ║ (S)leep ║ Level: ║ ║
  244. ║ (H)ealer ║ EXP: ║ ║
  245. ║ (A)rmory ║ Gold: ║ ║
  246. ║ (F)ight in the arena! ╚═════════════════╝ ║
  247. ╚═════════════════════════════════════════════╝", player.Name.PadLeft(10), player.HitPoints.ToString().PadLeft(3));
  248.  
  249. Console.WriteLine("\n");
  250.  
  251. Console.WriteLine(" Make your selection: \n");
  252. string menuChoice = Console.ReadLine();
  253. switch (menuChoice.ToUpper())
  254. {
  255. case "C":
  256. Console.Clear();
  257.  
  258. if (player.Name == "")
  259. {
  260. Console.WriteLine("\nCurrently, no character creation functions are available in this version.\n");
  261. Console.WriteLine("\nName your character: \n");
  262. player.Name = Console.ReadLine();
  263. player.Strength = 22;
  264. player.Dexterity = 10;
  265. player.Intelligence = 10;
  266. player.Health = 10;
  267. player.MaxHitPoints = 22;
  268. player.HitPoints = 22;
  269. player.WeaponSkill = 12;
  270. player.Speed = 6;
  271. Console.WriteLine("\nCharacter created!\n");
  272. }
  273. else
  274. {
  275. Console.WriteLine("You have already created a character named {0}.\n", player.Name);
  276. }
  277.  
  278. Console.WriteLine("\nPress any key to continue... ");
  279. Console.ReadKey();
  280.  
  281. Console.Clear();
  282. break; // End 'C' case.
  283.  
  284. case "D":
  285. Console.Clear();
  286. Console.WriteLine(@"
  287.  
  288. ╔═══════════════ CHARACTER SHEET ═══════════════╗
  289. ║ ║
  290. ║ Name: {0} ║
  291. ║ Species: ║
  292. ║ Class: ║
  293. ║ ║
  294. ║ ╔═══ Attributes ════╗╔══ Characteristics ═══╗ ║
  295. ║ ║ Strength: {1} ║║ Hit Points: {5} ║ ║
  296. ║ ║ Dexterity: {2} ║║ Willpower: ║ ║
  297. ║ ║ Intelligence: {3} ║║ Perception: ║ ║
  298. ║ ║ Health: {4} ║║ Fatigue Points: ║ ║
  299. ║ ╚═══════════════════╝╚══════════════════════╝ ║
  300. ║ ╔═══════ Armor ════════╦════ Equipment ═════╗ ║
  301. ║ ║ Helmet: ║ R. Hand: ║ ║
  302. ║ ║ Body: ║ L. Hand: ║ ║
  303. ║ ║ Arms: ╠════════════════════╣ ║
  304. ║ ║ Hands: ║ Gold: ║ ║
  305. ║ ║ Legs: ║ Ring: ║ ║
  306. ║ ║ Feet: ║ Necklace: ║ ║
  307. ║ ╚══════════════════════╩════════════════════╝ ║
  308. ╚═══════════════════════════════════════════════╝", player.Name.PadRight(10),
  309. player.Strength.ToString().PadLeft(3),
  310. player.Dexterity.ToString().PadLeft(3),
  311. player.Intelligence.ToString().PadLeft(3),
  312. player.Health.ToString().PadLeft(3),
  313. player.MaxHitPoints.ToString().PadLeft(3));
  314.  
  315. Console.WriteLine("\nPress any key to continue... ");
  316. Console.ReadKey();
  317.  
  318. Console.Clear();
  319. break;
  320.  
  321. case "E":
  322. Console.Clear();
  323. Console.WriteLine("This selection not yet implemented.");
  324. Console.WriteLine("\nPress any key...");
  325. Console.ReadKey();
  326. Console.Clear();
  327. break;
  328.  
  329. case "S":
  330. Console.Clear();
  331. Console.WriteLine("This selection not yet implemented.");
  332. Console.WriteLine("\nPress any key...");
  333. Console.ReadKey();
  334. Console.Clear();
  335. break;
  336.  
  337. case "H":
  338. Console.Clear();
  339. Console.WriteLine("This selection not yet implemented.");
  340. Console.WriteLine("\nPress any key...");
  341. Console.ReadKey();
  342. Console.Clear();
  343. break;
  344.  
  345. case "A":
  346. Console.Clear();
  347. Console.WriteLine("This selection not yet implemented.");
  348. Console.WriteLine("\nPress any key...");
  349. Console.ReadKey();
  350. Console.Clear();
  351. break;
  352.  
  353. case "F":
  354. Console.Clear();
  355. Console.WriteLine("\nChose your opponent: (G)oblin, (O)rc.\n");
  356. string opponentChoice = Console.ReadLine();
  357. switch (opponentChoice.ToUpper())
  358. {
  359. case "G":
  360. Console.Clear();
  361. Console.WriteLine("\nYou're fighting a goblin!\n");
  362. do
  363. {
  364. if (player.Speed >= goblin.Speed)
  365. {
  366. if (player.Alive == true)
  367. {
  368. player.Combat(goblin);
  369. }
  370.  
  371. if (goblin.Alive == true)
  372. {
  373. Console.WriteLine("\nThe goblin is attacking!\n");
  374. goblin.Swing(player);
  375. }
  376.  
  377. }
  378.  
  379. else
  380. {
  381. if (goblin.Alive == true)
  382. {
  383. Console.WriteLine("\nThe goblin is attacking!\n");
  384. goblin.Swing(player);
  385. }
  386.  
  387. if (player.Alive == true)
  388. {
  389. player.Combat(goblin);
  390. }
  391.  
  392. }
  393.  
  394. } while (player.Alive == true && goblin.Alive == true);
  395.  
  396. break; // Break from combat with the goblin.
  397.  
  398. case "O":
  399. Console.Clear();
  400. Console.WriteLine("\nYou're fighting an orc!\n");
  401. do
  402. {
  403. if (player.Speed >= orc.Speed)
  404. {
  405. if (player.Alive == true)
  406. {
  407. player.Combat(orc);
  408. }
  409.  
  410. if (orc.Alive == true)
  411. {
  412. Console.WriteLine("\nThe orc is attacking!\n");
  413. orc.Swing(player);
  414. }
  415.  
  416. }
  417.  
  418. else
  419. {
  420. if (orc.Alive == true)
  421. {
  422. Console.WriteLine("\nThe orc is attacking!\n");
  423. orc.Swing(player);
  424. }
  425.  
  426. if (player.Alive == true)
  427. {
  428. player.Combat(orc);
  429. }
  430.  
  431. }
  432.  
  433. } while (player.Alive == true && orc.Alive == true);
  434.  
  435. break; // Break from combat with the orc.
  436.  
  437. default:
  438. Console.Clear();
  439. Console.WriteLine("Not a valid choice.");
  440. break;
  441. } // End opponenet choice.
  442.  
  443.  
  444. break;
  445.  
  446. default:
  447. Console.Clear();
  448. Console.WriteLine("Not a valid selection.");
  449. Console.WriteLine("\nPress any key...");
  450. Console.ReadKey();
  451. Console.Clear();
  452. break;
  453.  
  454. } // End main menu switch.
  455.  
  456. } // End game running loop.
  457.  
  458. } // End Main.
  459.  
  460. } // End Program class.
  461.  
  462. } // End namespace.
Add Comment
Please, Sign In to add comment