#include #define CLOUD_HP 4000 #define CLOUD_ATK 2400 #define SEPHIROTH_HP 6000 #define SEPHIROTH_ATK 1200 /* ステータス用構造体 */ struct status { char *cName; int iHp; int iAtk; }; //void knsCloud(int *piSephiroth); //void knsSephiroth(int *piCloud); void knsAttack(struct status *psOwn, struct status *psEnemy); int i_main(void) { /* HPだけ設定する方法 */ //int iCloud = CLOUD_HP; //int iSephiroth = SEPHIROTH_HP; struct status sCloud, *psCloud; /* クラウドのステータス */ struct status sSephiroth, *psSephiroth; /* セフィロスのステータス */ /* クラウドのステータス設定 */ psCloud = &sCloud; psCloud->cName = "クラウド"; /* 名前の設定(文字列定数の代入) */ psCloud->iHp = CLOUD_HP; /* HPの設定 */ psCloud->iAtk = CLOUD_ATK; /* 攻撃力の設定 */ /* セフィロスのステータス設定 */ psSephiroth = &sSephiroth; psSephiroth->cName = "セフィロス"; psSephiroth->iHp = SEPHIROTH_HP; psSephiroth->iAtk = SEPHIROTH_ATK; /* 戦闘開始 */ while(1) { //printf("HP: クラ:%d セフ:%d\n", iCloud, iSephiroth); printf("HP: クラ:%d セフ:%d\n", psCloud->iHp, psSephiroth->iHp); /* セフィロスのターン */ //knsSephiroth(&iCloud); knsAttack(psSephiroth, psCloud); //if (iCloud->iHp < 0) if (psCloud->iHp < 0) { printf("クラウドは力尽きた・・・\n"); break; } else { printf("\n"); } /* クラウドのターン */ //knsCloud(&iSephiroth); knsAttack(psCloud, psSephiroth); //if (iSephiroth < 0) if (psSephiroth->iHp < 0) { printf("セフィロスは力尽きた・・・\n"); break; } else { printf("\n"); } } return 0; } /* クラウドの攻撃 */ /* void knsCloud(int *piSephiroth) { printf("クラウドの攻撃: "); *piSephiroth -= CLOUD_ATK; printf("セフィロスに%dのダメージ!\n", CLOUD_ATK); } */ /* セフィロスの攻撃 */ /* void knsSephiroth(int *piCloud) { printf("セフィロスの攻撃: "); *piCloud -= SEPHIROTH_ATK; printf("クラウドに%dのダメージ!\n", SEPHIROTH_ATK); } */ /* 攻撃関数 */ void knsAttack(struct status *psOwn, struct status *psEnemy) { printf("%sの攻撃: ", psOwn->cName); psEnemy->iHp -= psOwn->iAtk; printf("%sに%dのダメージ!", psEnemy->cName, psOwn->iAtk); }