Advertisement
TheCobyLot

Hero.c

Jul 30th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.83 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 hL{
  16. heroType heroes[5];
  17. int noOfHeroes;
  18. }heroListType;
  19. int insertFirst(heroListType *a, char nameHero[]);
  20. int deleteHero(char nameHero[],heroListType *b);
  21. void display(heroListType *a);
  22. void game(heroListType *hero, int);
  23. int levelUp(heroListType *hero);
  24. int main(void)
  25. {
  26. heroListType hero;
  27. char aName[10],xName[10],choice;
  28. int i, ip;
  29. hero.noOfHeroes=0;
  30. printf("\n\n\n\n\n\n\t\t\t \20\20\20TRALSE DUNGEONEERING\21\21\21\n\n\n");
  31. printf(" \t\t\t\tby: Toneyap\n\n\n");
  32. printf("\t\t\t");
  33. system("pause");
  34. system("cls");
  35. do{
  36. printf("\n\n\n________________________________________________________________________________");
  37. 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");
  38. printf("\n________________________________________________________________________________");
  39. printf("CHOOSE YOUR LETTER: ");
  40. scanf("%c",&choice);
  41. fflush(stdin);
  42.  
  43. printf("\n");
  44. system("cls");
  45. if(choice=='A'||choice=='a'){
  46. printf("\nEnter name: ");
  47. fflush(stdin);
  48. gets(aName);
  49.  
  50.  
  51. if(insertFirst(&hero, aName)==0){
  52. printf("\nHERO WAS ADDED!\n");
  53. }else{
  54. printf("\nERROR! CANNOT ADD ANYMORE\n");
  55. }
  56. system("pause");
  57. system("cls");
  58. }else if(choice=='d'||choice=='D'){
  59. printf("Enter name:");
  60. fflush(stdin);
  61. gets(xName);
  62. if(deleteHero(xName,&hero)==0){
  63. printf("\nHERO WAS DELETED!\n");
  64. }else{
  65. printf("\nERROR! HERO NOT FOUND\n");
  66. }
  67. }else if(choice=='I'||choice=='i'){
  68. display(&hero);
  69. }else if(choice=='s' || choice=='S'){
  70. game(&hero, ip);
  71. }else if(choice=='E' || choice=='e'){
  72. printf("\n\n\n\n\t\t Thanks you! Please use our program again. \n\n\n\n\n");
  73. return 0;
  74. }
  75. }while(choice!='E' || choice!='e');
  76. getch ();
  77. return 0;
  78. }
  79. int insertFirst(heroListType *a, char nameHero[])
  80. {
  81.  
  82. int ret=0, i,x;
  83. if (((*a).noOfHeroes)== 5){
  84. printf("ERROR! cannot insert anymore\n");
  85. ret=1;
  86. }else{
  87. for(i=0; i<(*a).noOfHeroes; i++){
  88. (*a).heroes[(*a).noOfHeroes+i]=(*a).heroes[i];
  89. }
  90. }
  91. strcpy((*a).heroes[i].name, nameHero);
  92. (*a).heroes[0].exp=0;
  93. (*a).heroes[0].level=1;
  94. (*a).noOfHeroes+=1;
  95. for(x=0; x<3;x++){
  96. (*a).heroes[0].skill[x].hits=0;
  97. }
  98. //(*a).heroes[0].skill[1].hits=0;
  99. //(*a).heroes[0].skill[2].hits=0;
  100. for(x=0; x<3;x++){
  101. strcpy((*a).heroes[i].skill[x].skillName, "");
  102. }
  103. //strcpy((*a).heroes[i].skill[1].skillName, "");
  104. //strcpy((*a).heroes[i].skill[2].skillName, "");
  105.  
  106.  
  107. return ret;
  108. }
  109.  
  110. int deleteHero(char nameHero[],heroListType *b){
  111. int ret=1,i,j,x=-1;
  112.  
  113. for(i=0;i<((*b).noOfHeroes);i++){
  114. if(strcmp((*b).heroes[i].name,nameHero)==0){
  115. x=i;
  116. ret=0;
  117. }}
  118. if(x!=-1){
  119. for(j=x;j<((*b).noOfHeroes);j++){
  120. ((*b).heroes[x])=((*b).heroes[x+1]);
  121. }
  122. (*b).noOfHeroes-=1;
  123. }else{
  124. printf("Error!\n");
  125. }
  126. return ret;
  127. }
  128. void display(heroListType *a)
  129. {
  130.  
  131.  
  132. int i,j;
  133. for(i=0;i<((*a).noOfHeroes);i++)
  134. {
  135. printf("---------------Hero %d INFORMATION---------------\n",i+1);
  136. printf("\n\t\20 Name: ");
  137. printf("%s", (*a).heroes[i].name);
  138. printf("\n\t\20 Your XP: %d", (*a).heroes[i].exp);
  139. printf("\n\t\20 Hero LVL: %d", (*a).heroes[i].level);
  140. printf("\n\t\20 Skill 1: %s \tDamamge/hit: %d", (*a).heroes[i].skill[0].skillName, a->heroes[i].skill[0].hits);
  141. printf("\n\t\20 Skill 2: %s \tDamamge/hit: %d", (*a).heroes[i].skill[1].skillName, a->heroes[i].skill[1].hits);
  142. printf("\n\t\20 Skill 3: %s \tDamamge/hit: %d", (*a).heroes[i].skill[2].skillName, a->heroes[i].skill[2].hits);
  143. printf("\n------------------------------------------------\n\n");
  144. }
  145.  
  146.  
  147. printf("Number of Hero(es): %d\n\n\n", i);
  148. system("pause");
  149. system("cls");
  150. }
  151. void game(heroListType *hero, int input){
  152. char ans;
  153. int ip, x;
  154. printf("Pick The Hero of Your Choice:\n");
  155. for(x=0;x<hero->noOfHeroes;x++){
  156.  
  157. printf("%d.) %s\n", x+1, (*hero).heroes[x].name);
  158. }
  159. printf("\nNumber of hero you want to play.");
  160. printf("\nEnter number: ");
  161. scanf("%d", &ip);
  162. printf("\n\n\nLET THE GAMES BEGIN!\n");
  163. printf("May the odds be in your favor! \27\n\n\n\n\n\n");
  164. system("pause");
  165. system("cls");
  166.  
  167. if((*hero).heroes[ip-1].level==1){
  168. fflush(stdin);
  169. printf("\nThis Game is called Dungeon Tralse Level 1. \n1 correct answer is equivalent to 1 XP, so if you get 5 XP your level will increase and the game will also become more harder. Good Luck and God Bless! :). ");
  170. printf("\nT-True and F-False\n\n");
  171. printf("Is Marcelo H Del Pillar is one of the colleague of Jose Rizal? ");
  172. printf("\n \20 ");
  173. scanf("%c", &ans);
  174. system("cls");
  175. if(ans=='T' || ans=='t'){
  176. (*hero).heroes[ip-1].exp++;
  177. }
  178. fflush(stdin);
  179. printf("T-True and F-False\n\n");
  180. printf("\n\nDo we need water? ");
  181. printf("\n \20 ");
  182. scanf("%c", &ans);
  183. system("cls");
  184. if(ans=='T' || ans=='t'){
  185. (*hero).heroes[ip-1].exp++;
  186. }
  187. fflush(stdin);
  188. printf("T-True and F-False\n\n");
  189. printf("\n\n\nA triangle has 59 sides. ");
  190. printf("\n \20 ");
  191. scanf("%c", &ans);
  192. system("cls");
  193.  
  194. if(ans=='f' || ans=='F'){
  195. (*hero).heroes[ip-1].exp++;
  196. }
  197.  
  198. }else if((*hero).heroes[ip-1].level==2){
  199.  
  200. fflush(stdin);
  201. printf("\nDo you think that justin bieber is GAY?Y/N: ");
  202. scanf("%c", &ans);
  203. if(ans=='Y' || ans == 'y')
  204. (*hero).heroes[ip-1].exp++;
  205. printf("\nCorrect!");
  206. fflush(stdin);
  207. printf("\nDo you think that justin bieber is GAY?Y/N: ");
  208. scanf("%c", &ans);
  209. if(ans=='Y' || ans == 'y'){
  210. (*hero).heroes[ip-1].exp++;
  211. printf("\nCorrect!");
  212. }
  213.  
  214. fflush(stdin);
  215. printf("\nDo you think that justin bieber is GAY?Y/N: ");
  216. scanf("%c", &ans);
  217. if(ans=='Y' || ans == 'y'){
  218. (*hero).heroes[ip-1].exp++;
  219. printf("\nCorrect!");
  220. }
  221.  
  222. }else if((*hero).heroes[ip-1].level==3){
  223.  
  224. fflush(stdin);
  225. printf("\nWho is our current President? \na.)Noynoy Aquino \tb.)Gloria Arroyo \tc.)Manny Villar\n");
  226. scanf("%c", &ans);
  227. if(ans=='a' || ans == 'A'){
  228. (*hero).heroes[ip-1].exp++;
  229. printf("\nCorrect!");
  230. }else if(ans!='a'||ans!='A'){
  231. printf("\nIncorrect!");
  232. }
  233. fflush(stdin);
  234. printf("\nWho is the National Hero of the Philippines? \na.)D. Jusi Rezal \tb.)Dr. Jose Rizal \tc.)Dr. Jericho Rosales\n ");
  235. scanf("%c", &ans);
  236. if(ans=='b' || ans == 'B'){
  237. (*hero).heroes[ip-1].exp++;
  238. printf("\nCorrect!");
  239. }
  240. else if(ans!='b'||ans!='B'){
  241. printf("\nIncorrect!");
  242. }
  243.  
  244. fflush(stdin);
  245. printf("\nWhich of the following doesnt fit in?\n a.)Volcano \tb.)Sea \tc.)city\n ");
  246. scanf("%c", &ans);
  247. if(ans=='C' || ans == 'c'){
  248. (*hero).heroes[ip-1].exp++;
  249. printf("\nCorrect!");
  250. }
  251. else if(ans!='c'||ans!='c'){
  252. printf("\nIncorrect!");
  253. }
  254.  
  255. }
  256.  
  257.  
  258. printf("You Gained: %d", (*hero).heroes[ip-1].exp);
  259. if((*hero).heroes[ip-1].exp>=5){
  260. fflush(stdin);
  261. 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);
  262. scanf("%c", &ans);
  263. if(ans == 'y' || ans == 'Y'){
  264. (*hero).heroes[ip-1].level=levelUp(hero);
  265. }else if(ans == 'n'|| ans == 'N'){
  266. printf("Okay.");
  267. }
  268. }
  269. }
  270. int levelUp(heroListType *hero){
  271. int i;
  272. for(i=0;i<3;i++){
  273.  
  274. if((*hero).heroes[i].exp>=5){
  275. hero->heroes[i].level+=1;
  276. hero->heroes[i].exp-=5;
  277. }
  278. if(hero->heroes[i].level==2){
  279. fflush(stdin);
  280.  
  281. printf("Enter 1st skill: ");
  282. gets(hero->heroes[i].skill[0].skillName);
  283. do{
  284. printf("\nHits (30-60/hit): ");
  285. scanf("%d", &hero->heroes[i].skill[0].hits);
  286. fflush(stdin);
  287. if(hero->heroes[i].skill[0].hits<30||hero->heroes[i].skill[0].hits>60){
  288. printf("Invalid Input, Please Try Again!\n");
  289. }else{
  290. printf("Successfully Added!\n");
  291. }
  292. }while(hero->heroes[i].skill[0].hits<30||hero->heroes[i].skill[0].hits>60);
  293. system("pause");
  294. system("cls");
  295. }else if(hero->heroes[i].level==3){
  296. fflush(stdin);
  297.  
  298. printf("Enter 2nd skill: ");
  299. gets(hero->heroes[i].skill[1].skillName);
  300.  
  301. printf("\nHits (61-80/hit): ");
  302. scanf("%d", &hero->heroes[i].skill[1].hits);
  303. do{
  304. if(hero->heroes[i].skill[0].hits<61||hero->heroes[i].skill[0].hits>80){
  305. printf("Invalid Input, Please Try Again!\n");
  306. }else{
  307. printf("Successfully Added!\n");
  308. }
  309. }while(hero->heroes[i].skill[0].hits<61||hero->heroes[i].skill[0].hits>80);
  310. system("pause");
  311. system("cls");
  312.  
  313. }else if(hero->heroes[i].level==4){
  314. fflush(stdin);
  315.  
  316. printf("Enter 3rd skill: ");
  317. gets(hero->heroes[i].skill[2].skillName);
  318.  
  319. printf("\nHits (81-100/hit): ");
  320. scanf("%d", &hero->heroes[i].skill[2].hits);
  321. do{
  322. if(hero->heroes[i].skill[0].hits<81||hero->heroes[i].skill[0].hits>100){
  323. printf("Invalid Input, Please Try Again!\n");
  324. }else{
  325. printf("Successfully Added!\n");
  326. }
  327. }while(hero->heroes[i].skill[0].hits<81||hero->heroes[i].skill[0].hits>100);
  328. system("pause");
  329. system("cls");
  330. }
  331. return hero->heroes[i].level;
  332. }
  333. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement