Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main()
  6. {
  7.     srand ( time(NULL) );
  8.     int Stat[3] = {0,0,0}; // HP, Attack, Defense.
  9.     int HP, maxHP, mHP, level, race, tmp; // Yours and the enemys current HP, and the stage
  10.     char Name[20];
  11.     printf("RPG Survival, welcome!\n");
  12.     printf("What's your name?: "); scanf("%s", Name);
  13.     printf("\nChoose your race, along with it comes stats, in order HP-Attack-Defense:\n");
  14.     printf("1. Human; 10-10-10\n");
  15.     printf("2. Orc; 10-13-7\n");
  16.     printf("3. Elf; 15-7-8\n");
  17.     printf("4. Wizard; 6-11-12\n");
  18.     printf("Type the number for the race of your choice: "); scanf("%d", &race);
  19.     switch(race)
  20.     {
  21.         case 1:
  22.         Stat[0] = 10;
  23.         Stat[1] = 10;
  24.         Stat[2] = 10;
  25.         break;
  26.  
  27.         case 2:
  28.         Stat[0] = 10;
  29.         Stat[1] = 13;
  30.         Stat[2] = 17;
  31.         break;
  32.  
  33.         case 3:
  34.         Stat[0] = 15;
  35.         Stat[1] = 7;
  36.         Stat[2] = 8;
  37.         break;
  38.  
  39.         case 4:
  40.         Stat[0] = 6;
  41.         Stat[1] = 11;
  42.         Stat[2] = 12;
  43.         break;
  44.     }
  45.     maxHP = Stat[0]*1.5;
  46.     HP = maxHP;
  47.     printf("\nTime to start your journey!\n\n");
  48.     while(HP>0)
  49.     {
  50.         int Pow, npow, choice, mchoice, mmaxHP;
  51.         printf("You encounter a level %d enemy!\n", level);
  52.         mHP = level*5+1;
  53.         mmaxHP = level*5+1;
  54.         while(mHP>0)
  55.         {
  56.             printf("[%s: %d/%d HP; Monster: %d/%d HP]\n",Name, HP, maxHP, mHP, mmaxHP);
  57.             printf("What should you do?: [1-Attack; 2-Defend; 3-Heal]\n> ");
  58.             scanf("%d", &choice);
  59.             mchoice = rand()%3+1;
  60.             if(mchoice==2){printf("The monster defended itself!\n");}
  61.             switch(choice)
  62.             {
  63.                 case 1: // Attack
  64.                 Pow = rand() % 5 + Stat[1];
  65.                 switch(mchoice)
  66.                 {
  67.                     case 2: // Blocked!ř
  68.                     npow = Pow-10;
  69.                     if(npow<0) npow = 0;
  70.                     printf("%s attacked the monster! It did %d damage!\n", Name, npow);
  71.                     mHP -= npow;
  72.                     break;
  73.  
  74.                     default:
  75.                     printf("%s attacked the monster! it did %d damage!\n", Name, Pow);
  76.                     mHP -= Pow;
  77.                 }
  78.                 break;
  79.  
  80.                 case 2: // Defend
  81.                 printf("%s is defending!\n", Name);
  82.                 break;
  83.  
  84.                 case 3: // Healing
  85.                 Pow = rand()%5 + Stat[2];
  86.                 if(HP+Pow > maxHP)
  87.                 {
  88.                     printf("%s healed to full health\n", Name);
  89.                     HP = maxHP;
  90.                 }
  91.                 else if(HP+Pow < maxHP)
  92.                 {
  93.                     printf("%s healed %d points!\n", Name, Pow);
  94.                     HP += Pow;
  95.                 }
  96.             }
  97.  
  98.             if(mHP<=0)
  99.             {
  100.                 printf("The monster died!\n\n");
  101.                 goto SKIP;
  102.             }
  103.  
  104.             switch(mchoice)
  105.             {
  106.                 case 1: // Attack
  107.                 Pow = rand()%5 + level;
  108.                 switch(choice)
  109.                 {
  110.                     case 2: // Blocked!
  111.                     npow = Pow-10;
  112.                     if(npow<0) npow = 0;
  113.                     printf("The monster attacked you! It did %d damage!\n", npow);
  114.                     HP -= npow;
  115.                     break;
  116.  
  117.                     default:
  118.                     printf("The monster attacked you! it did %d damage!\n", Pow);
  119.                     HP -= Pow;
  120.                 }
  121.                 break;
  122.  
  123.                 case 3: // Healing
  124.                 Pow = rand()%5+(level*3);
  125.                 if(mHP+Pow > mmaxHP)
  126.                 {
  127.                     printf("The monster healed to full health!\n");
  128.                     mHP = mmaxHP;
  129.                 }
  130.                 else
  131.                 {
  132.                     printf("The monster healed %d points!\n", Pow);
  133.                     mHP += Pow;
  134.                 }
  135.             }
  136.             SKIP:
  137.             if(HP<=0)
  138.             {
  139.                 printf("You died!\n\n");
  140.             }
  141.             printf("\n");
  142.         }
  143.         level = level+1;
  144.     }
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement