int intelligence(){
srand(time(NULL));
int poption;
int moption;
int phits, mhits;
int pdam, mdam;
int escape = 0;
if(hp <= 0){
    mhp = 30;
    printf("You lost\n");
    gameworld();
}
if(mhp <= 0){
    printf("You won\n");
    mhp = 30;
    exp += 1;
    player();
}
printf("Chose your action:\n 1.Attack 2.Magic attack\n");
scanf("%d", &poption);
//How many hits
phits = agi / 3;
//Damage done by normal attack
if (poption == 1){
    (phits == 1)?
    printf("You have hit once\n"):printf("You have hit %d times\n", phits);
    //Damage amount
    pdam = str * phits;
    mhp -= (pdam - mdef);
    printf("Monsters health is:%d\n", mhp);
}
else if (poption == 2){
    //Damage done by magic attack
    mhp -= (mp - mmp);
}
if(mhp <= 0){
    printf("You won\n");
    exp += 1;
    mhp = 30;
    player();
}
    if (mhp > 0){
        moption = rand() % 2;
        if (moption == 0 || moption == 1){
            hp = hp - (mstr - def);
            printf("Your current health is: %d\n", hp);
            escape++;
            intelligence();
        }
        if (moption == 2 && escape == 0 ){
            printf("Monster has escaped\n");
            gameworld();
        }
    }



}
void weaponready(){
srand(time(NULL));
int weapon = rand() % 1;
int damage = 0, atspeed = 0;
int ice = 0, fire = 0;

  HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
  WORD wOldColorAttrs;
  CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  GetConsoleScreenBufferInfo(h, &csbiInfo);
  wOldColorAttrs = csbiInfo.wAttributes;

if(weapon == 0){
    printf("You got: \n");
    SetConsoleTextAttribute ( h, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
    printf("Glory sword\n");
    damage = 14;
    atspeed = 13;
    ice = 12;
    fire = 0;
    SetConsoleTextAttribute ( h, wOldColorAttrs);
    printf("Damage:%d\n", damage);
    printf("Attack Speed:%d\n", atspeed);
    printf("Ice damage:%d\n", ice);
    printf("Fire damage:%d\n\n", fire);
    gameworld();
}
else if (weapon == 1){
    printf("You got: \n");
    SetConsoleTextAttribute ( h, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
    printf("Glory axe\n");
    damage = 13;
    atspeed = 14;
    ice = 0;
    fire = 12;
    SetConsoleTextAttribute ( h, wOldColorAttrs);
    printf("Damage:%d\n", damage);
    printf("Attack Speed:%d\n", atspeed);
    printf("Ice damage:%d\n", ice);
    printf("Fire damage:%d\n\n", fire);
    gameworld();
}

}
Beispiel #3
0
void UnitPosition::update(const int deltaMs)
{
  TilePos oldP = _tilePosition;
  EntityPosition::update(deltaMs);
  if(oldP != _tilePosition)
  {
    EntityMap& eMap = gameworld().entityMap();
    eMap.eraseUnit(oldP);
    eMap.registerUnit(_tilePosition, entityId());
  }
}
int itemgenerator(){
    //Need to find better way of generating random numbers
srand(time(NULL));
int weapontype = rand() % 10;
int sword = 0, axe = 0;
int noitem = 0;
int damage = 0, atspeed = 0;
int type = 0;
int ice = 0, fire = 0;

  HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
  WORD wOldColorAttrs;
  CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  GetConsoleScreenBufferInfo(h, &csbiInfo);
  wOldColorAttrs = csbiInfo.wAttributes;

if(weapontype == 0 || weapontype == 1 || weapontype == 2  || weapontype == 3){
    sword++;
}
else if (weapontype == 4 || weapontype == 5 || weapontype == 6  || weapontype == 7){
    axe++;
}
else if(weapontype == 8 || weapontype == 9){
    noitem++;
}
else if(weapontype == 10){
    weaponready();
}

if(sword == 1){
    printf("You got: \n");
    type = (rand() % 3);
        if(type == 1){
        SetConsoleTextAttribute ( h, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
        printf("Ice ");
         ice = (rand() % 7) + 1;
    }
    if (type == 2){
  SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
        printf("Fire ");
        fire = (rand() % 7) + 1;
    }
    (type == 1 || type == 2)?
    printf("sword \n"):printf("Sword \n");
    SetConsoleTextAttribute ( h, wOldColorAttrs);
    //Chances of damage stat
    damage = (rand() % 7) + 1;
    printf("Damage:%d\n", damage);
    //Chances of speed stat
    atspeed = (rand() % 10) + 1;
    printf("Attack Speed:%d\n", atspeed);
    printf("Ice damage:%d\n", ice);
    printf("Fire damage:%d\n\n", fire);

}

else if(axe == 1){
    printf("You got: \n");
    type = (rand() % 3);
    if(type == 1){
        SetConsoleTextAttribute ( h, FOREGROUND_BLUE | FOREGROUND_INTENSITY );
        printf("Ice ");
         ice = (rand() % 7) + 1;
    }

    if (type == 2){
        SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
        printf("Fire ");
        fire = (rand() % 7) + 1;
    }
    (type == 1 || type == 2)?
    printf("axe \n"):printf("Axe \n");
    SetConsoleTextAttribute ( h, wOldColorAttrs);
    damage = (rand() % 10) + 1;
    printf("Damage:%d\n", damage);
    atspeed = (rand() % 7) + 1;

    printf("Attack Speed:%d\n", atspeed);
    printf("Ice damage:%d\n", ice);
    printf("Fire damage:%d\n\n", fire);
}
else if(noitem == 1){
    printf("Nothing was dropped\n\n");
}


gameworld();

}