diff --git a/src/c/encounter.c b/src/c/encounter.c index 80559ba..13859b5 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -130,7 +130,9 @@ int fight(Character *character, enemy* enemy) } } - +int rollInitiative (Character *character) { + return randomIntRange(1,20) + character->dexterity; +} bool enemyChoosesHeal(enemy* enemy) { diff --git a/src/c/encounter.h b/src/c/encounter.h index 4a2c1ff..d181d37 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -17,6 +17,7 @@ typedef struct enemy{ bool playerAlive(int health); int playerHeal(int health, int damage, Character* character); int playerDamaged(int health, int damage, int armor, Character* character); +int rollInitiative (Character *character); void enemyHeal(enemy *enemy, int healAmount); void enemyDamaged(enemy* enemy, int damage); bool enemyChoosesHeal(enemy* enemy); diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index 023d470..f92bf32 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -9,9 +9,10 @@ #include "mock_helper.h" #include "utils.h" - +Character testcharacter; void setUp(void) { + testcharacter.dexterity = 5; } void teardown(void) @@ -395,5 +396,7 @@ void test_enemyHealsNoPotion(void) TEST_ASSERT_FALSE(result); } - +int test_rollInitiative (void) { + TEST_ASSERT(testcharacter.dexterity + 1 <= rollInitiative(&testcharacter) && testcharacter.dexterity + 20 >= rollInitiative(&testcharacter)); +} #endif // TEST