Untitled

 avatar
unknown
c_cpp
2 years ago
1.5 kB
5
Indexable
#include"function.h"
#define max(a, b) ((a>b) ? a : b)
#define min(a, b) ((a<b) ? a : b)

void attk(Pokemon *A, Pokemon *B);

// TODO: upgrade and recover the PokĂŠmon
void level_up(Pokemon *P){
    if(P->level < 5){
        P->level++;
        P->attack += lvup_atk, P->defense += lvup_dfn;
        P->maxHp += lvup_maxHp, P->maxMp += lvup_maxMp;
    }
    P->Hp = P->maxHp, P->Mp = P->maxMp;  

}

// TODO: simulate and print the process of the battle
void battle(Pokemon *A, Pokemon *B){
    // printf("%s hp %d mp %d\n%s hp %d mp %d\n", A->name, A->Hp, A->Mp, B->name, B->Hp, B->Mp);

    long long round = 0, atkr, dfnr;
    Pokemon* P[2] = {A, B};
    while(P[0]->Hp > 0 && P[1]->Hp > 0){

        atkr = round % 2, dfnr = (round + 1) % 2;
        P[atkr]->Mp = min((P[atkr]->Mp)+T, P[atkr]->maxMp);
        attk(P[atkr], P[dfnr]);
        round++;
    }

    if(A->Hp == B->Hp) puts("Draw.\n");
    else if(A->Hp < B->Hp) printf("%s is the winner! %s died in vain...\n\n", B->name, A->name);
    else if(A->Hp > B->Hp) printf("%s is the winner! %s died in vain...\n\n", A->name, B->name);
}

void attk(Pokemon *A, Pokemon *B){
    
    if(A->Mp < A->costMp){
        A->Mp += T;
        printf("%s use Rest!\n%s now has %d MP.\n", A->name, A->name, A->Mp);
    }
    else{
        
        int dmg = (2 * A->level * max(A->attack - B->defense, 0)) / 100;
        A->Mp -= A->costMp;
        B->Hp = max(B->Hp - dmg, 0);
        printf("%s used Headbutt!\n%s now has %d HP.\n", A->name, B->name, B->Hp);
    }
}
Editor is loading...