Advertisement
akevintg

RPG GAME in C

Dec 3rd, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 12.42 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  GAME RPG
  4. //
  5. //  Created by Alexander Kevin on 11/29/13.
  6. //  Copyright (c) 2013 Alexander Kevin. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <time.h>
  11. #include <stdlib.h>
  12. #include <Windows.h>
  13. #include <string.h>
  14. void welcome();
  15. void home();
  16. void create();
  17.     void adventure();
  18.         void battle();
  19.         void enchant();
  20.         void store();
  21.         void about();
  22.         void exit();
  23.  
  24. int money=0,lv=1,plus=0,str=15,bonusstat=0,hpmaks=150,hpm,encounter=1;
  25. int brd=0,ktn=0,wft=0,elu=0;
  26. char nick[10],answer;
  27. FILE *nickname,*stat,*item;
  28.  
  29.  
  30. int main(){
  31.     welcome();
  32. }
  33.  
  34. void welcome(){
  35.     printf("*********************************** VER 3.2 ************************************");
  36.     if((nickname=fopen("nick.dat","r"))==NULL||(stat=fopen("stat.dat","r"))==NULL||(item=fopen("item.dat","r"))==NULL){
  37.         printf("\n\n\n\n\n\nWELCOME TO RPG GAME\n===============================\nStart your Journey <enter>");
  38.         printf(", Lets Create your Character\n");
  39.         getchar();
  40.         create();}
  41.     else{
  42.         fscanf(nickname,"%s",nick);
  43.         printf("\n\n\n\n\n\n===========================================\nWelcome Back %s!\nLets Continue your journey\n<Y to continue,N to start a new journey>\n===========================================\n",nick);
  44.         scanf("%c",&answer);fflush stdin;
  45.         if(answer=='Y'||answer=='y'){
  46.             fscanf(stat,"%d %d %d %d %d %d %d",&money,&lv,&plus,&str,&bonusstat,&hpmaks,&encounter);
  47.             fscanf(item,"%d %d %d %d",&brd,&ktn,&wft,&elu);
  48.             adventure();
  49.         }
  50.         else
  51.             create();
  52.     }
  53.        
  54. }
  55.  
  56. void create(){
  57.     system("cls");
  58.     do{
  59.         printf("Input your Character Nicknames[maks 10] : ");
  60.         gets(nick);fflush (stdin);
  61.         printf("Your Character names is %s, OK[Y/N]? ",nick);
  62.         scanf("%c",&answer);fflush (stdin);
  63.     }while(answer!='Y'&&answer!='y');
  64.     printf("\nLet The Adventure Begin");
  65.     nickname=fopen("nick.dat","w");
  66.     fprintf(nickname,"%s",nick);
  67.     fclose(nickname);
  68.     stat=fopen("stat.dat","w");
  69.     fprintf(stat,"%d %d %d %d %d %d %d",money,lv,plus,str,bonusstat,hpmaks,encounter);
  70.     fclose(stat);
  71.     getchar();
  72.     adventure();
  73. }
  74.  
  75. void adventure(){
  76.     char eq[100][100]={"Broadsword","Katana","WindFleuret","Elucidator"};
  77.     int x;
  78.     if (brd==1)
  79.         x=0;
  80.     if (ktn==1)
  81.         x=1;
  82.     if (wft==1)
  83.         x=2;
  84.     if (elu==1)
  85.         x=3;
  86.     system("cls");
  87.     printf("-------------------------------------------------------------------------------\n%s, Welcome to the world of ....... !\n-------------------------------------------------------------------------------",nick);
  88.     printf("\n\n\n%s Lv.%d\n=================================\n|Status\t\t|Point\t\t|\n=================================\n",nick,lv);
  89.     printf("|HP\t\t|%d\t\t|\n",hpmaks);
  90.     printf("|STR\t\t|%d(+%d)\t",str,bonusstat);
  91.         if (bonusstat<10)
  92.             printf("\t");
  93.     printf("|\n");
  94.     printf("=================================\n");
  95.     if(brd==1||ktn==1||wft==1||elu==1)
  96.         printf("%s+%d(STR+%d)\n",eq[x],plus,bonusstat);
  97.     printf("GOLD %dG\n",money);
  98.     printf("What do you want to do(B=Battle,E=Enchant,S=Store,0=exit)? ");
  99.     scanf("%c",&answer);fflush (stdin);
  100.     if(answer=='B'||answer=='b')
  101.         battle();
  102.     if(answer=='E'||answer=='e')
  103.         enchant();
  104.     if(answer=='S'||answer=='s')
  105.         store();
  106.     else
  107.         about();
  108. }
  109.  
  110. void battle(){
  111.     system("cls");
  112.     int att,critical,criticalm,attm,hpup,strup,hp=hpmaks,gold,boss=0;
  113.     srand(time(NULL));
  114.     hpm=rand()%30*lv+10*lv;
  115.     if(hpm>=(25*lv+10*lv)){
  116.         printf("Boss Level\n*********************************************\n");
  117.         boss=1;
  118.     }
  119.     printf("\nMonster Lv.%d\n=================================\n|Status\t\t|Point\t\t|\n",encounter);
  120.     printf("|HP\t\t|%d\t\t|\n",hpm);
  121.     printf("=================================\nBattle Will Begin\n");
  122.     printf("Attack Log : \nLoading Data");
  123.     Sleep(400);
  124.     printf(".");
  125.     Sleep(400);
  126.     printf(".");
  127.     Sleep(400);
  128.     printf(".\n\n");
  129.            do{  
  130.                srand(time(NULL));
  131.                critical=rand()%100+1;
  132.                att=str+(rand()%10);
  133.                if (critical==(11||22||33||44||55))
  134.                    att=0;
  135.                if(critical==(66||32||21||10||43||54||77||88||99))
  136.                    att=att*(rand()%2+2);
  137.                Sleep(2000);
  138.                if(att!=0&&hp>0&&hpm>0){
  139.                    if(critical==(66||32||21||10||43||54||77||88||99))
  140.                        printf("CRITICAL HIT!\n");
  141.                    hpm-=att;
  142.                    if(hpm<0)
  143.                        hpm=0;
  144.                    printf("Damage %d, Monster Hp %d\n",att,hpm);
  145.                }else if(att==0&&hp>0)
  146.                    printf("YOUR ATTACK MISS!\n");
  147.                 printf("\nMonster Lv.%d\n=================================\n|Status\t\t|Point\t\t|\n",encounter);
  148.                 printf("|HP\t\t|%d\t\t|\n",hpm);
  149.                 printf("=================================\n");
  150.                 Sleep(300);
  151.                 srand(time(NULL));
  152.                 criticalm=rand()%100+1;
  153.                 attm=str+(rand()%10)*(encounter/3+1);
  154.                 if(boss==1)
  155.                     attm+=str/3;
  156.                 if (criticalm==(77||88||99||66||1))
  157.                     attm=0;
  158.                 if(criticalm==(5||15||25||35||45||55||65||75||85||95))
  159.                     attm=attm*(rand()%2+2);
  160.                
  161.                 if(attm!=0&&hpm>0&&hp>0){
  162.                     hp-=attm;
  163.                     if(criticalm==(5||15||25||35||45||55||65||75||85||95))
  164.                         printf("Monster does CRITICAL HIT!\n");
  165.                     if(hp<0)
  166.                         hp=0;
  167.                    printf("Damage Received %d, your Hp %d\n",attm,hp);
  168.                 }else if(attm==0&&hpm>0&&hp>0)
  169.                    printf("LUCKY, MONSTER ATTACK MISS!\n");
  170.                 printf("\n%s Lv.%d\n=================================\n|Status\t\t|Point\t\t|\n",nick,lv);
  171.                 printf("|HP\t\t|%d\t\t|\n",hp);
  172.                 printf("=================================\n");
  173.            }while(hpm>0&&hp>0);
  174.     if(hpm<=0&&hp>0){
  175.         encounter++;
  176.         if (boss==1){
  177.             gold=(rand()%100+100)*lv+20;
  178.             money+=gold;
  179.             printf("YOU DEFEAT THE BOSS\nBonus Reward : %dG\n",money);
  180.         }
  181.         hpup=(rand()%3+1)*10;
  182.         Sleep(10);
  183.         strup=rand()%7+1;
  184.         Sleep(10);
  185.         gold=(rand()%50+50)*lv+20;
  186.         money+=gold;
  187.         str+=strup;
  188.         hpmaks+=hpup;
  189.         lv++;
  190.         printf("CONGRATULATION %s, LVL UP BY 1\nSTR UP BY %d\nHP UP BY %d\nGot %dG ",nick,strup,hpup,gold);
  191.         getchar();
  192.     }else{
  193.         printf("DEFEATED");
  194.         getchar();
  195.     }
  196.     adventure();
  197. }
  198.  
  199. void exit(){
  200.     system("cls");
  201.    
  202.     FILE *stat;
  203.     stat=fopen("stat.dat","w");
  204.     fprintf(stat,"%d %d %d %d %d %d %d",money,lv,plus,str,bonusstat,hpmaks,encounter);
  205.     fclose(stat);
  206.    
  207.     printf("\n\n\n\n\n***********************************************************\n%s, THANKS FOR PLAYING SEE U NEXT TIME\n***********************************************************\n",nick);
  208.     printf("Program Will SelfClose in 3");
  209.     Sleep(600);
  210.     printf(" 2");
  211.     Sleep(600);
  212.     printf(" 1");
  213.     Sleep(600);
  214. }
  215.  
  216. void enchant(){
  217.     int price,chance;
  218.     price=plus*100;
  219.     int times=500+plus*100;
  220.     if (plus>=3)
  221.         price=plus*250;
  222.     if (plus>=6)
  223.         price=plus*500;
  224.     if (plus>=9)
  225.         plus=plus*1000;
  226.     system("cls");
  227.     printf("-------------------------------------------------------------------------------\n%s, Welcome to the Blacksmith!\n-------------------------------------------------------------------------------\n",nick);
  228.     printf("* +4 - +6 if fail weapon may be down by 1 level\n  +7 - +13 if fail weapon will be destroyed or go down by 1/2 level\n\nYour Current Gold %dG\n\n",money);
  229.     if(ktn==0&&elu==0&&wft==0&&brd==0){
  230.         printf("Sorry You dont have weapon Yet!\nThanks For Stoping By\nSee You Next Time\n");
  231.         getchar();
  232.         adventure();
  233.     }
  234.     if(plus<13){
  235.     printf("do you want to strenghtning your weapon to +%d (Price %dG)[Y/N]? ",plus+1,price);
  236.     scanf("%c",&answer);fflush stdin;
  237.     if ((answer=='Y'||answer=='y')&&money>=price){
  238.         money-=price;
  239.         printf("Enchanting your weapon \nDo NOT PRESS ANY BUTON, Loading");
  240.         Sleep(times);
  241.         printf(".");
  242.         Sleep(times);
  243.         printf(".");
  244.         Sleep(times);
  245.         printf(".\n\n");
  246.         srand(time(NULL));
  247.         chance=rand()%100+1;
  248.         if(plus<10){
  249.         if(chance>=plus*10){
  250.             plus++;
  251.             bonusstat+=bonusstat*0.1;
  252.             if(plus>=7&&plus<10)
  253.                 bonusstat+=bonusstat*0.1+plus;
  254.             printf("SUCCESS!!!\nYOUR WEAPON IS NOW +%d Bonus Stat(STR+%d)\n",plus,bonusstat);
  255.             str+=bonusstat;
  256.         }else if(plus<=3)
  257.             printf("ENCHANCEMENT FAILED! sorry...\n");
  258.         else if(plus>3&&plus<7){
  259.             srand(time(NULL));
  260.             chance=rand()%100+1;
  261.             if(chance<10){
  262.                 plus--;
  263.                 bonusstat-=bonusstat*0.1;
  264.                 printf("ENCHANCEMENT FAILED! your weapon is now +%d Bonus Stat(STR+%d)\n",plus,bonusstat);
  265.             }else
  266.                 printf("ENCHANCEMENT FAILED! sorry...\n");
  267.         }else if(plus>=7){
  268.             srand(time(NULL));
  269.             chance=rand()%100+1;
  270.             if(chance<25){
  271.                 plus=0;
  272.                 bonusstat=0;
  273.                 brd=0,elu=0,ktn=0,wft=0;
  274.                 printf("ENCHANCEMENT FAILED! your weapon is destroyed\n");
  275.             }
  276.             else if(chance>=25&&chance<=50){
  277.                 plus--;
  278.                 bonusstat-=bonusstat*0.1;
  279.                 printf("ENCHANCEMENT FAILED! your weapon is now +%d Bonus Stat(STR+%d)\n",plus,bonusstat);
  280.             }
  281.             else
  282.                 printf("ENCHANCEMENT FAILED! sorry...\n");
  283.         }
  284.         }else if(plus>=10) {
  285.             if(chance>=(100-10+plus/2)){
  286.             plus++;
  287.             bonusstat+=bonusstat*0.4+plus;
  288.             printf("SUCCESS!!!\nYOUR WEAPON IS NOW +%d Bonus Stat(STR+%d)\n",plus,bonusstat);
  289.             str+=bonusstat;
  290.             }
  291.             else if(chance<65){
  292.                 plus=0;
  293.                 bonusstat=0;
  294.                 brd=0,elu=0,ktn=0,wft=0;
  295.                 printf("ENCHANCEMENT FAILED! your weapon is destroyed\n");
  296.             }
  297.             else if(chance>=65&&chance<(100-10+plus/2)){
  298.                 plus-=2;
  299.                 bonusstat-=bonusstat*0.2+plus;
  300.                 printf("ENCHANCEMENT FAILED! your weapon is now +%d Bonus Stat(STR+%d)\n",plus,bonusstat);
  301.             }
  302.             else
  303.                 printf("ENCHANCEMENT FAILED! sorry...\n");
  304.         }
  305.     }else if(money<price&&(answer=='Y'||answer=='y'))
  306.             printf("Sorry You Don't have enough Gold.\n");
  307.     FILE *stat;
  308.     stat=fopen("stat.dat","w");
  309.     fprintf(stat,"%d %d %d %d %d %d %d",money,lv,plus,str,bonusstat,hpmaks,encounter);
  310.     fclose(stat);
  311.     }else
  312.         printf("%s, You CONGRATULATION YOU HAVE MAX-OUT YOUR WEAPON, There's nothing else you can do here\n");
  313.     printf("Thanks For stoping bye %s!",nick);
  314.     printf(" See U Next Time\n");
  315.     getchar();
  316.     adventure();
  317. }
  318.  
  319. void about(){
  320.     system("cls");
  321.     printf("\n\n\nChanelogs :\n==============================================================\n");
  322.     printf("Ver 1.0 Release\nVer 1.3 Fix Major Bugs\nVer 1.5 Fix Minor Bugs\nVer 2.0 Added Save Feature\nVer 2.2 Fix Enchance Feature\nVer 2.3 Fix Minor Bugs\nVer 2.8 Major Fix in Echanment Feature\n");
  323.     printf("Ver 3.0 New Eq(Wft,Brd,Elu,Ktn), Critical Renewal, Enchant Renewal, Store FEATURE, BOSS LEVEL, NEW SAVE FEATURE\nVer 3.2 Games Rebalanced(GOLD,HP,STR,MISS)\n");
  324.     printf("==============================================================\n");
  325.     printf("You will be automove to the exit windows in a few second\n<DO NOT PRESS ANY BUTTON>\n");
  326.     Sleep(4000);
  327.     exit();
  328. }
  329.  
  330. void store(){
  331.     system("cls");
  332.     printf("WELCOME %s TO THE ITEM STORE\n=======================================================\n",nick);
  333.     printf("Broadsword(str+10)\t=100G(Code 0)\nKatana(str+50)\t\t=10000G(Code 1)\nWindFleuret(str+100)\t=50000G(Code 2)\nElucidator(str+200)\t=100000G(Code 3)\n");
  334.     printf("*Keep in mind! if you buy a new eq, your current eq will be destroyed\n\nWhat do you want to buy?\nInput the code here (E to go back): ");
  335.     scanf("%c",&answer);fflush stdin;
  336.     if(answer=='0'&&money>=100){
  337.         brd=1;str-=bonusstat;
  338.         ktn=0,wft=0,elu=0;
  339.         bonusstat=10;str+=bonusstat;
  340.         money-=100;
  341.         plus=0;
  342.         printf("Success!, now your strength is %d(%d) ",str,bonusstat);
  343.     }
  344.     else if(answer=='1'&&money>=10000){
  345.         ktn=1;str-=bonusstat;
  346.         brd=0,wft=0,elu=0;
  347.         bonusstat=50;str+=bonusstat;
  348.         money-=10000;
  349.         plus=0;
  350.         printf("Success!, now your strength is %d(%d) ",str,bonusstat);
  351.     }
  352.     else if(answer=='2'&&money>=50000){
  353.         ktn=0;str-=bonusstat;
  354.         brd=0,wft=1,elu=0;
  355.         bonusstat=100;str+=bonusstat;
  356.         money-=50000;
  357.         plus=0;
  358.         printf("Success!, now your strength is %d(%d) ",str,bonusstat);
  359.     }
  360.     else if(answer=='3'&&money>=100000){
  361.         ktn=0;str-=bonusstat;
  362.         brd=0,wft=1,elu=0;
  363.         bonusstat=200;str+=bonusstat;
  364.         money-=100000;
  365.         plus=0;
  366.         printf("Success!, now your strength is %d(%d) ",str,bonusstat);
  367.     }
  368.     else if(answer=='9'){
  369.         str-=bonusstat;
  370.         elu=1;
  371.         bonusstat=2000;
  372.         str+=bonusstat;
  373.         plus=0;
  374.         printf("You Unlock A secret Elucidator!, now your strength is %d(%d) ",str,bonusstat);
  375.     }
  376.     else if(answer=='e'||answer=='E')
  377.         ;
  378.     else
  379.         printf("Sorry You dont have enough money\n");
  380.     printf("\nThanks for stopping Bye!");
  381.     stat=fopen("stat.dat","w");
  382.     fprintf(stat,"%d %d %d %d %d %d %d",money,lv,plus,str,bonusstat,hpmaks,encounter);
  383.     fclose(stat);
  384.     item=fopen("item.dat","w");
  385.     fprintf(item,"%d %d %d %d ",brd,ktn,wft,elu);
  386.     fclose(item);
  387.     getchar();
  388.     adventure();
  389.    
  390. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement