Advertisement
Guest User

Finalcode

a guest
Apr 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include <vector>
  5. #include <iomanip>
  6. #include <thread>
  7. #include <chrono>
  8. #include <windows.h>
  9. #include <stdlib.h>
  10. #include <time.h>
  11.  
  12.  
  13.  
  14. using namespace std;
  15.  
  16. int lives = 3;
  17.  
  18. void SetColor(int value) {
  19. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), value);
  20. }
  21.  
  22. string MainMenu() {
  23. string quit;
  24. int i;
  25.  
  26. cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
  27. for (i = 0; i < 11; i++) {
  28. cout << "|" << setw(59) << "|" << endl;
  29. }
  30.  
  31. cout << "|" << setw(10) << " ";
  32. SetColor(2);
  33. cout << R"(|\/| _ _ __|_ _ _ |~) _ _|__|_| _ )";
  34. SetColor(15);
  35. cout << setw(11) << "|" << endl;
  36. cout << "|" << setw(10) << " ";
  37. SetColor(2);
  38. cout << R"(| |(_)| |_\ | (/_| |_)(_| | | |(/_)";
  39. SetColor(15);
  40. cout << setw(11) << "|" << endl;
  41. cout << "|" << setw(59) << "|" << endl;
  42. cout << "|" << setw(38) << "A Game Created By:" << setw(21) << "|" << endl;
  43. cout << "|" << setw(45) << "Donald Draper and Jensen Tucker" << setw(14) << "|" << endl;
  44.  
  45. for (i = 0; i < 8; i++) {
  46. cout << "|" << setw(59) << "|" << endl;
  47. }
  48.  
  49. cout << "|" << setw(5) << "Type 'Start' to begin, Type 'Quit' to exit." << setw(16) << "|" << endl;
  50.  
  51. cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl << endl;
  52.  
  53. cin >> quit;
  54.  
  55. return quit;
  56. }
  57.  
  58.  
  59. void ClearScreen()
  60. {
  61. cout << string(100, '\n');
  62. }
  63.  
  64. void draw1() {
  65.  
  66. SetColor(4);
  67. cout << endl;
  68. cout << R"( __ _ )" << endl;
  69. cout << R"( _/ \ _(\(o )" << endl;
  70. cout << R"( / \ / _ ^^^o )" << endl;
  71. cout << R"( / ! \/ ! '!!!v' )" << endl;
  72. cout << R"( ! ! \ _' ( \____ )" << endl;
  73. cout << R"( ! . \ _!\ \===^\) )" << endl;
  74. cout << R"( \ \_! / __! )" << endl;
  75. cout << R"( \! / \ )" << endl;
  76. cout << R"( (\_ _/ _\ ) )" << endl;
  77. cout << R"( \ ^^--^^ __-^ /(__ )" << endl;
  78. cout << R"( ^^----^^ "^--v' )" << endl;
  79. SetColor(15);
  80.  
  81. }
  82.  
  83. void draw2() {
  84.  
  85. SetColor(5);
  86. cout << R"( .'''''. ..||..'''''''...)" << endl;
  87. cout << R"( / ##### \ : || ''.)" << endl;
  88. cout << R"( | ## # ## | :.||...''''''.... '.)" << endl;
  89. cout << R"( | # # # | || '''')" << endl;
  90. cout << R"( | ####### | . ||)" << endl;
  91. cout << R"( \ ##### / /| < _>)" << endl;
  92. cout << R"( \ ### / / |/ < _>)" << endl;
  93. cout << R"( ..'' ''... / | < _>)" << endl;
  94. cout << R"( .' / | /||)" << endl;
  95. cout << R"( ' |/ ||)" << endl;
  96. cout << R"( | | '.. | ||)" << endl;
  97. cout << R"( | | | '...'' ||)" << endl;
  98. cout << R"( | | | ||)" << endl;
  99. cout << R"( \ | | ||)" << endl;
  100. cout << R"( |\| | ||)" << endl;
  101. cout << R"( \| | ||)" << endl;
  102. cout << R"( | | ||)" << endl;
  103. cout << R"( | | ||)" << endl;
  104. cout << R"( | | ||)" << endl;
  105. cout << R"( __| |__ ||)" << endl;
  106. cout << R"( / '.........' \ ||)" << endl;
  107. cout << R"( '''''' '''''' ##)" << endl;
  108. SetColor(15);
  109.  
  110.  
  111. }
  112.  
  113. int weapon;
  114. char role;
  115.  
  116.  
  117. int weaponChoice() {
  118.  
  119. int weaponChoice;
  120. int Longsword, Battleaxe, Cutlass, Daggers, Crossbow, Longbow, Polearm;
  121.  
  122. //Declaring Weapon Values weaponChoice
  123. Longsword = (rand() % 18) + 2; //1
  124. Battleaxe = (rand() % 12) + 4; //2
  125. Cutlass = (rand() % 8) + 6; //3
  126. Daggers = (rand() % 10) + 5; //4
  127. Crossbow = (rand() % 21); //5
  128. Longbow = (rand() % 10) + 5; //6
  129. Polearm = (rand() % 4) + 8; //7
  130.  
  131. cout << "Choose your weapon" << endl << endl;
  132. cout << "Longsword, 2-20 Damage, +10 Damage with Warrior Class, press 1" << endl;
  133. cout << "Battleaxe, 4-16 Damage, + 4 Damage with Warrior Class, press 2" << endl;
  134. cout << "Cutlass, 6-14 Damage, + 5 Damage with Rogue Class, press 3" << endl;
  135. cout << "Daggers, 5-15 Damage, +5 Damage with Rogue Class, press 4" << endl;
  136. cout << "Crossbow, 0-20 Damage, +7 Damage if used with Hunter Class, press 5" << endl;
  137. cout << "Longbow, 5-15 Damage, +5 Damage if used with Hunter Class, press 6" << endl;
  138. cout << "Polearm, 8-12 Damage, non class specific, press 7" << endl;
  139. cout << endl;
  140. cin >> weaponChoice;
  141.  
  142. if (weaponChoice == 1) {
  143. cout << "You chose the Longsword" << endl;
  144. }
  145. else if (weaponChoice == 2) {
  146. cout << "You chose the Battleaxe" << endl;
  147. }
  148. else if (weaponChoice == 3) {
  149. cout << "You chose the Cutlass" << endl;
  150. }
  151. else if (weaponChoice == 4) {
  152. cout << "You chose the Daggers " << endl;
  153. }
  154. else if (weaponChoice == 5) {
  155. cout << "You chose the Crossbow" << endl;
  156. }
  157. else if (weaponChoice == 6) {
  158. cout << "You chose the Longbow" << endl;
  159. }
  160. else if (weaponChoice == 7) {
  161. cout << "You chose the Polearm" << endl;
  162. }
  163. else {
  164. cout << "Invalid Command, please choose a Weapon";
  165.  
  166. }
  167.  
  168. return weaponChoice;
  169.  
  170. }
  171.  
  172. char roleChoice() {
  173. char roleChoice;
  174.  
  175. // string Warrior, Rogue, Hunter;
  176. // Warrior = 1, Rogue = 2, Hunter = 3;
  177.  
  178.  
  179.  
  180. cout << "Please pick a Role!" << endl << endl;
  181. // classChoice
  182. cout << "For Warrior, Press w" << endl; // 1
  183. cout << "For Rogue, Press r" << endl; // 2
  184. cout << "For Hunter, Press h" << endl; // 3
  185. cout << endl;
  186. cin >> roleChoice;
  187. cout << endl;
  188.  
  189. if ((roleChoice == 'w') || (roleChoice == 'W')) {
  190. cout << "You chose to be a Warrior" << endl;
  191. }
  192. else if ((roleChoice == 'r') || (roleChoice == 'R')) {
  193. cout << "You chose to be a Rogue" << endl;
  194.  
  195. }
  196. else if ((roleChoice == 'h') || (roleChoice == 'H')) {
  197. cout << "You chose to be a Hunter" << endl;
  198.  
  199. }
  200. else {
  201. cout << "Invalid Command, please choose a Class";
  202.  
  203. }
  204. return roleChoice;
  205. }
  206.  
  207.  
  208. int playerDamage() {
  209. int playerDamage;
  210.  
  211. if ((role == 'w') || (role == 'W') && (weapon == 1)) {
  212. playerDamage = ((rand() % 18) + 2) + 10;
  213. }
  214. else if ((role == 'w') || (role == 'W') && (weapon == 2)) {
  215. playerDamage = ((rand() % 12) + 4) + 4;
  216. }
  217. else if ((role == 'r') || (role == 'R') && (weapon == 3)) {
  218. playerDamage = ((rand() % 12) + 4) + 4;
  219. }
  220. else if ((role == 'r') || (role == 'R') && (weapon == 4)) {
  221. playerDamage = ((rand() % 12) + 4) + 4;
  222. }
  223. else if ((role == 'h') || (role == 'H') && (weapon == 5)) {
  224. playerDamage = ((rand() % 12) + 4) + 4;
  225. }
  226. else if ((role == 'h') || (role == 'H') && (weapon == 6)) {
  227. playerDamage = ((rand() % 12) + 4) + 4;
  228. }
  229. else if (weapon == 1) {
  230. playerDamage = (rand() % 18) + 2;
  231. }
  232. else if (weapon == 2) {
  233. playerDamage = (rand() % 12) + 4;
  234. }
  235. else if (weapon == 3) {
  236. playerDamage = (rand() % 8) + 6;
  237. }
  238. else if (weapon == 4) {
  239. playerDamage = (rand() % 10) + 5;
  240. }
  241. else if (weapon == 5) {
  242. playerDamage = (rand() % 21);
  243. }
  244. else if (weapon == 6) {
  245. playerDamage = (rand() % 10) + 5;
  246. }
  247. else if (weapon == 7) {
  248. playerDamage = (rand() % 4) + 8;
  249. }
  250.  
  251. return playerDamage;
  252.  
  253. }
  254.  
  255. void fight() {
  256.  
  257. bool monster = true;
  258. int monsterHealth = 10, damage, enemyDamage;
  259. string action;
  260.  
  261. ClearScreen();
  262.  
  263. while (lives > 0 && monster == true) {
  264. draw1();
  265. cout << "A Dragon Has Appeared!" << endl;
  266. cout << "It's health is at " << monsterHealth << "." << endl;
  267. cout << "You Have " << lives << " Lives Left!" << endl;
  268. cin >> action;
  269. cout << endl;
  270. if (action == "fight" || action == "Fight") {
  271. srand(time(0));
  272.  
  273. damage = playerDamage();
  274. cout << "You have done " << damage << " damage to the dragon!" << endl << endl;
  275. monsterHealth = monsterHealth - damage;
  276.  
  277. if (monsterHealth < 1) {
  278. monster = false;
  279. }
  280.  
  281. else {
  282. this_thread::sleep_for(chrono::seconds(1));
  283.  
  284. cout << "The Dragon Swings!" << endl;
  285. enemyDamage = (rand() % 11);
  286.  
  287. if (enemyDamage == 10) {
  288. cout << "The Dragon Hits You! You lose a health point!" << endl;
  289. lives--;
  290. }
  291.  
  292. else {
  293. cout << "The Dragon Misses!" << endl;
  294. }
  295.  
  296. this_thread::sleep_for(chrono::seconds(2));
  297. ClearScreen();
  298.  
  299. }
  300. }
  301.  
  302. else if (action == "quit" || action == "Quit") {
  303. lives = -1;
  304. }
  305.  
  306. else {
  307. cout << "You have typed something that is not a command, please try again" << endl;
  308. this_thread::sleep_for(chrono::seconds(2));
  309. ClearScreen();
  310. }
  311. }
  312.  
  313. if (lives == 0) {
  314. this_thread::sleep_for(chrono::seconds(1));
  315. cout << endl << "The dragon beat you. You Lose." << endl;
  316. this_thread::sleep_for(chrono::seconds(2));
  317. ClearScreen();
  318. }
  319.  
  320. else if (monster == false) {
  321. this_thread::sleep_for(chrono::seconds(1));
  322. cout << endl << "You beat the dragon! You Win!" << endl;
  323. this_thread::sleep_for(chrono::seconds(2));
  324. ClearScreen();
  325. }
  326.  
  327. else if (lives == -1) {
  328. this_thread::sleep_for(chrono::seconds(1));
  329. ClearScreen();
  330. }
  331.  
  332. }
  333.  
  334. void rules() {
  335. string start;
  336. int i;
  337.  
  338. ClearScreen();
  339.  
  340. cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
  341. for (i = 0; i < 11; i++) {
  342. cout << "|" << setw(59) << "|" << endl;
  343. }
  344.  
  345.  
  346. cout << "|" << setw(35) << "How to Play:" << setw(24) << "|" << endl;
  347. cout << "|" << setw(45) << "Choose your role and your weapon" << setw(14) << "|" << endl;
  348. cout << "|" << setw(39) << "Type 'Fight' to attack" << setw(20) << "|" << endl;
  349. cout << "|" << setw(45) << "Type 'Quit' to exit to the menu" << setw(14) << "|" << endl;
  350.  
  351. for (i = 0; i < 10; i++) {
  352. cout << "|" << setw(59) << "|" << endl;
  353. }
  354.  
  355. cout << "|" << setw(5) << "Type 'Start' to continue, Type 'Quit' to return to menu." << setw(3) << "|" << endl;
  356.  
  357. cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl << endl;
  358.  
  359. cin >> start;
  360.  
  361. if (start == "Start" || start == "start") {
  362. role = roleChoice();
  363. weapon = weaponChoice();
  364. fight();
  365. }
  366.  
  367. else if (start == "Quit" || start == "quit") {
  368. this_thread::sleep_for(chrono::seconds(1));
  369. ClearScreen();
  370. }
  371.  
  372. else {
  373. this_thread::sleep_for(chrono::seconds(1));
  374. cout << "You have typed something that is not start or quit, please try again." << endl;
  375. this_thread::sleep_for(chrono::seconds(1));
  376. ClearScreen();
  377. }
  378. }
  379.  
  380. int main() {
  381. string game = MainMenu();
  382.  
  383.  
  384. while (game != "Quit" && game != "quit") {
  385. if (game == "Start" || game == "start") {
  386. cout << "You Have Started The Game!" << endl;
  387. lives = 3;
  388. rules();
  389. }
  390. else {
  391. cout << "You have typed something that is not 'Quit' or 'Start', please try again" << endl << endl;
  392. this_thread::sleep_for(chrono::seconds(3));
  393. }
  394.  
  395. game = MainMenu();
  396. }
  397.  
  398. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement