Пример #1
0
int main(int argc, char** argv)
{
    struct character_t me, orc;

    char name[NAME_MAX];
    sprintf(name, "Metiscus");

    char* username = getenv("USER");
    if(username)
    {
        if(isalpha(username[0]))
        {
            username[0] = toupper(username[0]);
        }
        sprintf(name, "%s", username);
    }

    char_create(&orc, "Munkres", R_Human);
    orc.skills[SK_Concentration] = 10;
    orc.weapon_id = 2; // bo staff
    char_add_inventory(&orc, object_create(5));

    char_create(&me, name, R_Elf);
    me.weapon_id = 1; // katana
    me.skills[SK_Blade] = 10;

    srand(time(0));

    int j;
    int meWins = 0;
    int trials = 1000;
    for(j=0; j<trials; ++j)
    {
        me.vitals.value[0] = me.vitals.max[0];
        orc.vitals.value[0] = orc.vitals.max[0];

        for( ; ; )
        {
            //printf("Me: %d\tOrc: %d\n", me.vitals.value[0], orc.vitals.value[0]);
            combat_round(&me, &orc);

            // If the ORC health is near critical have him chug a potion
            unsigned criticalHealth = orc.vitals.max[0] / 2 + 1;

            unsigned canAttack = 1;
            if((orc.vitals.value[0] <= criticalHealth) && (orc.inventory_count > 0))
            {
                // look for a potion to use
                unsigned item = 0;
                for(item=0; item<orc.inventory_count; ++item)
                {
                    struct object_t *pObj = orc.inventory[item];
                    if(pObj->type == obj_consumable && pObj->consumable.type == con_potion)
                    {
                        // we have a potion
                        // Check for charges and then use it!
                        if(pObj->consumable.charge_qty > 0)
                        {
                            char_consumable_apply(&orc, pObj);
                            canAttack = 0;
                            break;
                        }
                    }
                }
            }

            if(canAttack)
            {
                combat_round(&orc, &me);
            }

            if(me.vitals.value[0]<=0 || orc.vitals.value[0]<=0)
            {
                meWins += (me.vitals.value[0]<=0) ? 0 : 1;
                printf("Battle complete!\n");
                if(me.vitals.value[0]>0)
                {
                    char_add_inventory(&orc, object_create(1));
                }
                break;
            }
        }
        //printf("Me: %d\tOrc: %d\n", me.vitals.value[0], orc.vitals.value[0]);
    }

    char_explain(&me);
    char_explain(&orc);

    printf("Final result: me %d, Orc %d\n", meWins, trials - meWins);

    test_resourcemgr();

    return 0;
}
Пример #2
0
////////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS
////////////////////////////////////////////////////////////////////////////////
void game_create() {
  map_create();
  char_create();
}