Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
2.5 kB
1
Indexable
Never
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;
    }
}

void battle(Pokemon *A, Pokemon *B)
{
    if (A->Hp == 0 && B->Hp == 0)
    {
        puts("Draw.\n");
        puts("");
        return;
    }
    else if (A->Hp == 0)
    {
        printf("%s is the winner! %s died in vain...\n", B->name, A->name);
        puts("");
        return;
    }
    else if (B->Hp == 0)
    {
        printf("%s is the winner! %s died in vain...\n", A->name, B->name);
        puts("");
        return;
    }

    while (1)
    {
        int Dam = 0;

        A->Mp += T;
        if (A->Mp > A->maxMp)
            A->Mp = A->maxMp;

        if (A->Mp >= A->costMp)
        {
            A->Mp -= A->costMp;
            Dam = 2 * A->level * max(A->attack - B->defense, 0) / 100;
            B->Hp -= Dam;

            if (B->Hp <= 0)
            {
                B->Hp = 0;
                printf("%s used Headbutt!\n", A->name);
                printf("%s now has %d HP.\n", B->name, B->Hp);
                printf("%s is the winner! %s died in vain...\n", A->name, B->name);
                puts("");
                return;
            }
            printf("%s used Headbutt!\n%s now has %d HP.\n", A->name, B->name, B->Hp);
        }
        else
        {
            A->Mp += T;
            printf("%s used Rest!\n%s now has %d MP.\n", A->name, A->name, A->Mp);
        }

        B->Mp += T;
        if (B->Mp > B->maxMp)
            B->Mp = B->maxMp;
        if (B->Mp >= B->costMp)
        {
            B->Mp -= B->costMp;
            Dam = 2 * B->level * max(B->attack - A->defense, 0) / 100;
            A->Hp -= Dam;

            if (A->Hp <= 0)
            {
                A->Hp = 0;
                printf("%s used Headbutt!\n", B->name);
                printf("%s now has %d HP.\n", A->name, A->Hp);
                printf("%s is the winner! %s died in vain...\n", B->name, A->name);
                puts("");
                return;
            }
            printf("%s used Headbutt!\n%s now has %d HP.\n", B->name, A->name, A->Hp);
        }
        else
        {
            B->Mp += T;
            printf("%s used Rest!\n%s now has %d MP.\n", B->name, B->name, B->Mp);
        }
    }
}

int max(int a, int b)
{
    return a > b ? a : b;
}