Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
- #include<stdlib.h>
- typedef struct skill{
- char skillName[30];
- int hits;
- }skillType;
- typedef struct hero{
- char name[10];
- skillType skill[3];
- int level;
- int exp;
- }heroType;
- typedef struct{
- int value, found;
- }cardType;
- typedef struct hL{
- heroType heroes[5];
- int noOfHeroes;
- cardType card[10];
- }heroListType;
- int insertFirst(heroListType *a, char nameHero[]);
- int deleteHero(char nameHero[],heroListType *b);
- void display(heroListType *a);
- void game(heroListType *hero, int);
- int levelUp(heroListType *hero);
- void memoryGame(heroListType *hero);
- void memoryFill(heroListType *hero);
- void memoryGuess(heroListType *hero);
- int memoryPlay(heroListType *hero);
- int main(void)
- {
- heroListType hero;
- char aName[10],xName[10],choice;
- int i, ip;
- hero.noOfHeroes=0;
- printf("\n\n\n\n\n\n\t\t\t \20\20\20TRALSE DUNGEONEERING\21\21\21\n\n\n");
- printf(" \t\t\t\tby: Toneyap\n\n\n");
- printf("\t\t\t");
- system("pause");
- system("cls");
- do{
- printf("\n\n\n________________________________________________________________________________");
- 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");
- printf("\n________________________________________________________________________________");
- printf("CHOOSE YOUR LETTER: ");
- scanf("%c",&choice);
- fflush(stdin);
- printf("\n");
- system("cls");
- if(choice=='A'||choice=='a'){
- printf("\nEnter name: ");
- fflush(stdin);
- gets(aName);
- if(insertFirst(&hero, aName)==0){
- printf("\nHERO WAS ADDED!\n\n");
- }else{
- printf("\nERROR! CANNOT ADD ANYMORE\n\n");
- }
- system("pause");
- system("cls");
- }else if(choice=='d'||choice=='D'){
- printf("Enter name:");
- fflush(stdin);
- gets(xName);
- if(deleteHero(xName,&hero)==0){
- printf("\nHERO WAS DELETED!\n\n");
- }else{
- printf("\nERROR! HERO NOT FOUND\n\n");
- }
- }else if(choice=='I'||choice=='i'){
- display(&hero);
- }else if(choice=='s' || choice=='S'){
- game(&hero, ip);
- }else if(choice=='E' || choice=='e'){
- printf("\n\n\n\n\t\t Thank you! Please use our program again. \n\n\n\n\n");
- return 0;
- }
- }while(choice!='E' || choice!='e');
- getch ();
- return 0;
- }
- int insertFirst(heroListType *a, char nameHero[])
- {
- int ret=0, i,x;
- if (((*a).noOfHeroes)== 5){
- printf("ERROR! cannot insert anymore\n");
- ret=1;
- }else{
- for(i=0; i<(*a).noOfHeroes; i++){
- (*a).heroes[(*a).noOfHeroes+i]=(*a).heroes[i];
- }
- }
- strcpy((*a).heroes[i].name, nameHero);
- (*a).heroes[0].exp=0;
- (*a).heroes[0].level=1;
- (*a).noOfHeroes+=1;
- for(x=0; x<3;x++){
- (*a).heroes[i].skill[x].hits=0;
- }
- //(*a).heroes[0].skill[1].hits=0;
- //(*a).heroes[0].skill[2].hits=0;
- for(x=0; x<3;x++){
- strcpy((*a).heroes[i].skill[x].skillName, "");
- }
- //strcpy((*a).heroes[i].skill[1].skillName, "");
- //strcpy((*a).heroes[i].skill[2].skillName, "");
- return ret;
- }
- int deleteHero(char nameHero[],heroListType *b){
- int ret=1,i,j,x=-1;
- for(i=0;i<((*b).noOfHeroes);i++){
- if(strcmp((*b).heroes[i].name,nameHero)==0){
- x=i;
- ret=0;
- }}
- if(x!=-1){
- for(j=x;j<((*b).noOfHeroes);j++){
- ((*b).heroes[x])=((*b).heroes[x+1]);
- }
- (*b).noOfHeroes-=1;
- }else{
- printf("Error!\n");
- }
- return ret;
- }
- void display(heroListType *a)
- {
- int i,j;
- for(i=0;i<((*a).noOfHeroes);i++)
- {
- printf("---------------Hero %d INFORMATION---------------\n",i+1);
- printf("\n\t\20 Name: ");
- printf("%s", (*a).heroes[i].name);
- printf("\n\t\20 Your XP: %d", (*a).heroes[i].exp);
- printf("\n\t\20 Hero LVL: %d", (*a).heroes[i].level);
- printf("\n\t\20 Skill 1: %s \tDamamge/hit: %d", (*a).heroes[i].skill[0].skillName, a->heroes[i].skill[0].hits);
- printf("\n\t\20 Skill 2: %s \tDamamge/hit: %d", (*a).heroes[i].skill[1].skillName, a->heroes[i].skill[1].hits);
- printf("\n\t\20 Skill 3: %s \tDamamge/hit: %d", (*a).heroes[i].skill[2].skillName, a->heroes[i].skill[2].hits);
- printf("\n------------------------------------------------\n\n");
- }
- printf("Number of Hero(es): %d\n\n\n", i);
- system("pause");
- system("cls");
- }
- void game(heroListType *hero, int input){
- char ans;
- int ip, x;
- printf("Pick The Hero of Your Choice:\n");
- for(x=0;x<hero->noOfHeroes;x++){
- printf("%d.) %s\n", x+1, (*hero).heroes[x].name);
- }
- printf("\nNumber of hero you want to play.");
- printf("\nEnter number: ");
- scanf("%d", &ip);
- printf("\n\n\nLET THE GAMES BEGIN!\n");
- printf("May the odds be in your favor! \27\n\n\n\n\n\n");
- system("pause");
- system("cls");
- if((*hero).heroes[ip-1].level==1){
- fflush(stdin);
- 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! :). ");
- printf("\n\n\t\t\t");
- system("pause");
- system("cls");;
- printf("\n\t\t\tDungeon Tralse Level 1");
- printf("\n\t\t\t");
- system("pause");
- system("cls");
- printf("\n\t\t\tT-True and F-False\n\n");
- printf("Is Marcelo H Del Pillar is one of the colleague of Jose Rizal? ");
- printf("\n \20 ");
- scanf("%c", &ans);
- if(ans=='T' || ans=='t'){
- (*hero).heroes[ip-1].exp++;
- }
- fflush(stdin);
- printf("\nDo we need water? ");
- printf("\n \20 ");
- scanf("%c", &ans);
- if(ans=='T' || ans=='t'){
- (*hero).heroes[ip-1].exp++;
- }
- fflush(stdin);
- printf("\nA triangle has 59 sides. ");
- printf("\n \20 ");
- scanf("%c", &ans);
- if(ans=='f' || ans=='F'){
- (*hero).heroes[ip-1].exp++;
- }
- // lvl 2
- }else if((*hero).heroes[ip-1].level==2){
- printf("\n\t\t\tDungeon Tralse Level 2");
- fflush(stdin);
- printf("\nIs Console better than PC?Y/N: \n");
- printf("\32");
- scanf("%c", &ans);
- if(ans=='N' || ans == 'n'){
- (*hero).heroes[ip-1].exp++;
- printf("\nCorrect!");
- }else if (ans == 'Y' || ans == 'y'){
- printf("\nWrong!");
- }
- fflush(stdin);
- printf("\nIs Tomato a fruit?Y/N: \n");
- printf("\32");
- scanf("%c", &ans);
- if(ans=='Y' || ans == 'y'){
- (*hero).heroes[ip-1].exp++;
- printf("\nCorrect!");
- }else if (ans == 'N' || ans == 'n'){
- printf("\nWrong!");
- }
- fflush(stdin);
- printf("\nAre you happy?Y/N: \n");
- printf("\32");
- scanf("%c", &ans);
- if(ans=='N' || ans == 'n'){
- (*hero).heroes[ip-1].exp++;
- printf("\nCorrect!");
- }else if (ans == 'Y' || ans == 'y'){
- printf("\nWrong!");
- }
- // lvl 3
- }else if((*hero).heroes[ip-1].level==3){
- printf("\n\t\t\tDungeon Tralse Level 3");
- fflush(stdin);
- printf("\nWho is our current President? \na.)Noynoy Aquino \tb.)Gloria Arroyo \tc.)Manny Villar\n");
- printf("\32");
- scanf("%c", &ans);
- if(ans=='a' || ans == 'A'){
- (*hero).heroes[ip-1].exp++;
- printf("\nCorrect!");
- }else if(ans!='a'||ans!='A'){
- printf("\nIncorrect!");
- }
- fflush(stdin);
- printf("\nWho is the National Hero of the Philippines? \na.)D. Jusi Rezal \tb.)Dr. Jose Rizal \tc.)Dr. Jericho Rosales\n ");
- printf("\32");
- scanf("%c", &ans);
- if(ans=='b' || ans == 'B'){
- (*hero).heroes[ip-1].exp++;
- printf("\nCorrect!");
- }
- else if(ans!='b'||ans!='B'){
- printf("\nIncorrect!");
- }
- fflush(stdin);
- printf("\nWhich of the following doesnt fit in?\n a.)Volcano \tb.)Sea \tc.)city\n ");
- printf("\32");
- scanf("%c", &ans);
- if(ans=='C' || ans == 'c'){
- (*hero).heroes[ip-1].exp++;
- printf("\nCorrect!");
- }
- else if(ans!='c'||ans!='c'){
- printf("\nIncorrect!");
- }
- // lvl 4
- }else if((*hero).heroes[ip-1].level==4){
- printf("\n\t\t\tDungeon Tralse Level 4");
- fflush(stdin);
- printf("\nUnsang lugara sa Cebu nga mamadlong? \na.)Mambaling \tb.)Mandaue \tc.)Badian\n");
- printf("\32");
- scanf("%c", &ans);
- if(ans=='c' || ans == 'c'){
- (*hero).heroes[ip-1].exp++;
- printf("\nCorrect!");
- }else if(ans!='a'||ans!='A'){
- printf("\nIncorrect!");
- }
- fflush(stdin);
- printf("\nUnsang lugara sa Cebu nga switch? \na.)Moalboal \tb.)Opon \tc.)Carmen\n");
- printf("\32");
- scanf("%c", &ans);
- if(ans=='c' || ans == 'c'){
- (*hero).heroes[ip-1].exp++;
- printf("\nCorrect!");
- }else if(ans!='a'||ans!='A'){
- printf("\nIncorrect!");
- }
- fflush(stdin);
- printf("\nKung ang lain og batasan kay bati ang walay batasan? \na.)Masbate \tb.)Bohol \tc.)Davao\n");
- printf("\32");
- scanf("%c", &ans);
- if(ans=='a' || ans == 'A'){
- (*hero).heroes[ip-1].exp++;
- printf("\nCorrect!");
- }else if(ans!='a'||ans!='A'){
- printf("\nIncorrect!");
- }
- // lvl 5
- }else if((*hero).heroes[ip-1].level==5){
- printf("\n\t\t\tDungeon Tralse Level 5");
- printf("\n\nWarning: Enter at your own risk\nContinue? Y/N: ");
- scanf("%c", &ans);
- if(ans == 'y' || ans == 'Y'){
- memoryGame(hero);
- } else if(ans == 'n' || ans == 'N'){
- printf("Nice choice.");
- }
- fflush(stdin);
- }
- printf("\n\nYou Gained: %d", (*hero).heroes[ip-1].exp);
- if((*hero).heroes[ip-1].exp>=5){
- fflush(stdin);
- 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);
- scanf("%c", &ans);
- if(ans == 'y' || ans == 'Y'){
- (*hero).heroes[ip-1].level=levelUp(hero);
- }else if(ans == 'n'|| ans == 'N'){
- printf("Okay.");
- }
- }
- }
- void memoryGame(heroListType *hero){
- int ret;
- printf("Right - Wrong");
- do{
- memoryFill(hero);
- printf("\n\n");
- memoryGuess(hero);
- printf("\n\n");
- memoryPlay(hero);
- }while(ret!=10);
- }
- void memoryFill(heroListType *hero){
- hero->card[0].value = 7;
- hero->card[1].value = 4;
- hero->card[2].value = 3;
- hero->card[3].value = 9;
- hero->card[4].value = 6;
- hero->card[5].value = 7;
- hero->card[6].value = 6;
- hero->card[7].value = 9;
- hero->card[8].value = 3;
- hero->card[9].value = 4;
- }
- void memoryGuess(heroListType *hero){
- int i, correct = 0;
- for(i=0;i<10;i++){
- if(hero->card[i].found == 1){
- printf("%d ", hero->card[i].value);
- correct++;
- } else {
- printf("* ");
- }
- }
- }
- int memoryPlay(heroListType *hero){
- int one, two, i;
- printf("Guess first position <1-10>: ");
- scanf("%d", &one+1);
- printf("Guess second position <1-10>: ");
- scanf("%d", &two+1);
- if(hero->card[one].value == hero->card[two].value){
- hero->card[one].found = 1;
- hero->card[two].found = 1;
- return i+=2;
- }
- }
- int levelUp(heroListType *hero){
- int i;
- for(i=0;i<3;i++){
- if((*hero).heroes[i].exp>=5){
- hero->heroes[i].level+=1;
- hero->heroes[i].exp-=5;
- }
- // 1st skill
- if(hero->heroes[i].level==2){
- fflush(stdin);
- printf("Enter 1st skill: ");
- gets(hero->heroes[i].skill[0].skillName);
- do{
- printf("\nHits (30-60/hit): ");
- scanf("%d", &hero->heroes[i].skill[0].hits);
- fflush(stdin);
- if(hero->heroes[i].skill[0].hits<30||hero->heroes[i].skill[0].hits>60){
- printf("Invalid Input, Please Try Again!\n");
- }else{
- printf("Successfully Added!\n");
- }
- }while(hero->heroes[i].skill[0].hits<30||hero->heroes[i].skill[0].hits>60);
- system("pause");
- system("cls");
- // 2nd skill
- }else if(hero->heroes[i].level==3){
- fflush(stdin);
- printf("Enter 2nd skill: ");
- gets(hero->heroes[i].skill[1].skillName);
- printf("\nHits (61-80/hit): ");
- scanf("%d", &hero->heroes[i].skill[1].hits);
- do{
- if(hero->heroes[i].skill[1].hits<61||hero->heroes[i].skill[1].hits>80){
- printf("Invalid Input, Please Try Again!\n");
- }else{
- printf("Successfully Added!\n");
- }
- }while(hero->heroes[i].skill[1].hits<61||hero->heroes[i].skill[1].hits>80);
- system("pause");
- system("cls");
- // 3rd skill
- }else if(hero->heroes[i].level==4){
- fflush(stdin);
- printf("Enter 3rd skill: ");
- gets(hero->heroes[i].skill[2].skillName);
- printf("\nHits (81-100/hit): ");
- scanf("%d", &hero->heroes[i].skill[2].hits);
- do{
- if(hero->heroes[i].skill[2].hits<81||hero->heroes[i].skill[2].hits>100){
- printf("Invalid Input, Please Try Again!\n");
- }else{
- printf("Successfully Added!\n");
- }
- }while(hero->heroes[i].skill[2].hits<81||hero->heroes[i].skill[2].hits>100);
- system("pause");
- system("cls");
- }
- return hero->heroes[i].level;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement