Advertisement
PROFESSOR_AIH

Quiz Game

Jul 3rd, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 27.67 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<conio.h>
  4. #include<windows.h>
  5. #include<time.h>
  6. void Game();
  7. void highestscore();
  8. void rules();
  9. void Search();
  10. void developerinfo();
  11. void easy();
  12. void medium();
  13. void hard();
  14. void easygame();
  15. void mediumgame();
  16. void hardgame();
  17. void tnks();
  18. void Exit();
  19. void result();
  20. struct PlayerInfo
  21. {
  22.     char name[255];
  23.     int score;
  24.     char level[20];
  25. } player[1000];
  26. void gotoxy(int a,int b)
  27. {
  28.     COORD c;
  29.     c.X = a;
  30.     c.Y = b;
  31.  
  32.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
  33. }
  34. void border()
  35. {
  36.     Sleep(50);
  37.     for(int i=0;i<122;i+=2)
  38.     {
  39.         gotoxy(0+i,0);
  40.  
  41.         printf("\xDB");
  42.         gotoxy(0+i,30);
  43.  
  44.         printf("\xDB");
  45.     }
  46.  
  47.     for(int i=0;i<30;i+=2)
  48.     {
  49.         gotoxy(0,2+i);
  50.  
  51.         printf("\xDB");
  52.         gotoxy(120,2+i);
  53.  
  54.         printf("\xDB");
  55.     }
  56. }
  57. void color()
  58. {
  59.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),6);
  60. }
  61. void addquiz()
  62. {
  63.  
  64.     system("cls");
  65.     border();
  66.     gotoxy(45,7);
  67.     printf("> Add Easy Quiz");
  68.     gotoxy(45,8);
  69.     printf("> Add Medium Quiz");
  70.     gotoxy(45,9);
  71.     printf("> Add Hard Quiz");
  72.     gotoxy(45,16);
  73.     int n;
  74.     printf("Select Your Option ");
  75. go:
  76.     scanf("%d",&n);
  77.     switch(n)
  78.     {
  79.     case 1:
  80.         easy();
  81.         break;
  82.     case 2:
  83.         medium();
  84.         break;
  85.     case 3:
  86.         hard();
  87.         break;
  88.     default:
  89.     {
  90.         gotoxy(45,18);
  91.         printf("Invalid Selection.Please Re-Select Your Option ");
  92.         goto go;
  93.     }
  94.  
  95.     }
  96. }
  97. void menu()
  98. {
  99.     system("cls");
  100.     border();
  101.     for(int i=0;i<17;i++)
  102.     {
  103.         gotoxy(48+i,3);
  104.         Sleep(10);
  105.         printf("\xDB");
  106.         gotoxy(48+i,5);
  107.         Sleep(10);
  108.         printf("\xDB");
  109.     }
  110.     gotoxy(48,4);
  111.     Sleep(10);
  112.     printf("\xDB");
  113.     gotoxy(64,4);
  114.     Sleep(10);
  115.     printf("\xDB");
  116.  
  117.     gotoxy(50,4);
  118.     Sleep(10);
  119.     printf("*BE The Best*");
  120.     gotoxy(18,7);
  121.     printf("> 1.Start Game");
  122.     gotoxy(18,8);
  123.     printf("> 2.Highest Scores");
  124.     gotoxy(18,9);
  125.     printf("> 3.Rules & Regulations");
  126.     gotoxy(18,10);
  127.     printf("> 4.Add Quiz");
  128.     gotoxy(18,11);
  129.     printf("> 5.Result Search");
  130.     gotoxy(18,12);
  131.     printf("> 6.Developer Information");
  132.     gotoxy(18,13);
  133.     printf("> 7.Exit");
  134.     gotoxy(47,20);
  135.     printf("Select Your Option ");
  136.     int n;
  137.     scanf("%d",&n);
  138. again:
  139.     switch(n)
  140.     {
  141.     case 1:
  142.         Game();
  143.         break;
  144.     case 2:
  145.         highestscore();
  146.         break;
  147.     case 3:
  148.         rules();
  149.         break;
  150.     case 4:
  151.         addquiz();
  152.         break;
  153.     case 5:
  154.         Search();
  155.         break;
  156.     case 6:
  157.         developerinfo();
  158.         break;
  159.     case 7:
  160.         Exit();
  161.         break;
  162.     default:
  163.     {
  164.         gotoxy(47,22);
  165.         printf("Invalid Selection.Please Re-Select Your Option ");
  166.         scanf("%d",&n);
  167.         goto again;
  168.     }
  169.     }
  170.  
  171. }
  172. void intro()
  173. {
  174.     border();
  175.     for(int i=0;i<17;i+=2)
  176.     {
  177.         gotoxy(45+i,4);
  178.         Sleep(10);
  179.         printf("\xDB");
  180.         gotoxy(45+i,10);
  181.         Sleep(10);
  182.         printf("\xDB");
  183.     }
  184.     for(int i=0;i<7;i+=2)
  185.     {
  186.         gotoxy(45,4+i);
  187.         Sleep(10);
  188.         printf("\xDB");
  189.     }
  190.     for(int i=0;i<5;i+=2)
  191.     {
  192.         gotoxy(61,6+i);
  193.         Sleep(10);
  194.         printf("\xDB");
  195.     }
  196.     gotoxy(50,5);
  197.     Sleep(10);
  198.     printf("Welcome");
  199.     gotoxy(52,7);
  200.     Sleep(10);
  201.     printf("To");
  202.     gotoxy(49,9);
  203.     Sleep(10);
  204.     printf("Quiz Game");
  205.     gotoxy(5,28);
  206.     Sleep(10);
  207.     printf("*Developed By NULL_STUNNERS");
  208.     gotoxy(34,16);
  209.     Sleep(10);
  210.     printf("Please Enter Any key To Show Main Menu ");
  211.     getchar();
  212.     menu();
  213. }
  214. int main()
  215. {
  216.     color();
  217.     intro();
  218.     getch();
  219. }
  220. void easy()
  221. {
  222.     system("cls");
  223.     border();
  224.     FILE *game;
  225.  
  226.     game=fopen("easyquiz.text","a");
  227.     gotoxy(10,3);
  228.     printf("Enter Your Question Below:\n");
  229.     gotoxy(10,5);
  230.     getchar();
  231.     char easyquiz[100][200];
  232.     gets(easyquiz[0]);
  233.     fprintf(game,"%s\n",easyquiz[0]);
  234.     fclose(game);
  235.  
  236.     game=fopen("easyoption.text","a");
  237.     gotoxy(10,7);
  238.     printf("Enter Quiz Options Below:\n");
  239.     char easyopt[4][100];
  240.     for(int i=0; i<4; i++)
  241.     {
  242.         gotoxy(10,9+i);
  243.         gets(easyopt[i]);
  244.         fprintf(game,"%s\n",easyopt[i]);
  245.     }
  246.     fclose(game);
  247.  
  248.     game=fopen("easyanswer.text","a");
  249.     gotoxy(10,15);
  250.     printf("Enter Quiz Answer Below:\n");
  251.     char ans[1];
  252.     gotoxy(10,16);
  253.     scanf("%c",&ans[0]);
  254.     fprintf(game,"%c",ans[0]);
  255.     fclose(game);
  256.     getchar();
  257.     tnks();
  258. }
  259. void medium()
  260. {
  261.     system("cls");
  262.     border();
  263.     FILE *game;
  264.  
  265.     game=fopen("mediumquiz.text","a");
  266.     gotoxy(10,3);
  267.     printf("Enter Your Question Below:\n");
  268.     gotoxy(10,5);
  269.     getchar();
  270.     char mediumquiz[100][200];
  271.     gets(mediumquiz[0]);
  272.     fprintf(game,"%s\n",mediumquiz[0]);
  273.     fclose(game);
  274.  
  275.     game=fopen("mediumoption.text","a");
  276.     gotoxy(10,7);
  277.     printf("Enter Quiz Options Below:\n");
  278.     char mediumopt[4][100];
  279.     for(int i=0; i<4; i++)
  280.     {
  281.         gotoxy(10,9+i);
  282.         gets(mediumopt[i]);
  283.         fprintf(game,"%s\n",mediumopt[i]);
  284.     }
  285.     fclose(game);
  286.  
  287.     game=fopen("mediumanswer.text","a");
  288.     gotoxy(10,15);
  289.     printf("Enter Quiz Answer Below:\n");
  290.     char ans[1];
  291.     gotoxy(10,16);
  292.     scanf("%c",&ans[0]);
  293.     fprintf(game,"%c",ans[0]);
  294.     fclose(game);
  295.     getchar();
  296.     tnks();
  297. }
  298. void hard()
  299. {
  300.     system("cls");
  301.     border();
  302.     FILE *game;
  303.  
  304.     game=fopen("hardquiz.text","a");
  305.     gotoxy(10,3);
  306.     printf("Enter Your Question Below:\n");
  307.     gotoxy(10,5);
  308.     getchar();
  309.     char hardquiz[100][200];
  310.     gets(hardquiz[0]);
  311.     fprintf(game,"%s\n",hardquiz[0]);
  312.     fclose(game);
  313.  
  314.     game=fopen("hardoption.text","a");
  315.     gotoxy(10,7);
  316.     printf("Enter Quiz Options Below:\n");
  317.     char hardopt[4][100];
  318.     for(int i=0; i<4; i++)
  319.     {
  320.         gotoxy(10,9+i);
  321.         gets(hardopt[i]);
  322.         fprintf(game,"%s\n",hardopt[i]);
  323.     }
  324.     fclose(game);
  325.  
  326.     game=fopen("hardanswer.text","a");
  327.     gotoxy(10,15);
  328.     printf("Enter Quiz Answer Below:\n");
  329.     char ans[1];
  330.     gotoxy(10,16);
  331.     scanf("%c",&ans[0]);
  332.     fprintf(game,"%c",ans[0]);
  333.     fclose(game);
  334.     getchar();
  335.     tnks();
  336. }
  337. void rules()
  338. {
  339.     system("cls");
  340.     border();
  341.     gotoxy(45,2);
  342.     printf("\"Rules & Regulation\"");
  343.     for(int i=0;i<20;i++)
  344.     {
  345.       gotoxy(45+i,3);
  346.       printf("-");
  347.     }
  348.     gotoxy(22,5);
  349.     printf("1. The Quiz Game is about Basic C Programming.");
  350.     gotoxy(22,7);
  351.     printf("2. There are 10 questions in each difficulty level.");
  352.     gotoxy(22,9);
  353.     printf("3. Each Correct answer will increase the participant score by 1.");
  354.     gotoxy(22,11);
  355.     printf("4. The wrong answers will not reduce any points.");
  356.     gotoxy(22,13);
  357.     printf("5. There will be only one question at a time.");
  358.     gotoxy(22,15);
  359.     printf("6.There are 3 Difficulty Levels - Easy, Medium, Hard.");
  360.     gotoxy(22,17);
  361.     printf("7.You Can Choose Any Of them.");
  362.     gotoxy(22,19);
  363.     printf("8.After Answer a question wait 2 sec for a new question to see.");
  364.     getchar();
  365.     gotoxy(43,26);
  366.     printf("Enter Any Key To Go Back ");
  367.     getchar();
  368.     menu();
  369. }
  370. void tnks()
  371. {
  372.     system("cls");
  373.     border();
  374.     for(int i=0;i<27;i++)
  375.     {
  376.         gotoxy(45+i,9);
  377.         Sleep(5);
  378.         printf("\xDB");
  379.         gotoxy(45+i,14);
  380.         Sleep(5);
  381.         printf("\xDB");
  382.     }
  383.     for(int i=0;i<5;i++)
  384.     {
  385.         gotoxy(45,9+i);
  386.         Sleep(5);
  387.         printf("\xDB");
  388.     }
  389.     for(int i=0;i<5;i++)
  390.     {
  391.         gotoxy(71,9+i);
  392.         Sleep(5);
  393.         printf("\xDB");
  394.     }
  395.     gotoxy(47,11);
  396.     printf("Thanks For Contributing");
  397.     gotoxy(53,13);
  398.     printf("Happy Gaming");
  399.  
  400.     gotoxy(45,19);
  401.     printf("Enter Any Key to Go Main Menu ");
  402.     getchar();
  403.     menu();
  404. }
  405. void result(int score,char name[255],char status[255],char insname[255],int age)
  406. {
  407.     system("cls");
  408.     border();
  409.     gotoxy(1,3);
  410.     if(score>=8 && score<=10)
  411.     {
  412.         printf("\n\t\t\t\t\t\t ___________________\n");
  413.         printf("\t\t\t\t\t\t|                   |");
  414.         printf("\n\t\t\t\t\t\t| Congratulations!! |\n");
  415.         printf("\t\t\t\t\t\t|___________________|");
  416.         printf("\n\n\n\t\t\t\t\tParticipant Name: ");
  417.         puts(name);
  418.         printf("\t\t\t\t\tAge: %d\n",age);
  419.         printf("\t\t\t\t\tEducational Status : %s\n",status);
  420.         printf("\t\t\t\t\tInstitute name : %s\n",insname);
  421.         printf("\n\t\t\t\t\tFINAL SCORE : %d/10\n",score);
  422.         gotoxy(18,22);
  423.         printf("> Press 1 To go Game Level");
  424.         gotoxy(18,23);
  425.         printf("> Press 2 To go Main Menu");
  426.         gotoxy(18,24);
  427.         printf("> Press 3 To Exit");
  428.         gotoxy(18,25);
  429.         int n;
  430.         printf("Choose: ");
  431. level:
  432.         scanf("%d",&n);
  433.         switch(n)
  434.         {
  435.         case 1:
  436.             Game();
  437.             break;
  438.         case 2:
  439.             menu();
  440.             break;
  441.         case 3:
  442.             Exit();
  443.             break;
  444.         default:
  445.         {
  446.             gotoxy(18,27);
  447.             printf("Invalid Choose.Please Re-Choose: ");
  448.             goto level;
  449.         }
  450.         }
  451.     }
  452.     else if(score>=5 && score<8)
  453.     {
  454.         printf("\n\t\t\t\t\t\t _______________\n");
  455.         printf("\t\t\t\t\t\t|               |");
  456.         printf("\n\t\t\t\t\t\t|  Well Done!!  |\n");
  457.         printf("\t\t\t\t\t\t|_______________|");
  458.         printf("\n\n\n\t\t\t\t\tParticipant Name: ");
  459.         puts(name);
  460.         printf("\t\t\t\t\tAge: %d\n",age);
  461.         printf("\t\t\t\t\tEducational Status : %s\n",status);
  462.         printf("\t\t\t\t\tInstitute name : %s\n",insname);
  463.         printf("\n\t\t\t\t\tFINAL SCORE : %d/10\n",score);
  464.         gotoxy(18,22);
  465.         printf("> Press 1 To go Game Level");
  466.         gotoxy(18,23);
  467.         printf("> Press 2 To go Main Menu");
  468.         gotoxy(18,24);
  469.         printf("> Press 3 To Exit");
  470.         gotoxy(18,25);
  471.         int n;
  472.         printf("Choose: ");
  473. ki:
  474.         scanf("%d",&n);
  475.         switch(n)
  476.         {
  477.         case 1:
  478.             Game();
  479.             break;
  480.         case 2:
  481.             menu();
  482.             break;
  483.         case 3:
  484.             Exit();
  485.             break;
  486.         default:
  487.         {
  488.             gotoxy(18,27);
  489.             printf("Invalid Choose.Please Re-Choose: ");
  490.             goto ki;
  491.         }
  492.         }
  493.     }
  494.     else if(score>=0 && score<5)
  495.     {
  496.         printf("\n\t\t\t\t\t\t _____________\n");
  497.         printf("\t\t\t\t\t\t|             |");
  498.         printf("\n\t\t\t\t\t\t| Try Again!! |\n");
  499.         printf("\t\t\t\t\t\t|_____________|");
  500.         printf("\n\n\n\t\t\t\t\tParticipant Name: ");
  501.         puts(name);
  502.         printf("\t\t\t\t\tAge: %d\n",age);
  503.         printf("\t\t\t\t\tEducational Status : %s\n",status);
  504.         printf("\t\t\t\t\tInstitute name : %s\n",insname);
  505.         printf("\n\t\t\t\t\tFINAL SCORE : %d/10\n",score);
  506.         gotoxy(18,22);
  507.         printf("> Press 1 To go Game Level");
  508.         gotoxy(18,23);
  509.         printf("> Press 2 To go Main Menu");
  510.         gotoxy(18,24);
  511.         printf("> Press 3 To Exit");
  512.         gotoxy(18,25);
  513.         int n;
  514.         printf("Choose: ");
  515. li:
  516.         scanf("%d",&n);
  517.         switch(n)
  518.         {
  519.         case 1:
  520.             Game();
  521.             break;
  522.         case 2:
  523.             menu();
  524.             break;
  525.         case 3:
  526.             Exit();
  527.             break;
  528.         default:
  529.         {
  530.             gotoxy(18,27);
  531.             printf("Invalid Choose.Please Re-Choose: ");
  532.             goto li;
  533.         }
  534.         }
  535.     }
  536.  
  537. }
  538. void Game()
  539. {
  540.     system("cls");
  541.     border();
  542.     gotoxy(50,3);
  543.     printf("Game Levels");
  544.     for(int i=0;i<11;i++)
  545.     {
  546.         gotoxy(50+i,4);
  547.         printf("-");
  548.     }
  549.     gotoxy(24,5);
  550.     printf("> Easy Level.");
  551.     gotoxy(24,6);
  552.     printf("> Medium Level.");
  553.     gotoxy(24,7);
  554.     printf("> Hard Level.");
  555.     gotoxy(47,14);
  556.     printf("Choose Any level: ");
  557.     int n;
  558. level:
  559.     scanf("%d",&n);
  560.     switch(n)
  561.     {
  562.     case 1:
  563.         easygame();
  564.         break;
  565.     case 2:
  566.         mediumgame();
  567.         break;
  568.     case 3:
  569.         hardgame();
  570.         break;
  571.     default:
  572.     {
  573.         gotoxy(46,16);
  574.         printf("Invalid Choose.Please Re-Choose Game Level: ");
  575.         goto level;
  576.     }
  577.     }
  578. }
  579. void easygame()
  580. {
  581.     system("cls");
  582.     border();
  583.     char nm[255],stat[255],inst[255];
  584.     int ag;
  585.     gotoxy(47,3);
  586.     printf("Enter Below Info\n");
  587.     for(int i=0;i<16;i++)
  588.     {
  589.         gotoxy(47+i,4);
  590.         printf("-");
  591.     }
  592.     getchar();
  593.     gotoxy(25,5);
  594.     printf("User Name: ");
  595.     gets(nm);
  596.     gotoxy(25,6);
  597.     printf("Age: ");
  598.     scanf("%d",&ag);
  599.     gotoxy(25,7);
  600.     printf("Educational Status: ");
  601.     getchar();
  602.     gets(stat);
  603.     gotoxy(25,8);
  604.     printf("Institution: ");
  605.     gets(inst);
  606.  
  607.     FILE *game;
  608.  
  609.     game = fopen("search.text","a");
  610.     fprintf(game,"%s\n",nm);
  611.     fclose(game);
  612.  
  613.     game = fopen("level.text","a");
  614.     fprintf(game,"Easy\n");
  615.     fclose(game);
  616.     int i,j,count=0;
  617.     time_t t;
  618.     char quiz[300][200]= {};
  619.     char option[1200][100]= {};
  620.     char answer[300]= {};
  621.     game=fopen("easyquiz.text","r");
  622.     for(int i=0; ; i++)
  623.     {
  624.         if(fgets(quiz[i],200,game)!=NULL)
  625.             count++;
  626.         else
  627.             break;
  628.     }
  629.     fclose(game);
  630.     count=0;
  631.     game=fopen("easyoption.text","r");
  632.     for(i=0; ; i++)
  633.     {
  634.         if(fgets(option[i],100,game)!=NULL)
  635.             count++;
  636.         else
  637.             break;
  638.     }
  639.     fclose(game);
  640.     count=0;
  641.     game=fopen("easyanswer.text","r");
  642.     for(i=0; ; i++)
  643.     {
  644.         answer[i]=fgetc(game);
  645.         count++;
  646.         if(feof(game))
  647.             break ;
  648.     }
  649.     fclose(game);
  650.     count--;
  651.     srand(time(NULL));
  652.     system("cls");
  653.     border();
  654.     int scr=0;
  655.     int arr[count];
  656.     for(i=0; i<count; i++)
  657.     {
  658.         arr[i]=i;
  659.     }
  660.     int temp,z;
  661.     for(i=0; i<count; i++)
  662.     {
  663.         z=(rand()%count);
  664.         temp=arr[i];
  665.         arr[i]=arr[z];
  666.         arr[z]=temp;
  667.     }
  668.     for(i=0; i<10; i++)
  669.     {
  670.         char partians;
  671.         gotoxy(4,2);
  672.         printf("SCORE : %d",scr);
  673.         gotoxy(92,2);
  674.         printf("Difficulty Level : Easy");
  675.         gotoxy(18,5);
  676.         printf("________________________________________");
  677.         gotoxy(18,7);
  678.         printf("%d.%s\n",(i+1),quiz[arr[i]]);
  679.  
  680.         for(int j=(arr[i]*4); j<((arr[i]*4)+4); j++)
  681.         {
  682.             printf("\t\t\t%s\n",option[j]);
  683.         }
  684.         gotoxy(18,16);
  685.         printf("________________________________________");
  686.         gotoxy(20,19);
  687.         printf("Choose Your Answer: ");
  688.         scanf("%c",&partians);
  689.         getchar();
  690.         partians=toupper(partians);
  691.         if(partians==answer[arr[i]])
  692.         {
  693.             gotoxy(20,21);
  694.             printf("CORRECT!!!");
  695.             scr++;
  696.         }
  697.         else
  698.         {
  699.             gotoxy(20,21);
  700.             printf("WRONG!!!");
  701.             gotoxy(20,23);
  702.             printf("The correct Answer is %c\n",answer[arr[i]]);
  703.         }
  704.         gotoxy(20,24);
  705.         Sleep(2000);
  706.         system("cls");
  707.         border();
  708.     }
  709.     game = fopen("score.text","a");
  710.     fprintf(game,"%d\n",scr);
  711.     fclose(game);
  712.     result(scr,nm,stat,inst,ag);
  713. }
  714. void mediumgame()
  715. {
  716.     system("cls");
  717.     border();
  718.     char nm[255],stat[255],inst[255];
  719.     int ag;
  720.     gotoxy(47,3);
  721.     printf("Enter Below Info\n");
  722.     for(int i=0;i<16;i++)
  723.     {
  724.         gotoxy(47+i,4);
  725.         printf("-");
  726.     }
  727.     getchar();
  728.     gotoxy(25,5);
  729.     printf("User Name: ");
  730.     gets(nm);
  731.     gotoxy(25,6);
  732.     printf("Age: ");
  733.     scanf("%d",&ag);
  734.     gotoxy(25,7);
  735.     printf("Educational Status: ");
  736.     getchar();
  737.     gets(stat);
  738.     gotoxy(25,8);
  739.     printf("Institution: ");
  740.     gets(inst);
  741.  
  742.     FILE *game;
  743.  
  744.     game = fopen("search.text","a");
  745.     fprintf(game,"%s\n",nm);
  746.     fclose(game);
  747.  
  748.     game = fopen("level.text","a");
  749.     fprintf(game,"Medium\n");
  750.     fclose(game);
  751.  
  752.     int i,j,count=0;
  753.     time_t t;
  754.     char quiz[300][200]= {};
  755.     char option[1200][100]= {};
  756.     char answer[300]= {};
  757.     game=fopen("mediumquiz.text","r");
  758.     for(int i=0; ; i++)
  759.     {
  760.         if(fgets(quiz[i],200,game)!=NULL)
  761.             count++;
  762.         else
  763.             break;
  764.     }
  765.     fclose(game);
  766.     count=0;
  767.     game=fopen("mediumoption.text","r");
  768.     for(i=0; ; i++)
  769.     {
  770.         if(fgets(option[i],100,game)!=NULL)
  771.             count++;
  772.         else
  773.             break;
  774.     }
  775.     fclose(game);
  776.     count=0;
  777.     game=fopen("mediumanswer.text","r");
  778.     for(i=0; ; i++)
  779.     {
  780.         answer[i]=fgetc(game);
  781.         count++;
  782.         if(feof(game))
  783.             break ;
  784.     }
  785.     fclose(game);
  786.     count--;
  787.     srand(time(NULL));
  788.     system("cls");
  789.     border();
  790.     int scr=0;
  791.     int arr[count];
  792.     for(i=0; i<count; i++)
  793.     {
  794.         arr[i]=i;
  795.     }
  796.     int temp,z;
  797.     for(i=0; i<count; i++)
  798.     {
  799.         z=(rand()%count);
  800.         temp=arr[i];
  801.         arr[i]=arr[z];
  802.         arr[z]=temp;
  803.     }
  804.     for(i=0; i<10; i++)
  805.     {
  806.         char partians;
  807.         gotoxy(4,2);
  808.         printf("SCORE : %d",scr);
  809.         gotoxy(92,2);
  810.         printf("Difficulty Level : Medium");
  811.         gotoxy(18,5);
  812.         printf("________________________________________");
  813.         gotoxy(18,7);
  814.         printf("%d.%s\n",(i+1),quiz[arr[i]]);
  815.  
  816.         for(int j=(arr[i]*4); j<((arr[i]*4)+4); j++)
  817.         {
  818.             printf("\t\t\t%s\n",option[j]);
  819.         }
  820.         gotoxy(18,16);
  821.         printf("________________________________________");
  822.         gotoxy(20,19);
  823.         printf("Choose Your Answer: ");
  824.         scanf("%c",&partians);
  825.         getchar();
  826.         partians=toupper(partians);
  827.         if(partians==answer[arr[i]])
  828.         {
  829.             gotoxy(20,21);
  830.             printf("CORRECT!!!\n");
  831.             scr++;
  832.         }
  833.         else
  834.         {
  835.             gotoxy(20,21);
  836.             printf("WRONG!!!");
  837.             gotoxy(20,23);
  838.             printf("The correct Answer is %c\n",answer[arr[i]]);
  839.         }
  840.         gotoxy(20,24);
  841.         Sleep(2000);
  842.         system("cls");
  843.         border();
  844.     }
  845.     game = fopen("score.text","a");
  846.     fprintf(game,"%d\n",scr);
  847.     fclose(game);
  848.     result(scr,nm,stat,inst,ag);
  849. }
  850. void hardgame()
  851. {
  852.     system("cls");
  853.     border();
  854.     char nm[255],stat[255],inst[255];
  855.     int ag;
  856.     gotoxy(47,3);
  857.     printf("Enter Below Info\n");
  858.     for(int i=0;i<16;i++)
  859.     {
  860.         gotoxy(47+i,4);
  861.         printf("-");
  862.     }
  863.     getchar();
  864.     gotoxy(25,5);
  865.     printf("User Name: ");
  866.     gets(nm);
  867.     gotoxy(25,6);
  868.     printf("Age: ");
  869.     scanf("%d",&ag);
  870.     gotoxy(25,7);
  871.     printf("Educational Status: ");
  872.     getchar();
  873.     gets(stat);
  874.     gotoxy(25,8);
  875.     printf("Institution: ");
  876.     gets(inst);
  877.  
  878.     FILE *game;
  879.  
  880.     game = fopen("search.text","a");
  881.     fprintf(game,"%s\n",nm);
  882.     fclose(game);
  883.  
  884.     game = fopen("level.text","a");
  885.     fprintf(game,"Hard\n");
  886.     fclose(game);
  887.     int i,j,count=0;
  888.     time_t t;
  889.     char quiz[300][200]= {};
  890.     char option[1200][100]= {};
  891.     char answer[300]= {};
  892.     game=fopen("hardquiz.text","r");
  893.     for(int i=0; ; i++)
  894.     {
  895.         if(fgets(quiz[i],200,game)!=NULL)
  896.             count++;
  897.         else
  898.             break;
  899.     }
  900.     fclose(game);
  901.     count=0;
  902.     game=fopen("hardoption.text","r");
  903.     for(i=0; ; i++)
  904.     {
  905.         if(fgets(option[i],100,game)!=NULL)
  906.             count++;
  907.         else
  908.             break;
  909.     }
  910.     fclose(game);
  911.     count=0;
  912.     game=fopen("hardanswer.text","r");
  913.     for(i=0; ; i++)
  914.     {
  915.         answer[i]=fgetc(game);
  916.         count++;
  917.         if(feof(game))
  918.             break ;
  919.     }
  920.     fclose(game);
  921.     count--;
  922.     srand(time(NULL));
  923.     system("cls");
  924.     border();
  925.     int scr=0;
  926.     int arr[count];
  927.     for(i=0; i<count; i++)
  928.     {
  929.         arr[i]=i;
  930.     }
  931.     int temp,z;
  932.     for(i=0; i<count; i++)
  933.     {
  934.         z=(rand()%count);
  935.         temp=arr[i];
  936.         arr[i]=arr[z];
  937.         arr[z]=temp;
  938.     }
  939.     for(i=0; i<10; i++)
  940.     {
  941.         char partians;
  942.         gotoxy(4,2);
  943.         printf("SCORE : %d",scr);
  944.         gotoxy(92,2);
  945.         printf("Difficulty Level : Hard");
  946.         gotoxy(18,5);
  947.         printf("________________________________________");
  948.         gotoxy(18,7);
  949.         printf("%d.%s\n",(i+1),quiz[arr[i]]);
  950.  
  951.         for(int j=(arr[i]*4); j<((arr[i]*4)+4); j++)
  952.         {
  953.             printf("\t\t\t%s\n",option[j]);
  954.         }
  955.         gotoxy(18,16);
  956.         printf("________________________________________");
  957.         gotoxy(20,19);
  958.         printf("Choose Your Answer: ");
  959.         scanf("%c",&partians);
  960.         getchar();
  961.         partians=toupper(partians);
  962.         if(partians==answer[arr[i]])
  963.         {
  964.             gotoxy(20,21);
  965.             printf("CORRECT!!!\n");
  966.             scr++;
  967.         }
  968.         else
  969.         {
  970.             gotoxy(20,21);
  971.             printf("WRONG!!!");
  972.             gotoxy(20,23);
  973.             printf("The correct Answer is %c\n",answer[arr[i]]);
  974.         }
  975.         gotoxy(20,24);
  976.         Sleep(2000);
  977.         system("cls");
  978.         border();
  979.     }
  980.     game = fopen("score.text","a");
  981.     fprintf(game,"%d\n",scr);
  982.     fclose(game);
  983.     result(scr,nm,stat,inst,ag);
  984. }
  985. void highestscore()
  986. {
  987.     system("cls");
  988.     border();
  989.     FILE *game;
  990.     game=fopen("score.text","r");
  991.     int i=0;
  992.     while(!feof(game))
  993.     {
  994.         fscanf(game,"%d",&player[i].score);
  995.         i++;
  996.     }
  997.     fclose(game);
  998.     game=fopen("search.text","r");
  999.     int m=0;
  1000.     while(!feof(game))
  1001.     {
  1002.         if(fgets(player[m].name,255,game)!=NULL)
  1003.             m++;
  1004.     }
  1005.     fclose(game);
  1006.     for(int i=0;i<17;i++)
  1007.     {
  1008.         gotoxy(48+i,4);
  1009.         Sleep(10);
  1010.         printf("\xDB");
  1011.         gotoxy(48+i,6);
  1012.         Sleep(10);
  1013.         printf("\xDB");
  1014.     }
  1015.     gotoxy(48,5);
  1016.     Sleep(10);
  1017.     printf("\xDB");
  1018.     gotoxy(64,5);
  1019.     Sleep(10);
  1020.     printf("\xDB");
  1021.     gotoxy(50,5);
  1022.     printf("Highest Score");
  1023.     gotoxy(41,7);
  1024.     printf("User Name");
  1025.     for(int i=0;i<9;i++)
  1026.     {
  1027.         gotoxy(41+i,8);
  1028.         Sleep(10);
  1029.         printf("-");
  1030.     }
  1031.     gotoxy(67,7);
  1032.     printf("Score");
  1033.     for(int i=0;i<5;i++)
  1034.     {
  1035.         gotoxy(67+i,8);
  1036.         Sleep(10);
  1037.         printf("-");
  1038.     }
  1039.     for(int j=0; j<i; j++)
  1040.     {
  1041.         int temp;
  1042.         char str[255]= {};
  1043.         for(int k=j+1; k<i; k++)
  1044.         {
  1045.             if(player[j].score < player[k].score)
  1046.             {
  1047.                 temp=player[j].score;
  1048.                 int o=strlen(player[j].name);
  1049.                 for(int l=0; l<o; l++)
  1050.                 {
  1051.                     str[l]=player[j].name[l];
  1052.                     player[j].name[l]='\0';
  1053.                 }
  1054.                 str[o+1]='\0';
  1055.                 player[j].score=player[k].score;
  1056.                 o=strlen(player[k].name);
  1057.                 for(int l=0; l<o; l++)
  1058.                 {
  1059.                     player[j].name[l]=player[k].name[l];
  1060.                     player[k].name[l]='\0';
  1061.                 }
  1062.                 player[j].name[o+1]='\0';
  1063.                 player[k].score=temp;
  1064.                 o=strlen(str);
  1065.                 for(int l=0; l<o; l++)
  1066.                 {
  1067.                     player[k].name[l]=str[l];
  1068.                     str[l]='\0';
  1069.                 }
  1070.                 player[k].name[o+1]='\0';
  1071.             }
  1072.         }
  1073.     }
  1074.     for(int j=0; j<10; j++)
  1075.     {
  1076.         gotoxy(40,9+j);
  1077.         printf("%d. %s",j+1,player[j].name);
  1078.         gotoxy(65,9+j);
  1079.         printf(" ---> %d",player[j].score);
  1080.     }
  1081.     getchar();
  1082.     gotoxy(45,24);
  1083.     printf("Enter Any Key To Go Back ");
  1084.     getchar();
  1085.     menu();
  1086. }
  1087. void Search()
  1088. {
  1089.     system("cls");
  1090.     border();
  1091.     getchar();
  1092.     char user[255];
  1093.     gotoxy(18,10);
  1094.     printf("> Please Enter User Name : ");
  1095.     gets(user);
  1096.     int s=strlen(user);
  1097.     system("cls");
  1098.     border();
  1099.     FILE *game;
  1100.     game=fopen("search.text","r");
  1101.     int m=0;
  1102.     while(!feof(game))
  1103.     {
  1104.         if(fgets(player[m].name,255,game)!=NULL)
  1105.             m++;
  1106.     }
  1107.     fclose(game);
  1108.     game=fopen("score.text","r");
  1109.     int i=0;
  1110.     while(!feof(game))
  1111.     {
  1112.         fscanf(game,"%d",&player[i].score);
  1113.         i++;
  1114.     }
  1115.     fclose(game);
  1116.     game=fopen("level.text","r");
  1117.     i=0;
  1118.     while(!feof(game))
  1119.     {
  1120.         if(fgets(player[i].level,20,game)!=NULL)
  1121.          i++;
  1122.     }
  1123.     fclose(game);
  1124.     for(int i=0;i<17;i+=2)
  1125.     {
  1126.         gotoxy(47+i,3);
  1127.         Sleep(8);
  1128.         printf("\xDB");
  1129.         gotoxy(47+i,5);
  1130.         Sleep(8);
  1131.         printf("\xDB");
  1132.     }
  1133.     gotoxy(47,4);
  1134.     printf("\xDB");
  1135.     gotoxy(63,4);
  1136.     printf("\xDB");
  1137.     gotoxy(49,4);
  1138.     printf("Search Result");
  1139.  
  1140.     gotoxy(33,6);
  1141.     printf("User Name");
  1142.     for(int i=0;i<9;i++)
  1143.     {
  1144.         gotoxy(33+i,7);
  1145.         Sleep(8);
  1146.         printf("-");
  1147.     }
  1148.     gotoxy(58,6);
  1149.     printf("Score");
  1150.     for(int i=0;i<5;i++)
  1151.     {
  1152.         gotoxy(58+i,7);
  1153.         Sleep(8);
  1154.         printf("-");
  1155.     }
  1156.     gotoxy(72,6);
  1157.     printf("Level");
  1158.     for(int i=0;i<5;i++)
  1159.     {
  1160.         gotoxy(72+i,7);
  1161.         Sleep(8);
  1162.         printf("-");
  1163.     }
  1164.     int q=0,count=0;
  1165.     for(i=0; i<m; i++)
  1166.     {
  1167.  
  1168.         int k=strlen(player[i].name);
  1169.         for(int j=0; j<=k; j++)
  1170.         {
  1171.             if(user[j]==player[i].name[j])
  1172.             {
  1173.                 count++;
  1174.             }
  1175.         }
  1176.         if(count==k)
  1177.         {
  1178.             q++;
  1179.             gotoxy(32,8+q);
  1180.             printf("%d.%s",q,player[i].name);
  1181.             gotoxy(57,8+q);
  1182.             printf(" ----> %d",player[i].score);
  1183.             gotoxy(72,8+q);
  1184.             printf("%s",player[i].level);
  1185.  
  1186.         }
  1187.         count=0;
  1188.     }
  1189.     if(q==0)
  1190.     {
  1191.         system("cls");
  1192.         border();
  1193.         color();
  1194.         gotoxy(40,8);
  1195.         printf("Data Not Found!! Please Input Correct Data.");
  1196.         gotoxy(45,10);
  1197.         printf("Enter Any Key To Go Back ");
  1198.         getchar();
  1199.         menu();
  1200.  
  1201.     }
  1202.     gotoxy(45,12+q);
  1203.     printf("Enter Any Key To Go Back ");
  1204.     getchar();
  1205.     menu();
  1206. }
  1207. void developerinfo()
  1208. {
  1209.     system("cls");
  1210.     border();
  1211.     for(int i=0;i<17;i++)
  1212.     {
  1213.         gotoxy(46+i,4);
  1214.         Sleep(10);
  1215.         printf("\xDB");
  1216.         gotoxy(46+i,8);
  1217.         Sleep(10);
  1218.         printf("\xDB");
  1219.     }
  1220.     for(int i=0;i<5;i++)
  1221.     {
  1222.         gotoxy(46,4+i);
  1223.         Sleep(10);
  1224.         printf("\xDB");
  1225.         gotoxy(63,4+i);
  1226.         Sleep(10);
  1227.         printf("\xDB");
  1228.     }
  1229.     gotoxy(48,6);
  1230.     Sleep(8);
  1231.     printf("NULL_STUNNERS");
  1232.     gotoxy(15,11);
  1233.     Sleep(8);
  1234.     printf("> Asik Ifthaker Hamim(Team Leader)");
  1235.     gotoxy(15,12);
  1236.     Sleep(8);
  1237.     printf("> Abdul Mohaimin");
  1238.     gotoxy(15,13);
  1239.     Sleep(8);
  1240.     printf("> Mohammad Faisal Bin Awal Chowdhury");
  1241.     gotoxy(15,14);
  1242.     Sleep(8);
  1243.     printf("> Sheikh Mohammad Rajking");
  1244.     gotoxy(45,20);
  1245.     Sleep(8);
  1246.     getchar();
  1247.     printf("Press Any Key To Go Back ");
  1248.     getchar();
  1249.     menu();
  1250.  
  1251. }
  1252. void Exit()
  1253. {
  1254.     system("cls");
  1255.     border();
  1256.     for(int i=0;i<31;i++)
  1257.     {
  1258.         gotoxy(44+i,11);
  1259.         Sleep(8);
  1260.         printf("\xDB");
  1261.         gotoxy(44+i,17);
  1262.         Sleep(8);
  1263.         printf("\xDB");
  1264.     }
  1265.     for(int i=0;i<7;i++)
  1266.     {
  1267.         gotoxy(44,11+i);
  1268.         Sleep(8);
  1269.         printf("\xDB");
  1270.         gotoxy(75,11+i);
  1271.         Sleep(8);
  1272.         printf("\xDB");
  1273.     }
  1274.     gotoxy(47,13);
  1275.     Sleep(5);
  1276.     printf("Thanks For Playing The Game");
  1277.     gotoxy(47,15);
  1278.     Sleep(5);
  1279.     printf("Developed By NULL_STUNNERS");
  1280.     gotoxy(3,30);
  1281. }
  1282.  
  1283.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement