Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.83 KB | None | 0 0
  1. /* Nolen Johnson
  2. * OceanVoyage
  3. * Keeps track of your journey, supplies, and crew members status when traveling to the destination on the old pirates map.
  4. */
  5.  
  6. //Included Libraries
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <time.h>
  10. #include <string.h>
  11.  
  12. //Constants for Arrays
  13. #define STRLENGTH 30
  14. #define NUMCREW 5
  15. #define NUMSUPPLIES 4
  16.  
  17. //Constants for Distances (measured in miles)
  18. #define CANARY 1261
  19. #define GRENADA 3110
  20. #define FINAL 500
  21. #define DISTANCE 4871
  22.  
  23. //Function Signatures - do not change these
  24. void setup(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int supplies[NUMSUPPLIES], int *captaintype, int *funds, int *distanceperday);
  25. int countcrew(int crewstatus[NUMCREW]);
  26. void printstatus(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW]);
  27. void getsupplies(char supplytypes[NUMSUPPLIES][STRLENGTH], int supplies[NUMSUPPLIES], int *funds);
  28. void dailyreport(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int supplies[NUMSUPPLIES], int funds, int traveled);
  29. void rest(int supplies[NUMSUPPLIES], char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int *days);
  30. int fish();
  31. int max(int a, int b);
  32. int min(int a, int b);
  33. void event(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int *days, int supplies[NUMSUPPLIES]);
  34.  
  35. //Main function - This is the final version of main. Any changes you make while
  36. //creating the functions should be removed prior to submission.
  37. int main(void) {
  38. //crewnames and supplytypes are arrays of strings to store the names of the crew members
  39. //and the types of supplies that can be purchased and taken on the voyage
  40. char crewnames[NUMCREW][STRLENGTH];
  41. char supplytypes[NUMSUPPLIES][STRLENGTH] = {"Food", "Clothes", "Ship Parts", "Shovels"};
  42. //stop indicates whether or not the user would like to stop at a port
  43. //crewstatus indicates the status of each crew member, corresponding to the order of names
  44. //supplies has a total for each type of supply, corresponding to the order of supplies
  45. char stop;
  46. int crewstatus[NUMCREW], supplies[NUMSUPPLIES];
  47. //the distanceperday and funds depends on the captaintype the user selects
  48. //day is the current day, traveled is the total miles traveled, i is a loop counter
  49. //and action stores the intended action of the user for the day
  50. int distanceperday, captaintype, funds, traveled=0, day=1;
  51. int i, action;
  52.  
  53. //seed the pseudorandom number generator
  54. srand(time(0));
  55.  
  56. //initialize each variable with information from the user
  57. setup(crewnames, crewstatus, supplies, &captaintype, &funds, &distanceperday);
  58.  
  59. //begin the game by purchasing initial supplies
  60. printf("\nBefore leaving Port Marin, you should purchase some supplies.\n");
  61. getsupplies(supplytypes, supplies, &funds);
  62.  
  63. //continue the voyage until the ship reaches the intended destination
  64. //if all crew members perish, the journey cannot continui
  65. while (traveled < DISTANCE && countcrew(crewstatus) > 0) {
  66. printf("\n\n--It is day #%d.--\n", day);
  67.  
  68. //check to see if the ship has reached the next port
  69. if(traveled >= (GRENADA+CANARY) && traveled < (GRENADA + CANARY + distanceperday) ) {
  70. printf("You have arrived at Grenada, at the edge of the Carribbean Sea.\n");
  71. printf("Would you like to make port? (Y/N)\n");
  72. scanf(" %c", &stop);
  73.  
  74. if (stop == 'Y' || stop == 'y')
  75. getsupplies(supplytypes, supplies, &funds);
  76.  
  77. traveled = (GRENADA+CANARY) + distanceperday;
  78. }
  79. else if (traveled >= CANARY && traveled < (CANARY + distanceperday) ) {
  80. printf("You have arrived at the Canary Islands.\n");
  81. printf("Would you like to make port? (Y/N)\n");
  82. scanf(" %c", &stop);
  83.  
  84. if (stop == 'Y' || stop == 'y')
  85. getsupplies(supplytypes, supplies, &funds);
  86.  
  87. traveled = CANARY + distanceperday;
  88. }
  89. //if between destinations: print the daily report and process the user's action for the day
  90. else {
  91. dailyreport(crewnames, crewstatus, supplies, funds, traveled);
  92.  
  93. printf("\nWhat would you like to do?\n");
  94. printf("1 - Fish\n");
  95. printf("2 - Rest\n");
  96. printf("3 - Continue\n");
  97. scanf("%d", &action);
  98.  
  99. if(action == 1) {
  100. supplies[0] += fish();
  101. }
  102. else if(action == 2) {
  103. day--;
  104. rest(supplies, crewnames, crewstatus, &day);
  105. }
  106. else {
  107. traveled += distanceperday;
  108. supplies[0] = max(supplies[0] - countcrew(crewstatus) * 2, 0);
  109. event(crewnames, crewstatus, &day, supplies);
  110. }
  111. }
  112. day++;
  113. }
  114.  
  115. printf("\n\n");
  116.  
  117. //The final printout changes based on which condition broke the while loop
  118. if (countcrew(crewstatus) == 0) {
  119. printf("Your crew has perished in the search for treasure. :(\n");
  120.  
  121. printstatus(crewnames, crewstatus);
  122. }
  123. else {
  124. printf("Your crew has made it safely to the island.\n");
  125.  
  126. printstatus(crewnames, crewstatus);
  127.  
  128. if(supplies[3] >= countcrew(crewstatus))
  129. printf("You have enough shovels to dig up the treasure!\n");
  130. else
  131. printf("Unfortuantely, you will not be able to dig up the treasure.\n");
  132. }
  133.  
  134. return 0;
  135. }
  136.  
  137. //Pre-conditions: none
  138. //Post-conditions: each input parameter should be assigned an initial value
  139.  
  140. //What to do in this function: Provide the starting message for the user and ask how they plan to travel.
  141. // Based on their response initialize captaintype, funds, and distanceperday
  142. // -captaintype 1 should get 1000 funds and 80 distanceperday
  143. // -captaintype 2 should get 900 funds and 90 distanceperday
  144. // -captaintype 3 should get 800 funds and 100 distanceperday
  145. /** DONE **/
  146.  
  147. // Ask the user for their name. Place this in the first row of crewnames, representing the captain. Treat
  148. // crewnames as a 1-Dimensional array of strings. As an example: printf("%s", crewnames[0]); would print the
  149. // first string or the captains name to the screen. Then ask for the names of the other 4 crew members in a loop.
  150.  
  151. // Set the crew status to 2 for each crew member, representing healthy
  152. // Set the initial amount of supplies to be 0 for each supply
  153. /** DONE **/
  154. /** Maybe fix invalid input to be able to deal with characters? **/
  155.  
  156. void setup(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int supplies[NUMSUPPLIES], int *captaintype, int *funds, int *distanceperday) {
  157.  
  158. // Query the user about what type of captain they are
  159. printf("You may now take your ship and crew from Port Marin, Spain to the hidden island in the Caribbean on the old pirate's map.\n\n");
  160.  
  161. printf("How will you travel?\n");
  162. printf("1 - As a merchant\n");
  163. printf("2 - As a privateer\n");
  164. printf("3 - As a pirate\n");
  165. scanf("%d", &captaintype);
  166.  
  167. // This lets us cleanly store the captaintype label without needing an array (using string.h).
  168. size_t name;
  169.  
  170. // Assign captaintype, and teh corresponding funds, distanceperday, and name based on user input, check for invalid input.
  171. if (captaintype == 1) {
  172. funds = 1000;
  173. distanceperday = 80;
  174. name = "merchant";
  175. }
  176. if (captaintype == 2) {
  177. funds = 900;
  178. distanceperday = 90;
  179. name = "privateer";
  180. }
  181. if (captaintype == 3) {
  182. funds = 800;
  183. distanceperday = 100;
  184. name = "pirate";
  185. }
  186. if (captaintype != 1 && captaintype != 2 && captaintype != 3) {
  187. printf("Invalid Input Detected\n");
  188. }
  189.  
  190. // Tell the user what their captaintype gets.
  191. printf("As a %s, you begin your trip with %d gold pieces.\n", name, funds);
  192. printf("You will be sailing your Clipper, with an average speed of %d miles per day.\n\n", distanceperday);
  193.  
  194. // Query the user for their name.
  195. printf("What is your name, Captain?\n");
  196. scanf("%s",&crewnames[0]);
  197.  
  198. printf("%s\n", crewnames[0]);
  199.  
  200. // Query the user for additional crew member's names
  201. printf("Who are the other members of your crew?\n");
  202.  
  203. int i;
  204.  
  205. // Traverse the crewname array and scan strings into each row. Subtract 1 from NUMCREW to account for the captains name already being in the array, add 1 to i in crewnames[] to again account for the captains name being at position 0
  206. for(i=0;i<NUMCREW-1;i++) {
  207. scanf("%s",&crewnames[i+1]);
  208. }
  209.  
  210. // Print crew names starting with the 1st (array position 0)
  211. for(i=0;i<NUMCREW;i++) {
  212. printf("%d:%s\n", i+1, crewnames[i]);
  213. }
  214.  
  215. // All crew members start healthy
  216. for(i=0;i<NUMCREW;i++) {
  217. crewstatus[i] = 2;
  218. }
  219.  
  220. // All supply values start at 0
  221. for(i=0;i<NUMSUPPLIES;i++) {
  222. supplies[i] = 0;
  223. }
  224.  
  225. return;
  226.  
  227. }
  228.  
  229. //Pre-conditions: crewstatus is an array of numerical indicators for the status of each crew member
  230. // 0 - deceased, 1 - ill, 2 - healthy
  231. //Post-conditions: returns the number of crew members that are alive
  232.  
  233. //What to do in this function: Traverse the crew status array and count how many crew members
  234. // have a status that is not 0. Return this count.
  235. /** DONE NEEDS TESTING **/
  236. int countcrew(int crewstatus[NUMCREW]) {
  237.  
  238. int i, numalive=0;
  239. // Traverse the array and for everyone not dead, increment numalive.
  240. for(i=0;i<NUMCREW;i++) {
  241. if (crewstatus[i] != 0) {
  242. numalive = numalive+1;
  243. }
  244. }
  245. return numalive;
  246. }
  247.  
  248. //Pre-conditions: crew names is an array of strings for the crew members
  249. // crewstatus is an array of numerical indicators for the status of each crew member
  250. // 0 - deceased, 1 - ill, 2 - healthy
  251. //Post-conditions: none
  252.  
  253. //What to do in this function: print each crew members name and their status.
  254. // You may use a status array to shorten this process: char status[3][STRLENGTH] = {"Deceased", "Ill", "Healthy"};
  255. void printstatus(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW]) {
  256.  
  257. char status[3][STRLENGTH] = {"Deceased", "Ill", "Healthy"};
  258.  
  259. // Traverse the array and print crew names & their status
  260. int i;
  261. for(i=0;i<NUMCREW;i++) {
  262. printf("%s: %s\n",crewnames[i],status[crewstatus[i]]);
  263. }
  264. printf("\n");
  265. return;
  266. }
  267.  
  268. //Pre-conditions: supplytypes in an array of strings and gives the name of each supply type
  269. // supplies is an array of integers representing how many of each type the crew has
  270. // funds represents how many gold pieces the crew has to spend
  271. //Post-conditions: the user may choose to buy supplies: incrementing values in supplies and
  272. // decrementing funds
  273.  
  274. //What to do in this function: First print out the amount of gold the crew has.
  275. // Then print each supply type and the amount it costs. You may use a cost array to shorten
  276. // this process: int supplycosts[NUMSUPPLIES] = {1, 2, 20, 10};
  277. // Based on the user's selection, ask the user how many of that supply they would like to buy.
  278. // Verify that the user has enough gold for their purchase and update the correct index of supplies.
  279. // Deduct the corresponding amount from the user's funds.
  280. /** Why the fuck won't this work? **/
  281. /** funds returns as 65000, like wtf **/
  282. void getsupplies(char supplytypes[NUMSUPPLIES][STRLENGTH], int supplies[NUMSUPPLIES], int *funds) {
  283.  
  284. int r, shopping=1, numbought=0, costofitems=0;
  285.  
  286. int supplycosts[NUMSUPPLIES] = {1, 2, 20, 10};
  287.  
  288. char choice;
  289.  
  290. // Setup while loop for shopping
  291. while(shopping == 1) {
  292. \
  293. // Print options
  294. printf("You have %d gold pieces.\n", funds);
  295. printf("Available Supplies:\n");
  296. printf("1. Food - 1 gold pieces\n");
  297. printf("2. Clothes - 2 gold pieces\n");
  298. printf("3. Ship Parts - 20 gold pieces\n");
  299. printf("4. Shovels - 10 gold pieces\n");
  300. printf("5. Leave Store\n");
  301.  
  302. // Get user input for their desired option.
  303. // getch() masks the input to the console, getche() prints the input to the screen, getchar() only reads the input, we want getche().
  304. choice=getche();
  305.  
  306. if(choice == '1') {
  307. // Query user for how many of this item they'd like to buy
  308. printf("How many pounds of food would you like to buy?\n");
  309. scanf("%d",&numbought);
  310. // Calculate total cost of these items.
  311. costofitems = supplycosts[0]*numbought;
  312.  
  313. // Can they afford the amount of items they asked for?
  314. if (funds >= costofitems) {
  315. // If they can afford it, decrement funds & add supplies to their inventory
  316. funds = funds - (supplycosts[0]*numbought);
  317. supplies[0] = supplies[0] + numbought;
  318. }
  319. // If they can't afford the amount they asked for.
  320. else
  321. printf("Sorry, you cannot afford that many pounds of food.");
  322.  
  323.  
  324. // Reset variables for later use
  325. numbought=0;
  326. costofitems=0;
  327. }
  328.  
  329. if(choice=='2') {
  330. // Query user for how many of this item they'd like to buy
  331. printf("How many pounds of food would you like to buy?\n");
  332. scanf("%d",&numbought);
  333. // Calculate total cost of these items.
  334. costofitems = supplycosts[1]*numbought;
  335.  
  336. // Can they afford the amount of items they asked for?
  337. if (funds >= costofitems) {
  338. // If they can afford it, decrement funds & add supplies to their inventory
  339. funds = funds - (supplycosts[1]*numbought);
  340. supplies[1] = supplies[1] + numbought;
  341. }
  342. // If they can't afford the amount they asked for.
  343. else
  344. printf("Sorry, you cannot afford that many pounds of food.");
  345.  
  346.  
  347. // Reset variables for later use
  348. numbought=0;
  349. costofitems=0;
  350. }
  351.  
  352. if(choice=='3') {
  353. // Query user for how many of this item they'd like to buy
  354. printf("How many pounds of food would you like to buy?\n");
  355. scanf("%d",&numbought);
  356. // Calculate total cost of these items.
  357. costofitems = supplycosts[2]*numbought;
  358.  
  359. // Can they afford the amount of items they asked for?
  360. if (funds >= costofitems) {
  361. // If they can afford it, decrement funds & add supplies to their inventory
  362. funds = funds - (supplycosts[2]*numbought);
  363. supplies[2] = supplies[2] + numbought;
  364. }
  365. // If they can't afford the amount they asked for.
  366. else
  367. printf("Sorry, you cannot afford that many pounds of food.");
  368.  
  369.  
  370. // Reset variables for later use
  371. numbought=0;
  372. costofitems=0;
  373. }
  374.  
  375. if(choice=='4') {
  376. // Query user for how many of this item they'd like to buy
  377. printf("How many pounds of food would you like to buy?\n");
  378. scanf("%d",&numbought);
  379. // Calculate total cost of these items.
  380. costofitems = supplycosts[3]*numbought;
  381.  
  382. // Can they afford the amount of items they asked for?
  383. if (funds >= costofitems) {
  384. // If they can afford it, decrement funds & add supplies to their inventory
  385. funds = funds - (supplycosts[3]*numbought);
  386. supplies[3] = supplies[3] + numbought;
  387. }
  388. // If they can't afford the amount they asked for.
  389. else
  390. printf("Sorry, you cannot afford that many pounds of food.");
  391.  
  392.  
  393. // Reset variables for later use
  394. numbought=0;
  395. costofitems=0;
  396. }
  397.  
  398. if(choice=='5'){
  399. // Break while loop.
  400. shopping=0;
  401. }
  402. }
  403.  
  404. // Print remaining gold pieces after shopping is complete.
  405. printf("You have %d gold pieces.\n", funds);
  406. return;
  407. }
  408.  
  409. //Pre-conditions: crew names is an array of strings for the crew members
  410. // crewstatus is an array of numerical indicators for the status of each crew member
  411. // 0 - deceased, 1 - ill, 2 - healthy
  412. // supplies is an array of integers representing how many of each type the crew has
  413. // funds represents how many gold pieces the crew has to spend
  414. // traveled represents the total number of miles the ship has traveled from the beginning
  415. //Post-conditions: none
  416.  
  417. //What to do in this function: Print a daily status report by telling the user how many miles have been
  418. // traveled. Then, print the status of the crew by calling printstatus. Print the funds and amount
  419. // of food that the ship has. Then, let the user know how far they are from their next destination.
  420. /** DONE NEEDS TESTING **/
  421. void dailyreport(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int supplies[NUMSUPPLIES], int funds, int traveled) {
  422.  
  423. // Calculate miles to next destination
  424. int distancetodest, secondleg, thridleg;
  425. secondleg = CANARY + GRENADA;
  426. thirdleg = CANARY + GRENADA + FINAL;
  427.  
  428. if (traveled <= CANARY)
  429. distancetodest = CANARY - traveled;
  430. else if (traveled <= secondleg)
  431. distancetodest = secondleg - traveled;
  432. else if (traveled <= thirdleg)
  433. distancetodest = thirdleg - traveled;
  434.  
  435. // Print the daily report
  436. printf("You have traveled %d miles.\n", traveled);
  437. printstatus(crewnames, crewstatus);
  438. printf("You have %d gold pieces.\n", funds);
  439. printf("You have %d pounds of food.\n", supplies[0]);
  440. printf("You are %d miles from your next destination.\n", distancetodest);
  441.  
  442. return;
  443. }
  444.  
  445. //Pre-conditions: a and b are both integers
  446. //Post-conditions: the larger value will be returned
  447. /** DONE **/
  448. int max(int a, int b) {
  449.  
  450. // Which value is greater?
  451. if (a > b) {
  452. return a;
  453. }
  454. if (b > a) {
  455. return b;
  456. }
  457. }
  458.  
  459. //Pre-conditions: a and b are both integers
  460. //Post-conditions: the smaller value will be returned
  461. /** DONE **/
  462. int min(int a, int b) {
  463.  
  464. // Which value is less?
  465. if (a < b) {
  466. return a;
  467. }
  468. if (b < a) {
  469. return b;
  470. }
  471. }
  472.  
  473. //Pre-conditions: supplies is an array of integers representing how many of each type the crew has
  474. // crew names is an array of strings for the crew members
  475. // crewstatus is an array of numerical indicators for the status of each crew member
  476. // 0 - deceased, 1 - ill, 2 - healthy
  477. // days represents the current day
  478. //Post-conditions: the user will select a number of days to rest for. update days to reflect this number
  479. // there is a small chance an ill crew member will recover during rest days
  480.  
  481. //What to do in this function: ask the user how many days they would like to rest for.
  482. // Updates days to indicate that that many days has now passed. Deduct 2 pounds of food
  483. // for each crew member for each day rested.
  484.  
  485. // Generate a pseudorandom value that will be either 0 or 1. Generate a second value
  486. // between 0 and the number of original crew members. If the first number is a 1,
  487. // the crew member in the index of the second number may recover if they are sick.
  488. // If they are healthy or deceased, nothing happens. If the first number is a 0,
  489. // nothing happens.
  490. /** DONE NEEDS TESTING **/
  491. void rest(int supplies[NUMSUPPLIES], char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int *days) {
  492.  
  493. int daystorest=0;
  494.  
  495. // Ask the user how long they'd like to rest.
  496. printf("How many days would you like to rest for?\n");
  497. scanf("%d",&daystorest);
  498. // Increment days counter.
  499. days = days+daystorest;
  500. // Consume supplies in days they rest.
  501. supplies[0] = supplies[0] - (daystorest * (countcrew(crewstatus)* 2));
  502.  
  503. int random_number1, random_number2;
  504. // Calculate random number thats either 1 or 0
  505. random_number1 = rand() % 1;
  506. // Calculate random number thats between 1 and 4 inclusive
  507. random_number2 = rand() % (NUMCREW-1);
  508.  
  509. // Follow the logic define above, and recover sick crew members if random numbers match certain values.
  510. if (random_number1 == 1 && crewstatus[random_number2] != 0 && crewstatus[random_number2] != 2) {
  511. crewstatus[random_number2] = 2;
  512. printf("%s has recovered.", crewnames[random_number2]);
  513. }
  514.  
  515. return;
  516. }
  517.  
  518. //Pre-conditions: none
  519. //Post-conditions: returns the number of pounds of fish gained by the ship
  520.  
  521. //What to do in this function: Generate a pseudorandom value between 0 and 3, inclusive.
  522. // Multiply this number by 50 and tell the user how many fish were caught. Return
  523. // this value.
  524. /** DONE **/
  525. int fish() {
  526.  
  527. // Calculate a random number between 0 and 3 inclusive
  528. int random_number, num_fish;
  529. random_number = rand() % 3;
  530. num_fish = random_number * 50;
  531. printf("Your crew lowers the nets and pulls up %d pounds of fish.\n", num_fish);
  532.  
  533. return num_fish;
  534. }
  535.  
  536. //Pre-conditions: crew names is an array of strings for the crew members
  537. // crewstatus is an array of numerical indicators for the status of each crew member
  538. // 0 - deceased, 1 - ill, 2 - healthy
  539. // days represents the current day
  540. // supplies is an array of integers representing how many of each type the crew has
  541. //Post-conditions: the status of a crew member or supplies may be affected by a random event,
  542. // some events cause the ship to be delayed a certain number of days
  543.  
  544. //What to do in this function: Generate a pseudorandom number between 0 and 9, inclusive. If the user
  545. // has run out of food, tell the user they have no food and increase your number by 2. This number cannot
  546. // exceed 9.
  547.  
  548. // Numbers 0, 1, and 2 do not correspond with any events.
  549. // Numbers 3 and 4 correspond with "positive events"
  550. // on a 3 the user will gain between 1 and 4 ship parts determined randomly
  551. // on a 4 the user will gain between 10 and 60 pounds of food determined randomly
  552. // both events take 1 day
  553. // Number 5 means the user will lose between 5 and 55 pounds of food
  554. // this event takes 1 day
  555. // Number 6 means the ship is stuck in fog, which takes 1 day
  556. // Number 7 means the ship is in a storm, which takes 2 days
  557. // Number 8 means something on the ship has broken
  558. // check the number of extra ship parts the crew has
  559. // if they have at least one ship part, they can replace it and continue
  560. // this takes 1 day
  561. // if they have no extra parts, they must stop and repair
  562. // this takes 3 days
  563. // Number 9 indicates sickness. Generate a random number between 0 and the original
  564. // number of crew members. Check the status of that crew member: if they are healthy,
  565. // they now fall ill. If they are already ill, they now perish. If they are already
  566. // deceased, nothing happens.
  567.  
  568. // For any days spent in this way, deduct 2 pounds of food per crew member per day.
  569. /** DONE NEEDS TESTING **/
  570. void event(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int *days, int supplies[NUMSUPPLIES]) {
  571.  
  572. int random_number3, random_number4, random_number5, random_number6;
  573. // Calculate a random number between 0 and 10 inclusive
  574. random_number3 = rand() % 10;
  575.  
  576. // Is the user out of food?
  577. if (supplies[0] == 0) {
  578. printf("You are out of food!");
  579. // Value can't exceed 9
  580. if (random_number3 < 8) {
  581. random_number3 = random_number3 + 2;
  582. }
  583. }
  584.  
  585. // Good event (3)
  586. if (random_number3 == 3) {
  587. random_number4 = (rand() % 4) +1;
  588. supplies[2] = supplies[2] + random_number4;
  589. printf("Another pirate ship pulls alongside and attacks!\n");
  590. printf("You fend them off and take %d extra ship parts.\n", random_number4);
  591. printf("You spend the day recovering.\n");
  592. // Increment days counter for rest day
  593. days = days + 1;
  594. // Decrement food for rest day
  595. supplies[0] = supplies[0] - ((countcrew(crewstatus)* 2));
  596. }
  597.  
  598. // Good event (4)
  599. if (random_number3 == 4) {
  600. random_number4 = (rand() % 50) + 11;
  601. supplies[0] = supplies[0] + random_number4;
  602. printf("Another pirate ship pulls alongside and attacks!\n");
  603. printf("You fend them off and take %d pounds of their food.\n", random_number4);
  604. printf("You spend the day recovering.\n");
  605. //Increment days counter for rest day
  606. days = days + 1;
  607. // Decrement food for rest day
  608. supplies[0] = supplies[0] - ((countcrew(crewstatus)* 2));
  609. }
  610.  
  611. // Bad event (5)
  612. if (random_number3 == 5) {
  613. random_number4 = (rand() % 50) + 6;
  614. supplies[0] = supplies[0] - random_number4;
  615. printf("Another pirate ship pulls alongside and attacks!\n");
  616. printf("They took %d pounds of food and you spend the day recovering.\n.", random_number4);
  617. // Increment days counter for rest day
  618. days = days + 1;
  619. // Decrement food for rest day
  620. supplies[0] = supplies[0] - ((countcrew(crewstatus)* 2));
  621. }
  622.  
  623. // Bad event (6)
  624. if (random_number3 == 6) {
  625. printf("Fog surrounds your ship. Drop anchor for one day.\n");
  626. // Increment days counter for rest day
  627. days = days + 1;
  628. // Decrement food for rest day
  629. supplies[0] = supplies[0] - ((countcrew(crewstatus)* 2));
  630. }
  631.  
  632. // Bad event (7)
  633. if (random_number3 == 7) {
  634. printf("An ocean storm batters your ship. Drop anchor for two days.\n");
  635. // Increment days counter for rest days
  636. days = days + 2;
  637. // Decrement food for rest days
  638. supplies[0] = supplies[0] - (2 * (countcrew(crewstatus)* 2));
  639. }
  640.  
  641. // Bad event (8)
  642. if (random_number3 == 8) {
  643. supplies[0] = supplies[0] - random_number4;
  644. printf("A part of your ship has broken!");
  645.  
  646. // Do they have extra ship parts?
  647. if (supplies[2] >= 1) {
  648. printf("You replace the broken part. It takes one day.\n");
  649. // Increment days counter for rest day
  650. days = days + 1;
  651. // Decrement food for rest day
  652. supplies[0] = supplies[0] - ((countcrew(crewstatus)* 2));
  653. }
  654.  
  655. // If they don't have extra ship parts.
  656. if (supplies[2] == 0) {
  657. printf("You have no replacement parts. It takes three days t repair.\n");
  658. // Increment days counter for rest days
  659. days = days + 3;
  660. // Decrement food for rest days
  661. supplies[0] = supplies[0] - (3 * (countcrew(crewstatus)* 2));
  662. }
  663. }
  664.  
  665. // Bad event (9)
  666. if (random_number3 == 9) {
  667.  
  668. // NUMCREW-1 to make our number align with the crew members position in the array
  669. random_number5 = rand() % (NUMCREW-1);
  670.  
  671. // If they are healthy, make them ill
  672. if (crewstatus[random_number5] == 2) {
  673. crewstatus[random_number5] = 1;
  674. printf("%s has fallen ill.\n", crewnames[random_number5]);
  675.  
  676. }
  677.  
  678. // If they are ill, they perish.
  679. if (crewstatus[random_number5] == 1) {
  680. crewstatus[random_number5] = 0;
  681. printf("%s has died.\n", crewnames[random_number5]);
  682.  
  683. }
  684. }
  685. return;
  686. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement