日記の切れ端

何か思いついたら書く。

学生時代に作ったゲームのソースコード

資料整理してたらふるーいソース出てきたのでここに残す

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

#define KIZUGUSURI 5
#define MONSTER 5

short input_1,input_2,random,par,W;
short damage=0,command=0,game=0,myturn=0,next;
short mo_code;
short win=0;

struct charactor
{
    char name[20];
    char level;
    short hp,kou,bou,spd;
    short par_kou,turn;
    short item_01;
};


    struct charactor *po_mo,*po_pl;

    struct charactor player = 
        {"主人公",1,50,5,3,3,4,1,5};

    struct charactor monster[MONSTER] = 
    {
        {"ゴブリン"  ,1,30,5,3,3,4,1,3},
        {"スライム"  ,1,20,4,4,4,6,1,2},
        {"フライ"    ,1,25,4,3,6,4,2,0},
        {"マイコニド",1,30,3,6,3,8,1,0},
        {"怪魚"      ,1,15,7,4,5,4,2,0}
    };


struct challenger
{
    short level;
    short hp,kou,bou,spd;
    short turn;
    short item_01;
};

struct challenger vs_pl;
struct challenger vs_mo;

short attack_check(short,short,short);
void attack();
void item1();
void entory();


void main(void)
{
    for(;;)
    {
        while(!game)
        {
            printf("the VSゲーム\n");
            printf("1:ゲームを始める\n");
            scanf("%d",&input_1);
            switch(input_1)
            {
                case 1:
                    game=1;
                    break;
                default:
                    printf("\n\n\n");
                    break;
            }
            win=0;
        }
        while(game)
        {
            entory();   
            printf("%s",po_mo->name);
            printf("が現れた!!\n");
            next=0;

            while(game && !next)
            {
                vs_pl.turn = po_pl -> turn;
                vs_mo.turn = po_mo -> turn;
                while(command==0)
                {
                    printf("\n[あなた HP:%d/%d] ",vs_pl.hp,po_pl -> hp);
                    printf("[%s HP:%d/%d]\n\n",po_mo->name,vs_mo.hp,po_mo->hp);
                    printf("どうしますか \n 1:戦う 2:アイテム 3:ステータス 4:逃げる\n>");
                    scanf("%d",&input_1);
            /***    コマンド入力  ***/
                    switch(input_1)
                    {
                        case 1:         /*戦う*/
                            input_1 = 1;
                            command=1;
                            break;
                        case 2:/*アイテム*/
                            input_1 = 2;
                            printf("何を使いますか?\n");
                            if(vs_pl.item_01)
                            {
                                printf("1:傷薬        ×%d\n",vs_pl.item_01);
                            }
                            printf("0:キャンセル\n");
                            scanf("%d",&input_2);/*アイテムに行かない原因*/
                            switch(input_2)
                            {
                                case 1:     /*傷薬*/
                                    input_2 = 1;
                                    if(vs_pl.item_01)
                                    {   command=1;  }
                                    else
                                    {   printf("\n");   }
                                    break;  

                                case 0:     /*キャンセル*/
                                    printf("\n\n");
                                    break;  
    
                                default :
                                    printf("\n");
                            }
                            break;
                        case 3:         /*ステータス*/
                            printf("レベル :%d",po_pl -> level);
                            printf("攻撃力 :%d  防御力 :%d \n素早さ :%d",vs_pl.kou,vs_pl.bou,vs_pl.spd);
                            printf(" 現在%d連勝中\n",win);
                            break;
                        case 4:         /*逃げる*/
                            command=1;
                            break;
    
                        default :
                            printf("\n");
                            break;
                    }
                }
                command=0;

/************************/
/*      戦闘シーン     */
/************************/
                while(game)
                {
                    while(vs_pl.turn || vs_mo.turn)
                    {
/*自分のターン*/      if((vs_pl.turn && (vs_pl.spd  > vs_mo.spd)) || !vs_mo.turn)
                        {
                            W = 0;
                            myturn=1;
                            switch(input_1)
                            {
                                case 1: /*戦う*/
                                    attack();
                                    break;
                                case 2: /*アイテム*/
                                    printf("abd");
                                    switch(input_2)
                                    {
                                        case 1:     /*傷薬*/
                                            item1();
                                            break;
                                        default:
                                            printf("cckc");
                                    }
                                    break;
                                case 4:/*逃げる*/
                                    srand(time(NULL));
                                    random = (rand()%10 + (po_pl -> par_kou));
                                    if(random >= 10)
                                    {
                                        printf("は逃げ出した…\n");
                                        vs_pl.turn = vs_mo.turn = 0;
                                        game=0;
                                    }
                                    else
                                    {
                                        printf("\nあなたは逃げるのに失敗した…\n");
                                    }
                                    break;
                                default:
                                    printf("miss");
                            }
                            vs_pl.turn--;
                            myturn=0;
                        }

        /*敵のターン*/

                        else{
                            if(vs_mo.turn)
                            {
                                if(vs_mo.hp <= po_mo -> hp - KIZUGUSURI && vs_mo.item_01)
                                {
                                    item1();
                                }
                                else 
                                {
                                    attack();
                                }
                                vs_mo.turn--;
                                W = 1;              
                            }
                        }
                        if(vs_pl.hp<=0 && game)
                        {
                            printf("あなたの負け…\n\n\n\n\n\n");
                            vs_pl.turn = vs_mo.turn = 0;
                            game=0;
                        }
                        if(vs_mo.hp <= 0 && game)
                        {
                            printf("あなたの勝利!!\n\n");
                            vs_pl.turn = vs_mo.turn = 0;
                            win++;
                            next=1;
                        }
                    }
                break;
                }
            }
        }
    }
}


short attack_check(short kou,short bou,short kakuritu)
{
    short damage=0,lucky=0;
    srand(time(NULL));
    lucky=(rand()%10)+kakuritu;
    if(lucky>=10)
    {
        par = 1;
        damage += (kou-1)/2+1;
    }
    damage+=kou-bou;
    if(damage<=0)
    {
        srand(time(NULL));
        random = (rand()%10);
        if(random <=5)
            damage=1;
        else
            damage=0;
    }
    return damage;
}

void attack()
{
    if(myturn)
    {
        damage = attack_check(vs_pl.kou,vs_mo.bou,po_pl->par_kou);
        if(W)
        {
            printf("\n連続攻撃!!\n");
        }
        else
        {
            printf("%sの攻撃!!\n",player.name);
        }
        if(damage)
        { 
            if(par)
            printf("会心の一撃!!\n");
            printf("%sに%dポイントのダメージを与えた!!\n\n",po_mo->name,damage);
            vs_mo.hp -= damage;
        }   
        else
        {
            printf("しかし、失敗に終わった…");
        }
        par = 0;
    }
    else
    {
        damage=attack_check(vs_mo.kou,vs_pl.bou,po_mo -> par_kou);
        printf("%sの攻撃!!\n",po_mo -> name);
        if(damage)
        { 
            if(par)
            printf("痛恨の一撃!!\n");
            printf("%sは%dポイントのダメージを受けた!!\n\n",po_pl -> name,damage);
            vs_pl.hp -= damage;
        }
        else
        {
            printf("しかし、失敗に終わった…");
        }
    }

}
void item1()
{
    if(myturn)
    {
        printf("%s",po_pl->name);
    }
    else
    {
        printf("%s",po_mo->name);
    }
    printf("は『傷薬』を使った!!\n");
    printf("HPが回復した!!\n");
    if(myturn)
    {
        vs_pl.hp += KIZUGUSURI;
        vs_pl.item_01--;
        if((po_pl -> hp) < vs_pl.hp)
        {
            vs_pl.hp = (po_pl -> hp);
        }
    }
    else
    {
        vs_mo.hp += KIZUGUSURI;
        vs_mo.item_01--;
        if(po_mo -> hp < vs_mo.hp)
        {
            vs_mo.hp = po_mo -> hp;
        }
    }
}

void entory()
{
    if(!win)
    {
        po_pl = &player;
        vs_pl.level = po_pl -> level;
        vs_pl.hp = po_pl -> hp;
        vs_pl.kou = po_pl -> kou;
        vs_pl.bou = po_pl -> bou;
        vs_pl.spd = po_pl -> spd;
        vs_pl.turn = po_pl -> turn;
        vs_pl.item_01 = po_pl -> item_01;
    }
    srand(time(NULL));
    mo_code=(rand()% MONSTER);
    po_mo = &monster[mo_code];

    vs_mo.hp = po_mo -> hp;
    vs_mo.kou = po_mo -> kou;
    vs_mo.bou = po_mo -> bou;
    vs_mo.spd = po_mo -> spd;
    vs_mo.turn = po_mo -> turn;
    vs_mo.item_01 = po_mo -> item_01;
}