Advertisement
mantertius

poke.c

Jan 24th, 2021
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.58 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3.  
  4. #define MAX 1000001
  5.  
  6. #define bez 31
  7. #define clo 17
  8.  
  9. typedef struct Pokemons
  10. {
  11.     double hp;
  12.     double dano_inicial;
  13.     double dano_atual;
  14.  
  15. }Pokemon;
  16.  
  17. void SetPokemon(Pokemon *p, double v, double d)
  18. {
  19.     (*p).hp = v;
  20.     p->dano_inicial = d;
  21.     p->dano_atual = d;
  22.     //printf("%d,%d\n", p->hp,p->dano_inicial);
  23. }
  24. int when_b_dies(Pokemon *c, Pokemon *b)
  25. {
  26.     int j = 0;
  27.     double b_hp = b->hp;
  28.     for (int i = 0; 0 <= b_hp ; i++)
  29.     {  
  30.         if(i == 0)
  31.         {
  32.            b_hp = b_hp - c->dano_atual;
  33.            j = i;
  34.            continue;
  35.         }
  36.  
  37.         b_hp = b_hp - c->dano_atual;
  38.                
  39.         j = i;
  40.     }
  41.     //printf("bmorre_em=[%d]\n",j);
  42.     return j;
  43. }
  44.  
  45. int when_c_dies(Pokemon *c, Pokemon *b) //calcula quantos
  46. {
  47.     int j = 0;
  48.     double c_hp = c->hp;
  49.     for (int i = 0; 0 <= c_hp ; i++)
  50.     {  
  51.         if(i == 0)
  52.         {
  53.            c_hp = c_hp - b->dano_atual;
  54.            j = i;
  55.            continue;
  56.         }
  57.  
  58.         c_hp = c_hp - b->dano_atual;
  59.                
  60.         j = i;
  61.     }
  62.     //printf("c_morre_em=[%d]\t",j);
  63.     return j;
  64. }
  65.  
  66. int battle(Pokemon *c, Pokemon *b)
  67. {
  68.     int i = 1;
  69.     while (c->hp > 0 && b->hp > 0)
  70.     {
  71.         int b_dies = when_b_dies(c,b);
  72.         int c_dies = when_c_dies(c,b);
  73.         if (b_dies < c_dies)
  74.         {
  75.             b->hp = b->hp - c->dano_atual;
  76.         }
  77.         else
  78.         {
  79.             c->dano_atual = c->dano_atual + 50; //clodes usa habilidade
  80.         }
  81.        
  82.         c->hp = c->hp - b->dano_inicial; //bezaliel usa habilidade
  83.  
  84.         i = i+1;
  85.     }
  86.    
  87.     if (c->hp <= 0)
  88.     {
  89.         return bez;
  90.     }
  91.     else
  92.     {
  93.         return clo;
  94.     }
  95.    
  96.    
  97.  
  98. }
  99.  
  100.  
  101.  
  102. int stat_scan (int n_battles) //recebe os inputs baseado no numero de batalhas
  103. {
  104.     if (n_battles <= 0)
  105.     {
  106.         return 42;
  107.     }
  108.     Pokemon clodes;
  109.     Pokemon bezaliel;
  110.  
  111.     double v1;
  112.     double v2;
  113.     double d1;
  114.     double d2;
  115.     scanf("%lf",&v1);
  116.     scanf("%lf",&v2);
  117.     scanf("%lf",&d1);
  118.     scanf("%lf",&d2);
  119.  
  120.     SetPokemon(&clodes,v1,d1); //&pega o endereΓ§o de clodes e escreve lΓ‘
  121.     SetPokemon(&bezaliel,v2,d2);
  122.  
  123.     int resultado = battle(&clodes,&bezaliel); //resultado da batalha
  124.  
  125.     if (resultado == bez)
  126.     {
  127.         printf("Bezaliel\n");
  128.     }
  129.     if (resultado == clo)
  130.     {
  131.         printf("Clodes\n");
  132.     }
  133.  
  134.     return stat_scan(n_battles-1);
  135.    
  136. }
  137.  
  138.  
  139. int main()
  140. {
  141.     int n_battles;
  142.     scanf("%d", &n_battles);
  143.     stat_scan(n_battles);
  144.     return 0;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement