Advertisement
Guest User

what i got

a guest
Feb 8th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.81 KB | None | 0 0
  1. /*
  2. * File: main.cpp
  3. * Author: Logan Laframboise and Sean Bennell
  4. *
  5. * Created on February 1, 2016, 5:37 PM
  6. */
  7.  
  8. #include <cstdlib>
  9. #include <ctime>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string>
  13. #include <iostream>
  14. #include <ctime>
  15.  
  16. using namespace std;
  17.  
  18. int random(int x){
  19. int num;
  20. srand(time(NULL));
  21. num = (rand() % x) + 1;
  22. return num;
  23. }//simple random number generator
  24.  
  25. int randomRange(int x){
  26. int num;
  27. int y = 2*x;
  28. num = (rand() % y) + x;
  29. return num;
  30. }//returns a random number between two numbers.
  31.  
  32. int bossMoves(int boss){
  33. switch(boss){
  34. case 1://Bistrugg
  35. int choice;
  36. choice = rand() % 100;
  37. if(choice <= 20){
  38. return(1);
  39. }
  40. else if(choice <= 40 && choice >20){
  41. return(2);
  42. }
  43. else if(choice <= 100 && choice > 40){
  44. return(3);
  45. }
  46. case 2://Farnsten
  47. if(choice <=20){
  48. return(4);
  49. }
  50. else if(choice <= 60 && choice > 20){
  51. return(5);
  52. }
  53. else if(choice <= 100 && choice > 60){
  54. return(6);
  55. }
  56. case 3://Lagrath
  57. if(choice <= 35){
  58. return(7);
  59. }
  60. else if(choice <= 70 && choice > 35){
  61. return(8);
  62. }
  63. else if(choice <= 100 && choice > 70){
  64. return(9);
  65. }
  66. }
  67. }//%chance to cast different moves
  68.  
  69. void userInterface(int eHealth, int eEnergy, int uHealth, int uEnergy){
  70. cout << "You have: " << uHealth << " health and " << uEnergy << " energy.\n";
  71. cout << "Your foe has: " << eHealth << " health and " << eEnergy << " energy.\n";
  72. }//print user interface.
  73.  
  74. bool sleep(int x){
  75. int wakeChance;
  76. bool sleep = true;
  77. wakeChance = random(100);
  78. if(x == 1){
  79. if(wakeChance <= 20){
  80. sleep = false;
  81. }
  82. else{
  83. sleep = true;
  84. }
  85. }
  86. else if(x == 2){
  87. if(wakeChance <= 30){
  88. sleep = false;
  89. }
  90. else{
  91. sleep = true;
  92. }
  93. }
  94. else if(x == 3){
  95. if(wakeChance <= 50){
  96. sleep = false;
  97. }
  98. else{
  99. sleep = true;
  100. }
  101. }
  102. else{
  103. sleep = false;
  104. }
  105. return(sleep);
  106. }//enemy sleep//wake
  107.  
  108. bool timer(int x){
  109. bool empower;
  110. if(x > 0 && x <= 5){
  111. empower = true;
  112. }
  113. else{
  114. empower = false;
  115. }
  116. return(empower);
  117. }//attack steroid// change to for statement later
  118.  
  119. bool hit(int x){
  120. int chance = random(100);
  121. switch(x){
  122. bool rate;
  123. case 1://punch
  124. if(chance <= 85){
  125. rate = true;
  126. return rate;
  127. }
  128. case 2:// kick
  129. if(chance <= 60){
  130. rate = true;
  131. return rate;
  132. }
  133. case 3://punt
  134. if(chance <= 70){
  135. rate = true;
  136. return rate;
  137. }
  138. case 4:// throw
  139. if(chance <= 50){
  140. rate = true;
  141. return rate;
  142. }
  143. case 5:// smash
  144. if(chance <= 95){
  145. rate = true;
  146. return rate;
  147. }
  148. case 6://shiv
  149. if(chance <= 80){
  150. rate = true;
  151. return rate;
  152. }
  153. case 7://punches
  154. if(chance <= 60){
  155. rate = true;
  156. return rate;
  157. }
  158. case 8://slap
  159. if(chance <= 75){
  160. rate = true;
  161. return rate;
  162. }
  163. case 9://roll
  164. if(chance <= 60){
  165. rate = true;
  166. return rate;
  167. }
  168. case 10:
  169. if(chance <= 50){
  170. rate = true;
  171. return rate;
  172. }
  173. }
  174. }// percent to hit all moves that do damage.
  175.  
  176. int bossHp(int x){
  177. int hp;
  178. switch(x){
  179. case 1:
  180. hp = 100;
  181. return(hp);
  182. case 2:
  183. hp = 50;
  184. return(hp);
  185. case 3:
  186. hp = 250;
  187. return(hp);
  188. }
  189.  
  190. }//boss hp
  191.  
  192. int bossEn(int x){
  193. int en;
  194. switch(x){
  195. case 1:
  196. en = 10;
  197. return(en);
  198. case 2:
  199. en = 20;
  200. return(en);
  201. case 3:
  202. en = 5;
  203. return(en);
  204. }
  205.  
  206. }//boss en
  207.  
  208. int damage(int x, int hp, bool d){
  209. int punch = randomRange(5);
  210. int kick = randomRange(10);
  211. int punt = randomRange(5);
  212. int throe = randomRange(10);// wow throw is an operation. never lucky rubber ducky.
  213. int smash = randomRange(20);
  214. int shiv = randomRange(10);
  215. int punches = randomRange(3);
  216. int slap = randomRange(5);
  217. int roll = randomRange(10);
  218. int tantrum = randomRange(20);
  219. int defense;
  220. if(d){
  221. defense = 3;
  222. }
  223. else{
  224. defense = 0;
  225. }
  226. switch(x){
  227. case 1:
  228. if(punch >= 10){
  229. cout << "Critical hit!\n";
  230. }
  231. hp -= punch;
  232. return hp;
  233. case 2:
  234. if(kick >= 20){
  235. cout << "Critical hit!\n";
  236. }
  237. hp -= kick;
  238. return hp;
  239. case 3:
  240. if(punt >= 10){
  241. cout << "Critical hit!\n";
  242. }
  243. hp += defense;
  244. hp -= punt;
  245. return hp;
  246. case 4:
  247. if(throe >= 20){
  248. cout << "Critical hit!\n";
  249. }
  250. hp += defense;
  251. hp -= throe;
  252. return hp;
  253. case 5:
  254. if(smash >= 40){
  255. cout << "Critical hit!\n";
  256. }
  257. hp += defense;
  258. hp -= smash;
  259. return hp;
  260. case 6:
  261. if(shiv >= 20){
  262. cout << "Critical hit!\n";
  263. }
  264. hp += defense;
  265. hp -= shiv;
  266. return hp;
  267. case 7:
  268. if(punches >= 6){
  269. cout << "Critical hit!\n";
  270. }
  271. hp += defense;
  272. hp -= punches;
  273. return hp;
  274. case 8:
  275. if(slap >= 10){
  276. cout << "Critical hit!\n";
  277. }
  278. hp += defense;
  279. hp -= slap;
  280. return hp;
  281. case 9:
  282. if(roll >= 20){
  283. cout << "Critical hit!\n";
  284. }
  285. hp += defense;
  286. hp -= roll;
  287. return hp;
  288. case 10:
  289. if(tantrum >= 40){
  290. cout << "Critical hit!\n";
  291. }
  292. hp += defense;
  293. hp -= tantrum;
  294. return hp;
  295. }
  296. }// calculates damage on both characters
  297.  
  298. int dialogue(int x,int y,int z, string name){
  299. //int x is which boss he talking to.
  300. //int y is which instance of dialogue it is.
  301. //int z is talk 1 || inspect 2
  302. switch(x){
  303. case 1://bistrugg
  304. switch(y){
  305. case 1:
  306. switch(z){
  307. case 1://talk 1
  308. cout << name << ": Calm down, I don't want to fight!\n";
  309. cout << "Bistrugg: Less talk, more SMASH!\n";
  310. return(1);
  311. case 2://talk 2
  312. cout << name << ": Wait-!\n";
  313. cout << "Bistrugg: I WILL SMASH YOU\n!";
  314. return(2);
  315. default://talk 3
  316. cout << name << ": Stop!\n";
  317. cout << "Bistrugg: SMASH ONLY\n";
  318. return(3);
  319. }
  320. case 2:
  321. switch(z){
  322. case 1:// inspect
  323. cout << "The monstrosity before you seems to be more muscle than man.\n";
  324. cout << "He lets out a roar as he charges forward, lifting his arms up to attack.\n";
  325. cout << "Given his size, his movements seem slow and predictable!\n";
  326. return(4);
  327. default://inspect 2
  328. cout << "You have learned all you can.\n";
  329. return(5);
  330. }
  331. }
  332. case 2://Farnsten
  333. switch(y){
  334. case 1:
  335. switch(z){
  336. case 1:// talk 1
  337. cout << name << ": Hey, wait!\n";
  338. cout << "It seems that Farnsten isn't interested in talking.\n";
  339. return(6);
  340. default:// talk 2
  341. cout << name << ": Stop-\n";
  342. cout << "Farnsten continues to attack\n";
  343. return(7);
  344. }
  345. case 2:
  346. switch(z){
  347. case 1://inspect 1
  348. cout << "The man appears to be nothing more than a blur as he dashes from place to place.\n";
  349. cout << "He is very fast but not very strong!\n";
  350. return(8);
  351. case 2://inspect 2
  352. cout << "As you watch him you begin to notice a pattern.\n";
  353. return(9);
  354. case 3://inspect 3
  355. cout << "The pattern becomes more noticeable as you watch.\n";
  356. return(10);
  357. default://inspect 4
  358. cout << "If you kick him now; you can disrupt his movements\n";
  359. return(11);
  360. }
  361.  
  362. }
  363. case 3:// Lagrath
  364. switch(y){
  365. case 1:
  366. switch(z){
  367. case 1://talk 1
  368. cout << name << ": Wait! I just want to talk.\n";
  369. cout << "Lagrath: I shall talk but I shall not stop fighting.\n";
  370. return(12);
  371. case 2://talk 2
  372. cout << name << ": Who are you? Why are you attacking me?!";
  373. cout << "Lagrath: I am Lagrath! This is my mountain! You are trespassing!\n";
  374. return(13);
  375. case 3://talk 3
  376. cout << name << ": I'm just passing through. I didn't know this was your mountain. May I pass?\n";
  377. cout < "Lagrath: You are? Hum... perhaps. Do you swear not to harm my lands?\n";
  378. return(14);
  379. case 4://talk 4
  380. cout << name << ": I swear.\n";
  381. cout << "Lagrath: Very well. I shall let you go in peace. Farewell stranger.\n";
  382. return(15);
  383. }
  384. case 2:
  385. switch(z){
  386. case 1://inspect 1
  387. cout << "The man towers before you, looming like a mountain.\n";
  388. cout << "His height is matched only by his enormous girth.\n";
  389. cout << "It doesn't look like hitting him will have much of an affect.\n";
  390. return(16);
  391. default://inspect 2
  392. cout << "Fighting him doesn't seem realistic.\n";
  393. return(17);
  394. }
  395. }
  396. }
  397. }// talk and inspect dialogue
  398.  
  399. int actions(){
  400. int action;
  401. cout << "What would you like to do:\n";
  402. cout << "1. Interact \t" << "2. Items \t" << "3. Investigate \t" << "4. Flee \n";
  403. cin >> action;
  404. switch(action){
  405. int choice;
  406. case 1://confront
  407. cout << "What would you like to do:\n";
  408. cout << "1. Punch \t" << "2. Kick \t" << "3.Dodge \t" << "4. Talk \n";
  409. cin >> choice;
  410. switch(choice){
  411. case 1:
  412. cout << "You try and throw a punch.\n";
  413. return(1);
  414. case 2:
  415. cout << "You try and kick him.\n";
  416. return(2);
  417. case 3:
  418. cout << "You decide to dodge.\n";
  419. return(3);
  420. case 4:
  421. return(4);
  422. }
  423. case 2://items
  424. cout << "What would you like to use:\n";
  425. cout << "1. Medical Kit \t" << "2. Use PCP \t" << "3. Wear Kevlar \t" << "4. Use Sleep Powder \n";
  426. cin >> choice;
  427. switch(choice){
  428. case 1:
  429. cout << "You chug back a health potion.\n";
  430. return(5);
  431. case 2:
  432. cout << "You shoot up some PCP to give you an edge in combat.\n";
  433. return(6);
  434. case 3:
  435. cout << "You put on a new kevlar vest to protect yourself.\n";
  436. return(7);
  437. case 4:
  438. cout << "You throw some sleep powder in his face. He falls asleep instantly.\n";
  439. return(8);
  440. }
  441. case 3://inspect
  442. return(9);
  443. case 4://run
  444. cout << "You try and run away but you trip over your cowardice and die instantly.\n";
  445. return(10);
  446. }
  447. }// all the actions
  448.  
  449. int end(int ehp,int uhp, bool dip){
  450. if(ehp == 0){
  451. return(1);
  452. }
  453. if(uhp == 0){
  454. return(2);
  455. }
  456. if(dip == true){
  457. return(3);
  458. }
  459. }// checks for end of game scenario
  460.  
  461. bool dodge(int x){
  462. bool dodged;
  463. if(x == 1){
  464. dodged = true;
  465. }
  466. else{
  467. dodged = false;
  468. }
  469. return dodged;
  470. }
  471.  
  472. bool flipBool(bool x){
  473. if(x){
  474. x = false;
  475. return x;
  476. }
  477. }
  478.  
  479. int main(int argc, char** argv) {
  480. bool running = true;
  481. while (running){
  482. bool playing = true;
  483. cout << "What is your name? \n";
  484. string name;
  485. cin >> name;
  486. int turn = 0;
  487.  
  488. //defines boss stats.
  489. int boss;
  490. int eMove;
  491. int eHealth;
  492. int eEnergy;
  493. boss = random(3);
  494. eHealth = bossHp(boss);
  495. eEnergy = bossEn(boss);
  496. bool eAttackUp = false;
  497. //defines player stats.
  498. int uHealth = 50;
  499. int uEnergy = 5;
  500. bool userAttackUp = false;
  501. bool userDefenseUp = false;
  502. //status effects
  503. bool asleep = false;
  504. bool attack = false;
  505. bool defense = false;
  506. //core game variables
  507. int action;
  508. int sTimer;
  509. int aTimer;
  510. int dTimer;
  511. int talk = 1, inspect = 2;
  512. int tain;// talk or inspect
  513. bool diplomacy = false;
  514. int finish;
  515. bool uDodge;
  516. int dia;
  517. bool uAcc = false;
  518. bool conn = false;
  519. while(playing){
  520. tain = 0;
  521. attack = timer(aTimer);
  522. defense = timer(dTimer);
  523. asleep = sleep(sTimer);
  524. //writes how much hp and energy user and boss has each turn.
  525. userInterface(eHealth,eEnergy,uHealth,uEnergy);
  526. action = actions();// asks for user input.
  527. switch(action){
  528. case 1://punch
  529. conn = hit(1);
  530. if(conn){
  531. if(uEnergy > 0){
  532. eHealth = damage(1,eHealth,defense);
  533. uEnergy --;
  534. }
  535. else{
  536. cout << "You do not have enough energy for that!\n";
  537. }
  538. }
  539. else{
  540. cout << "You missed!";
  541. }
  542.  
  543. break;
  544. case 2://kick
  545. if(uEnergy > 0){
  546. eHealth = damage(2,eHealth,defense);
  547. uEnergy --;
  548. }
  549. else{
  550. cout << "You do not have enough energy for that!\n";
  551. }
  552. break;
  553. case 3://dodge
  554. uDodge = true;
  555. break;
  556. case 4://talk
  557. tain = 1;
  558. dia = dialogue(boss, talk, tain, name);
  559. talk ++;
  560. break;
  561. case 5://hp
  562. if(uHealth > 0 && uHealth < 30){
  563. uHealth += 20;
  564. }
  565. else if(uHealth > 30 && uHealth < 50){
  566. uHealth = 50;
  567. }
  568. else{
  569. cout << "You are already at full Health.\n";
  570. }
  571. break;
  572. case 6://pcp
  573. attack = true;
  574. aTimer = 1;
  575. break;
  576. case 7://kev
  577. defense = true;
  578. dTimer = 1;
  579. break;
  580. case 8://sleep
  581. asleep = true;
  582. sTimer = 1;
  583. break;
  584. case 9://inspect
  585. tain = 2;
  586. dia = dialogue(boss, inspect, tain, name);
  587. inspect ++;
  588. break;
  589. case 10://flee
  590. uHealth = 0;
  591. break;
  592. }
  593. eMove = bossMoves(boss);
  594. switch(boss){
  595. case 1://bistrugg
  596. switch(eMove){
  597. case 1:
  598. if(uDodge){
  599. cout << "Bistrugg missed.\n";
  600. break;
  601. }
  602. else if(eAttackUp == true){
  603. uHealth = damage(3,uHealth,defense);
  604. uHealth = damage(3,uHealth,defense);
  605. eEnergy --;
  606. }
  607. else{
  608. uHealth = damage(3,uHealth,defense);
  609. eEnergy --;
  610. }
  611. break;
  612. case 2:
  613. if(uDodge){
  614. cout << "Bistrugg missed.\n";
  615. break;
  616. }
  617. else if(eAttackUp == true){
  618. uHealth = damage(4,uHealth,defense);
  619. uHealth = damage(4,uHealth,defense);
  620. eEnergy --;
  621. }
  622. else {
  623. uHealth = damage(4,uHealth,defense);
  624. eEnergy --;
  625. }
  626. break;
  627. case 3:
  628. if(uDodge){
  629. cout << "Bistrugg missed.\n";
  630. break;
  631. }
  632. else if(eAttackUp == true){
  633. uHealth = damage(4,uHealth,defense);
  634. uHealth = damage(4,uHealth,defense);
  635. eEnergy --;
  636. }
  637. else{
  638. uHealth = damage(4,uHealth,defense);
  639. eEnergy --;
  640. eAttackUp = true;
  641. }
  642. break;
  643. }
  644. case 2://Farnsten
  645. switch(eMove){
  646. if(turn == 1){
  647. uAcc = true;
  648. break;
  649. }
  650. case 1:
  651. if(uDodge){
  652. cout << "Farnsten missed.\n";
  653. break;
  654. }
  655. else{
  656. uHealth = damage(6,uHealth,defense);
  657. eEnergy --;
  658. break;
  659. }
  660. case 2:
  661. if(uDodge){
  662. cout << "Farnsten missed.\n";
  663. break;
  664. }
  665. else{
  666. uHealth = damage();
  667. }
  668. }
  669. }
  670. aTimer++;
  671. dTimer++;
  672. sTimer++;
  673. if(boss == 1 && eEnergy == 0){
  674. diplomacy = true;
  675. }//boss pacifist 1
  676. if(boss == 2 && dia == 11 && action == 2){
  677. diplomacy = true;
  678. }//boss pacifist 2
  679. if(boss == 3 && dia == 15){
  680. diplomacy = true;
  681. }//boss pacifist 3
  682. finish = end(eHealth,uHealth,diplomacy);
  683. turn += 1;//increments turn
  684. switch(finish){//
  685. case 1:
  686. cout << "you have defeated your opponent!\n";
  687. playing = false;
  688. break;
  689. case 2:
  690. cout << "You have been defeated!\n";
  691. playing = false;
  692. break;
  693. case 3:
  694. cout << "Wow, you talked your way out like a coward. Good job... I guess.\n";
  695. playing = false;
  696. break;
  697. }
  698. }
  699. cout << endl << "Would you like to play again?\n";
  700. string close;
  701. cin >> close;
  702. if(close == "no"){
  703. running = false;
  704. }
  705. }
  706. }// if u run it rn it will have errors, in process of adding something i forgot so theres a half finished statement for farnsten punches rn.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement