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 hL{
- heroType heroes[5];
- int noOfHeroes;
- }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);
- 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");
- }else{
- printf("\nERROR! CANNOT ADD ANYMORE\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");
- }else{
- printf("\nERROR! HERO NOT FOUND\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 Thanks 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[0].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("\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! :). ");
- printf("\nT-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);
- system("cls");
- if(ans=='T' || ans=='t'){
- (*hero).heroes[ip-1].exp++;
- }
- fflush(stdin);
- printf("T-True and F-False\n\n");
- printf("\n\nDo we need water? ");
- printf("\n \20 ");
- scanf("%c", &ans);
- system("cls");
- if(ans=='T' || ans=='t'){
- (*hero).heroes[ip-1].exp++;
- }
- fflush(stdin);
- printf("T-True and F-False\n\n");
- printf("\n\n\nA triangle has 59 sides. ");
- printf("\n \20 ");
- scanf("%c", &ans);
- system("cls");
- if(ans=='f' || ans=='F'){
- (*hero).heroes[ip-1].exp++;
- }
- }else if((*hero).heroes[ip-1].level==2){
- fflush(stdin);
- printf("\nDo you think that justin bieber is GAY?Y/N: ");
- scanf("%c", &ans);
- if(ans=='Y' || ans == 'y')
- (*hero).heroes[ip-1].exp++;
- printf("\nCorrect!");
- fflush(stdin);
- printf("\nDo you think that justin bieber is GAY?Y/N: ");
- scanf("%c", &ans);
- if(ans=='Y' || ans == 'y'){
- (*hero).heroes[ip-1].exp++;
- printf("\nCorrect!");
- }
- fflush(stdin);
- printf("\nDo you think that justin bieber is GAY?Y/N: ");
- scanf("%c", &ans);
- if(ans=='Y' || ans == 'y'){
- (*hero).heroes[ip-1].exp++;
- printf("\nCorrect!");
- }
- }else if((*hero).heroes[ip-1].level==3){
- fflush(stdin);
- printf("\nWho is our current President? \na.)Noynoy Aquino \tb.)Gloria Arroyo \tc.)Manny Villar\n");
- 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 ");
- 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 ");
- scanf("%c", &ans);
- if(ans=='C' || ans == 'c'){
- (*hero).heroes[ip-1].exp++;
- printf("\nCorrect!");
- }
- else if(ans!='c'||ans!='c'){
- printf("\nIncorrect!");
- }
- }
- printf("You 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.");
- }
- }
- }
- 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;
- }
- 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");
- }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[0].hits<61||hero->heroes[i].skill[0].hits>80){
- printf("Invalid Input, Please Try Again!\n");
- }else{
- printf("Successfully Added!\n");
- }
- }while(hero->heroes[i].skill[0].hits<61||hero->heroes[i].skill[0].hits>80);
- system("pause");
- system("cls");
- }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[0].hits<81||hero->heroes[i].skill[0].hits>100){
- printf("Invalid Input, Please Try Again!\n");
- }else{
- printf("Successfully Added!\n");
- }
- }while(hero->heroes[i].skill[0].hits<81||hero->heroes[i].skill[0].hits>100);
- system("pause");
- system("cls");
- }
- return hero->heroes[i].level;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement