Advertisement
TheCobyLot

Untitled

Aug 3rd, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.09 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. #include<stdlib.h>
  5. typedef struct skill{
  6. char skillName[30];
  7. int hits;
  8. }skillType;
  9. typedef struct hero{
  10. char name[10];
  11. skillType skill[3];
  12. int level;
  13. int exp;
  14. }heroType;
  15. typedef struct{
  16. int value, found;
  17. }cardType;
  18. typedef struct hL{
  19. heroType heroes[5];
  20. int noOfHeroes;
  21. cardType card[10];
  22. }heroListType;
  23. int insertFirst(heroListType *a, char nameHero[]);
  24. int deleteHero(char nameHero[],heroListType *b);
  25. void display(heroListType *a);
  26. void game(heroListType *hero, int);
  27. int levelUp(heroListType *hero);
  28. void memoryGame(heroListType *hero);
  29. void memoryFill(heroListType *hero);
  30. void memoryGuess(heroListType *hero);
  31. int memoryPlay(heroListType *hero);
  32. int main(void)
  33. {
  34. heroListType hero;
  35. char aName[10],xName[10],choice;
  36. int i, ip;
  37. hero.noOfHeroes=0;
  38. printf("\n\n\n\n\n\n\t\t\t \20\20\20TRALSE DUNGEONEERING\21\21\21\n\n\n");
  39. printf(" \t\t\t\tby: Toneyap\n\n\n");
  40. printf("\t\t\t");
  41. system("pause");
  42. system("cls");
  43. do{
  44. printf("\n\n\n________________________________________________________________________________");
  45. printf("\n\n\n\t\20 A - ADD HERO\n\t\20 D - DELETE HERO\n\t\20 I - DISPLAY HERO INFORMATION\n\t\20 S - START GAME\n\t\20 E - EXIT:\n\n");
  46. printf("\n________________________________________________________________________________");
  47. printf("CHOOSE YOUR LETTER: ");
  48. scanf("%c",&choice);
  49. fflush(stdin);
  50.  
  51. printf("\n");
  52. system("cls");
  53. if(choice=='A'||choice=='a'){
  54. printf("\nEnter name: ");
  55. fflush(stdin);
  56. gets(aName);
  57.  
  58.  
  59. if(insertFirst(&hero, aName)==0){
  60. printf("\nHERO WAS ADDED!\n\n");
  61. }else{
  62. printf("\nERROR! CANNOT ADD ANYMORE\n\n");
  63. }
  64. system("pause");
  65. system("cls");
  66. }else if(choice=='d'||choice=='D'){
  67. printf("Enter name:");
  68. fflush(stdin);
  69. gets(xName);
  70. if(deleteHero(xName,&hero)==0){
  71. printf("\nHERO WAS DELETED!\n\n");
  72. }else{
  73. printf("\nERROR! HERO NOT FOUND\n\n");
  74. }
  75. }else if(choice=='I'||choice=='i'){
  76. display(&hero);
  77. }else if(choice=='s' || choice=='S'){
  78. game(&hero, ip);
  79. }else if(choice=='E' || choice=='e'){
  80. printf("\n\n\n\n\t\t Thank you! Please use our program again. \n\n\n\n\n");
  81. return 0;
  82. }
  83. }while(choice!='E' || choice!='e');
  84. getch ();
  85. return 0;
  86. }
  87. int insertFirst(heroListType *a, char nameHero[])
  88. {
  89.  
  90. int ret=0, i,x;
  91. if (((*a).noOfHeroes)== 5){
  92. printf("ERROR! cannot insert anymore\n");
  93. ret=1;
  94. }else{
  95. for(i=0; i<(*a).noOfHeroes; i++){
  96. (*a).heroes[(*a).noOfHeroes+i]=(*a).heroes[i];
  97. }
  98. }
  99. strcpy((*a).heroes[i].name, nameHero);
  100. (*a).heroes[0].exp=0;
  101. (*a).heroes[0].level=1;
  102. (*a).noOfHeroes+=1;
  103. for(x=0; x<3;x++){
  104. (*a).heroes[i].skill[x].hits=0;
  105. }
  106. //(*a).heroes[0].skill[1].hits=0;
  107. //(*a).heroes[0].skill[2].hits=0;
  108. for(x=0; x<3;x++){
  109. strcpy((*a).heroes[i].skill[x].skillName, "");
  110. }
  111. //strcpy((*a).heroes[i].skill[1].skillName, "");
  112. //strcpy((*a).heroes[i].skill[2].skillName, "");
  113.  
  114.  
  115. return ret;
  116. }
  117.  
  118. int deleteHero(char nameHero[],heroListType *b){
  119. int ret=1,i,j,x=-1;
  120.  
  121. for(i=0;i<((*b).noOfHeroes);i++){
  122. if(strcmp((*b).heroes[i].name,nameHero)==0){
  123. x=i;
  124. ret=0;
  125. }}
  126. if(x!=-1){
  127. for(j=x;j<((*b).noOfHeroes);j++){
  128. ((*b).heroes[x])=((*b).heroes[x+1]);
  129. }
  130. (*b).noOfHeroes-=1;
  131. }else{
  132. printf("Error!\n");
  133. }
  134. return ret;
  135. }
  136. void display(heroListType *a)
  137. {
  138.  
  139.  
  140. int i,j;
  141. for(i=0;i<((*a).noOfHeroes);i++)
  142. {
  143. printf("---------------Hero %d INFORMATION---------------\n",i+1);
  144. printf("\n\t\20 Name: ");
  145. printf("%s", (*a).heroes[i].name);
  146. printf("\n\t\20 Your XP: %d", (*a).heroes[i].exp);
  147. printf("\n\t\20 Hero LVL: %d", (*a).heroes[i].level);
  148. printf("\n\t\20 Skill 1: %s \tDamamge/hit: %d", (*a).heroes[i].skill[0].skillName, a->heroes[i].skill[0].hits);
  149. printf("\n\t\20 Skill 2: %s \tDamamge/hit: %d", (*a).heroes[i].skill[1].skillName, a->heroes[i].skill[1].hits);
  150. printf("\n\t\20 Skill 3: %s \tDamamge/hit: %d", (*a).heroes[i].skill[2].skillName, a->heroes[i].skill[2].hits);
  151. printf("\n------------------------------------------------\n\n");
  152. }
  153.  
  154.  
  155. printf("Number of Hero(es): %d\n\n\n", i);
  156. system("pause");
  157. system("cls");
  158. }
  159. void game(heroListType *hero, int input){
  160. char ans;
  161. int ip, x;
  162. printf("Pick The Hero of Your Choice:\n");
  163. for(x=0;x<hero->noOfHeroes;x++){
  164.  
  165. printf("%d.) %s\n", x+1, (*hero).heroes[x].name);
  166. }
  167. printf("\nNumber of hero you want to play.");
  168. printf("\nEnter number: ");
  169. scanf("%d", &ip);
  170. printf("\n\n\nLET THE GAMES BEGIN!\n");
  171. printf("May the odds be in your favor! \27\n\n\n\n\n\n");
  172. system("pause");
  173. system("cls");
  174.  
  175. if((*hero).heroes[ip-1].level==1){
  176. fflush(stdin);
  177. printf("\n1 correct answer == 1 XP.\n\nEvery 5 XP = 1 level. \n\nThe game gets harder each level\n\nGood Luck and God Bless! :). ");
  178. printf("\n\n\t\t\t");
  179. system("pause");
  180. system("cls");;
  181. printf("\n\t\t\tDungeon Tralse Level 1");
  182. printf("\n\t\t\t");
  183. system("pause");
  184. system("cls");
  185. printf("\n\t\t\tT-True and F-False\n\n");
  186. printf("Is Marcelo H Del Pillar is one of the colleague of Jose Rizal? ");
  187. printf("\n \20 ");
  188. scanf("%c", &ans);
  189. if(ans=='T' || ans=='t'){
  190. (*hero).heroes[ip-1].exp++;
  191. }
  192. fflush(stdin);
  193.  
  194. printf("\nDo we need water? ");
  195. printf("\n \20 ");
  196. scanf("%c", &ans);
  197. if(ans=='T' || ans=='t'){
  198. (*hero).heroes[ip-1].exp++;
  199. }
  200. fflush(stdin);
  201.  
  202. printf("\nA triangle has 59 sides. ");
  203. printf("\n \20 ");
  204. scanf("%c", &ans);
  205.  
  206. if(ans=='f' || ans=='F'){
  207. (*hero).heroes[ip-1].exp++;
  208. }
  209. // lvl 2
  210. }else if((*hero).heroes[ip-1].level==2){
  211. printf("\n\t\t\tDungeon Tralse Level 2");
  212. fflush(stdin);
  213. printf("\nIs Console better than PC?Y/N: \n");
  214. printf("\32");
  215. scanf("%c", &ans);
  216. if(ans=='N' || ans == 'n'){
  217. (*hero).heroes[ip-1].exp++;
  218. printf("\nCorrect!");
  219. }else if (ans == 'Y' || ans == 'y'){
  220. printf("\nWrong!");
  221. }
  222. fflush(stdin);
  223. printf("\nIs Tomato a fruit?Y/N: \n");
  224. printf("\32");
  225. scanf("%c", &ans);
  226. if(ans=='Y' || ans == 'y'){
  227. (*hero).heroes[ip-1].exp++;
  228. printf("\nCorrect!");
  229. }else if (ans == 'N' || ans == 'n'){
  230. printf("\nWrong!");
  231. }
  232. fflush(stdin);
  233. printf("\nAre you happy?Y/N: \n");
  234. printf("\32");
  235. scanf("%c", &ans);
  236. if(ans=='N' || ans == 'n'){
  237. (*hero).heroes[ip-1].exp++;
  238. printf("\nCorrect!");
  239. }else if (ans == 'Y' || ans == 'y'){
  240. printf("\nWrong!");
  241. }
  242. // lvl 3
  243. }else if((*hero).heroes[ip-1].level==3){
  244. printf("\n\t\t\tDungeon Tralse Level 3");
  245. fflush(stdin);
  246. printf("\nWho is our current President? \na.)Noynoy Aquino \tb.)Gloria Arroyo \tc.)Manny Villar\n");
  247. printf("\32");
  248. scanf("%c", &ans);
  249. if(ans=='a' || ans == 'A'){
  250. (*hero).heroes[ip-1].exp++;
  251. printf("\nCorrect!");
  252. }else if(ans!='a'||ans!='A'){
  253. printf("\nIncorrect!");
  254. }
  255. fflush(stdin);
  256. printf("\nWho is the National Hero of the Philippines? \na.)D. Jusi Rezal \tb.)Dr. Jose Rizal \tc.)Dr. Jericho Rosales\n ");
  257. printf("\32");
  258. scanf("%c", &ans);
  259. if(ans=='b' || ans == 'B'){
  260. (*hero).heroes[ip-1].exp++;
  261. printf("\nCorrect!");
  262. }
  263. else if(ans!='b'||ans!='B'){
  264. printf("\nIncorrect!");
  265. }
  266.  
  267. fflush(stdin);
  268. printf("\nWhich of the following doesnt fit in?\n a.)Volcano \tb.)Sea \tc.)city\n ");
  269. printf("\32");
  270. scanf("%c", &ans);
  271. if(ans=='C' || ans == 'c'){
  272. (*hero).heroes[ip-1].exp++;
  273. printf("\nCorrect!");
  274. }
  275. else if(ans!='c'||ans!='c'){
  276. printf("\nIncorrect!");
  277. }
  278. // lvl 4
  279. }else if((*hero).heroes[ip-1].level==4){
  280. printf("\n\t\t\tDungeon Tralse Level 4");
  281. fflush(stdin);
  282. printf("\nUnsang lugara sa Cebu nga mamadlong? \na.)Mambaling \tb.)Mandaue \tc.)Badian\n");
  283. printf("\32");
  284. scanf("%c", &ans);
  285. if(ans=='c' || ans == 'c'){
  286. (*hero).heroes[ip-1].exp++;
  287. printf("\nCorrect!");
  288. }else if(ans!='a'||ans!='A'){
  289. printf("\nIncorrect!");
  290. }
  291. fflush(stdin);
  292. printf("\nUnsang lugara sa Cebu nga switch? \na.)Moalboal \tb.)Opon \tc.)Carmen\n");
  293. printf("\32");
  294. scanf("%c", &ans);
  295. if(ans=='c' || ans == 'c'){
  296. (*hero).heroes[ip-1].exp++;
  297. printf("\nCorrect!");
  298. }else if(ans!='a'||ans!='A'){
  299. printf("\nIncorrect!");
  300. }
  301. fflush(stdin);
  302. printf("\nKung ang lain og batasan kay bati ang walay batasan? \na.)Masbate \tb.)Bohol \tc.)Davao\n");
  303. printf("\32");
  304. scanf("%c", &ans);
  305. if(ans=='a' || ans == 'A'){
  306. (*hero).heroes[ip-1].exp++;
  307. printf("\nCorrect!");
  308. }else if(ans!='a'||ans!='A'){
  309. printf("\nIncorrect!");
  310. }
  311. // lvl 5
  312. }else if((*hero).heroes[ip-1].level==5){
  313. printf("\n\t\t\tDungeon Tralse Level 5");
  314. printf("\n\nWarning: Enter at your own risk\nContinue? Y/N: ");
  315. scanf("%c", &ans);
  316. if(ans == 'y' || ans == 'Y'){
  317. memoryGame(hero);
  318. } else if(ans == 'n' || ans == 'N'){
  319. printf("Nice choice.");
  320. }
  321. fflush(stdin);
  322. }
  323.  
  324. printf("\n\nYou Gained: %d", (*hero).heroes[ip-1].exp);
  325. if((*hero).heroes[ip-1].exp>=5){
  326. fflush(stdin);
  327. printf("\nYour XP is now %d.\nYou now level Up. \n Do you want to unlock new skill? Y/N: ", (*hero).heroes[ip-1].exp);
  328. scanf("%c", &ans);
  329. if(ans == 'y' || ans == 'Y'){
  330. (*hero).heroes[ip-1].level=levelUp(hero);
  331. }else if(ans == 'n'|| ans == 'N'){
  332. printf("Okay.");
  333. }
  334. }
  335. }
  336. void memoryGame(heroListType *hero){
  337. int ret;
  338. printf("Right - Wrong");
  339. do{
  340. memoryFill(hero);
  341. printf("\n\n");
  342. memoryGuess(hero);
  343. printf("\n\n");
  344. memoryPlay(hero);
  345. }while(ret!=10);
  346. }
  347. void memoryFill(heroListType *hero){
  348. hero->card[0].value = 7;
  349. hero->card[1].value = 4;
  350. hero->card[2].value = 3;
  351. hero->card[3].value = 9;
  352. hero->card[4].value = 6;
  353. hero->card[5].value = 7;
  354. hero->card[6].value = 6;
  355. hero->card[7].value = 9;
  356. hero->card[8].value = 3;
  357. hero->card[9].value = 4;
  358. }
  359. void memoryGuess(heroListType *hero){
  360. int i, correct = 0;
  361. for(i=0;i<10;i++){
  362. if(hero->card[i].found == 1){
  363. printf("%d ", hero->card[i].value);
  364. correct++;
  365. } else {
  366. printf("* ");
  367. }
  368. }
  369. }
  370. int memoryPlay(heroListType *hero){
  371. int one, two, i;
  372. printf("Guess first position <1-10>: ");
  373. scanf("%d", &one+1);
  374. printf("Guess second position <1-10>: ");
  375. scanf("%d", &two+1);
  376. if(hero->card[one].value == hero->card[two].value){
  377. hero->card[one].found = 1;
  378. hero->card[two].found = 1;
  379. return i+=2;
  380. }
  381. }
  382. int levelUp(heroListType *hero){
  383. int i;
  384. for(i=0;i<3;i++){
  385.  
  386. if((*hero).heroes[i].exp>=5){
  387. hero->heroes[i].level+=1;
  388. hero->heroes[i].exp-=5;
  389. }
  390. // 1st skill
  391. if(hero->heroes[i].level==2){
  392. fflush(stdin);
  393.  
  394. printf("Enter 1st skill: ");
  395. gets(hero->heroes[i].skill[0].skillName);
  396. do{
  397. printf("\nHits (30-60/hit): ");
  398. scanf("%d", &hero->heroes[i].skill[0].hits);
  399. fflush(stdin);
  400. if(hero->heroes[i].skill[0].hits<30||hero->heroes[i].skill[0].hits>60){
  401. printf("Invalid Input, Please Try Again!\n");
  402. }else{
  403. printf("Successfully Added!\n");
  404. }
  405. }while(hero->heroes[i].skill[0].hits<30||hero->heroes[i].skill[0].hits>60);
  406. system("pause");
  407. system("cls");
  408. // 2nd skill
  409. }else if(hero->heroes[i].level==3){
  410. fflush(stdin);
  411.  
  412. printf("Enter 2nd skill: ");
  413. gets(hero->heroes[i].skill[1].skillName);
  414.  
  415. printf("\nHits (61-80/hit): ");
  416. scanf("%d", &hero->heroes[i].skill[1].hits);
  417. do{
  418. if(hero->heroes[i].skill[1].hits<61||hero->heroes[i].skill[1].hits>80){
  419. printf("Invalid Input, Please Try Again!\n");
  420. }else{
  421. printf("Successfully Added!\n");
  422. }
  423. }while(hero->heroes[i].skill[1].hits<61||hero->heroes[i].skill[1].hits>80);
  424. system("pause");
  425. system("cls");
  426. // 3rd skill
  427. }else if(hero->heroes[i].level==4){
  428. fflush(stdin);
  429.  
  430. printf("Enter 3rd skill: ");
  431. gets(hero->heroes[i].skill[2].skillName);
  432.  
  433. printf("\nHits (81-100/hit): ");
  434. scanf("%d", &hero->heroes[i].skill[2].hits);
  435. do{
  436. if(hero->heroes[i].skill[2].hits<81||hero->heroes[i].skill[2].hits>100){
  437. printf("Invalid Input, Please Try Again!\n");
  438. }else{
  439. printf("Successfully Added!\n");
  440. }
  441. }while(hero->heroes[i].skill[2].hits<81||hero->heroes[i].skill[2].hits>100);
  442. system("pause");
  443. system("cls");
  444. }
  445. return hero->heroes[i].level;
  446. }
  447. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement