#include #include #include typedef struct character{ char name[20]; //キャラクタ名 int syuzokuchi; //種族値 int kotaichi; //個体値 int doryokuchi; //努力値 int Offense; //攻撃力 int Defense; //防御力 }character; typedef struct level{ struct character *pokemon; int level; //レベル int HP; //HP }level; double calc_nouryoku(character *x, level *y); void battle(character *x1, level *y1, character *x2, level *y2); int main(int argc, char *argv[]){ int n; //キャラクタ数 character *c; level *l; int i, j; int p1, p2; //戦うキャラクタ int win=0; //勝った回数 srand((unsigned)time(NULL)); //キャラクタ数を入力 printf("キャラクタ数を入力してください:\n"); scanf("%d", &n); //変数c,lのメモリをmallocで確保 c = (struct character *) malloc (sizeof(struct character)*n); l = (struct level *) malloc (sizeof(struct level)*n); //各キャラクタのステータスを入力 printf("以下を入力してください。\n"); printf("あなたのキャラクタ名:"); scanf("%s", c[0].name); printf(" 種族値:"); scanf("%d", &c[0].syuzokuchi); printf(" 個体値:"); scanf("%d", &c[0].kotaichi); printf(" 努力値:"); scanf("%d", &c[0].doryokuchi); for(i=1; i= 0){ printf("やせいの%sが現れた!\n", c[p2].name); printf("たたかう>0\n"); printf("にげる>1\n"); scanf("%d", &j); if(j == 0){ battle(&c[p1], &l[p1], &c[p2], &l[p2]); }else if(j == 1){ win--; } } } //結果を表示 printf("最終結果\n"); printf("%d人倒しました!\n", win + p2 -1); if(win == 0){ printf("ノルマクリア達成!おめでとうございます!\n"); } } double calc_nouryoku(character *x, level *y){ return (double)(x->syuzokuchi*2 + x->kotaichi + x->doryokuchi/4) * y->level / 100 + y->level + 10; } void battle(character *x1, level *y1, character *x2, level *y2){ double nofp1, nofp2; nofp1 = calc_nouryoku(x1, y1); nofp2 = calc_nouryoku(x2, y2); int i=0; int damage; printf("%s (能力値:%.2f) vs %s (能力値%.2f)\n", x1->name, nofp1, x2->name, nofp2); while(1){ printf("レベル:%d HP:%d レベル:%d HP:%d\n", y1->level, y1->HP, y2->level, y2->HP); if(i%2 == 0){ printf("%sのこうげき\n", x1->name); damage = x1->Offense * nofp1 - x2->Defense * nofp2; printf("%sは%dのダメージを受けた!\n", x2->name, damage); y2->HP -= damage; i++; if(y2->HP <= 0){ printf("%sの勝利!\n", x1->name); printf("%sのレベルが1上がった!\n", x1->name); break; } }else{ printf("%sのこうげき\n", x2->name); damage = x2->Offense * nofp2 - x1->Defense * nofp1; printf("%sは%dのダメージを受けた!\n", x1->name, damage); y1->HP -= damage; i++; if(y1->HP <= 0){ printf("GAME OVER\n"); break; } } } /* if(nofp1 > nofp2){ printf("勝者 : %s\n", x1->name); y1->level ++; printf("%sのレベルが%dに上がりました。\n", x1->name, y1->level); y1->win ++; y2->lose ++; }else if(nofp1 < nofp2){ printf("勝者 : %s\n", x2->name); y2->level += 1; printf("%sのレベルが%dに上がりました。\n", x2->name, y2->level); y1->lose ++; y2->win++; }else{ printf("引き分けです\n"); } */ }