breakhack/src/stats.c

34 lines
723 B
C
Raw Normal View History

2017-12-15 08:08:45 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
2017-12-15 15:03:29 +01:00
#include <SDL2/SDL_ttf.h>
2017-12-15 08:08:45 +01:00
#include "stats.h"
2017-12-15 15:03:29 +01:00
unsigned int
2017-12-15 08:08:45 +01:00
stats_fight(Stats *attacker, Stats *defender)
{
unsigned int atkRoll, defRoll, dmgRoll;
bool critical = false;
srand(time(NULL));
atkRoll = (rand() % 20);
if (atkRoll == 20)
critical = true;
atkRoll += attacker->atk;
defRoll = (rand() % 20) + defender->def;
2017-12-15 15:03:29 +01:00
dmgRoll = 0;
2017-12-15 08:08:45 +01:00
2017-12-15 15:03:29 +01:00
//printf("Attacking: %u, Defending: %u\n", atkRoll, defRoll);
2017-12-15 08:08:45 +01:00
if (atkRoll > defRoll) {
dmgRoll = (rand() % 8) + attacker->dmg;
defender->hp -= dmgRoll;
if (critical)
defender->hp -= dmgRoll;
}
2017-12-15 15:03:29 +01:00
//printf("Attacker hp: %u, Defender hp: %u\n", attacker->hp, defender->hp);
return dmgRoll;
2017-12-15 08:08:45 +01:00
}