[ create a new paste ] login | about

Link: http://codepad.org/XhStFj1R    [ raw code | fork ]

C, pasted on Jul 20:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct monsters{
    char name[16]; //名前
    int hp;        //ヒットポイント
    int ap;        //アタックポイント
    int gp;        //ガードポイント
	int sp;        //スピードポイント(※追加)
};

// (※追加)
enum {
	RUNAWAY_NG	= 0,
	RUNAWAY_OK,
};

// 0~9をランダムに返す
int rand_num() {
    int rnd;
    rnd = (int)((double)(rand()/(double)(0x7fffffff))*10);
    return rnd;
}

// hp, ap, gp に0~9をランダムで加算する
void addRndToMonster(struct monsters *mon)
{
    mon->hp += rand_num();
    mon->ap += rand_num();
    mon->gp += rand_num();
	mon->sp += rand_num();	// (※追加)
}

// モンスター情報を入力する
void inputMonster(struct monsters *mon)
{
    printf("モンスター名:");
    scanf("%s", mon->name);
    printf("ヒットポイント:");
    scanf("%d", &mon->hp);
    printf("アタックポイント:");
    scanf("%d", &mon->ap);
    printf("ガードポイント:");
    scanf("%d", &mon->gp);
    printf("スピードポイント:");	// (※追加)
    scanf("%d", &mon->sp);			// (※追加)
}

// モンスター情報を出力する
void printMonster(struct monsters *mon)
{
    printf(">>モンスター名:%s\n", mon->name);
    printf(">>ヒットポイント:%d\n", mon->hp);
    printf(">>アタックポイント:%d\n", mon->ap);
    printf(">>ガードポイント:%d\n", mon->gp);
	printf(">>スピードポイント:%d\n", mon->sp);	// (※追加)
}

// (※追加)
// 第二引数プレイヤーのスピードポイントよりも、
// モンスターのスピードが高ければ逃走成功
int IsRunAway(struct monsters *mon, int playerSp)
{
	if(mon->sp > playerSp)
	{
		return RUNAWAY_OK;
	}
	return RUNAWAY_NG;
}

int main(int argc, char* argv[])
{
    struct monsters mon;

    srand(time(NULL));

    // モンスターの情報を入力
    for (;;)
    {
        inputMonster(&mon);
		if ((mon.hp + mon.ap + mon.gp + mon.sp) != 100)
        {
            printf("ヒット+アタック+ガード+スピード=100になるように入力\n");
        }
        break;
    }
    putchar('\n');

    // 乱数を加える
    addRndToMonster(&mon);
    // モンスターの情報を表示する
    printMonster(&mon);

	while(1);

    return 0;
}


Create a new paste based on this one


Comments: