Untitled

 avatar
unknown
c_cpp
5 months ago
2.0 kB
4
Indexable
#include <stdio.h>
#include "function.h"

Cat* newCatType(){

    Cat *newcat=(Cat *)malloc(sizeof(Cat));
    newcat->catName=(char *)malloc(30);
    char name[30];
    scanf("%s",name);
    strcpy(newcat->catName,name);
    scanf("%d %d %d",&newcat->attackPower,&newcat->attackSpeed,&newcat->levelUpTime);

    return newcat;
}




Monster* buildMonster(){

    Monster *mon=(Monster *)malloc(sizeof(Monster));
    scanf("%d %d %d %d",&mon->hp,&mon->skill_1_CooldownTime,&mon->skill_2_CooldownTime,&mon->skill_2_Duration);
    return mon;

}

Battlefield* newCat(Cat **catTypes, int currentTime){

    Battlefield *newkitty=(Battlefield*)malloc(sizeof(Battlefield));
    int type;
    scanf("%d",&type);
    newkitty->catLevel=1;
    newkitty->cat=(Cat*)malloc(sizeof(Cat));
    newkitty->cat->attackPower=catTypes[type]->attackPower;
    newkitty->cat->attackSpeed=catTypes[type]->attackSpeed;
    newkitty->cat->levelUpTime=catTypes[type]->levelUpTime;
    newkitty->cat->catName=(char *)malloc(30);
    strcpy(newkitty->cat->catName,catTypes[type]->catName);

    return newkitty;
}

void skill_1(Battlefield *battlefield[], Monster *monster, int currentTime){

    int count=0;
    for(int i=0;i<currentTime;i++){

        if(battlefield[i]!=NULL){
            battlefield[i]->catLevel=battlefield[i]->catLevel-1;
            count++;
        }
    }

    monster->hp=monster->hp+100*count;

}

void skill_2(Battlefield *battlefield[], Monster *monster, int currentTime){

    for(int i=currentTime;i<currentTime+monster->skill_2_Duration;i++){
        for(int j=0;i<currentTime;j++){
            if(battlefield[j]!=NULL){
                if(i%battlefield[j]->cat->attackSpeed == 0){
                monster->hp=monster->hp+battlefield[j]->cat->attackPower;
                }
            }
        }
    }

}

Battlefield* deleteCat(Battlefield *battlefield){

    free(battlefield->cat->catName);

    free(battlefield->cat);

    free(battlefield);

    return NULL;

}
Editor is loading...
Leave a Comment