diff --git a/src/c/encounter.c b/src/c/encounter.c index 13859b5..b3440a0 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -17,9 +17,9 @@ humanoide gegner haben heiltränke mit denen sie sich ggf heilen. heilung erfolgt dann, wenn bestimmte hp (50%) unterschritten wird. wird allerdings gewürfelt, je niedriger die hp%, desto höher die chance. */ -bool playerAlive(int health) +bool playerAlive(Character *character) { - if (health > 0) + if (getCharacterHealthPoints(character) > 0) { return true; } @@ -86,7 +86,7 @@ int fight(Character *character, enemy* enemy) int playerH = 0; int currentTurn = 2; char decision; - while (playerAlive(getCharacterHealthPoints(character)) && getEnemyHealth(enemy) > 0) + while (playerAlive(character) && getEnemyHealth(enemy) > 0) { if (currentTurn != 1) { @@ -118,7 +118,7 @@ int fight(Character *character, enemy* enemy) } currentTurn = switchTurns(currentTurn); } - if (playerAlive(getCharacterHealthPoints(character))) + if (playerAlive(character)) { setCharacterExp(character, getCharacterExp(character) + getEnemyExp(enemy)); setCharacterGold(character, getCharacterGold(character) + getEnemyGold(enemy)); diff --git a/src/c/encounter.h b/src/c/encounter.h index d181d37..68d0d71 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -14,7 +14,7 @@ typedef struct enemy{ } enemy; -bool playerAlive(int health); +bool playerAlive(Character *character); int playerHeal(int health, int damage, Character* character); int playerDamaged(int health, int damage, int armor, Character* character); int rollInitiative (Character *character); diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index f92bf32..49f25e8 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -13,6 +13,7 @@ Character testcharacter; void setUp(void) { testcharacter.dexterity = 5; + testcharacter.healthPoints = 100; } void teardown(void) @@ -25,7 +26,7 @@ void test_isPlayerAlive_healthGreaterZero(void) int health = 100; bool result; // act - result = playerAlive(health); + result = playerAlive(&testcharacter); // assert TEST_ASSERT_TRUE(result); } @@ -33,10 +34,10 @@ void test_isPlayerAlive_healthGreaterZero(void) void test_isPlayerAlive_healthLowerZero(void) { // arrange - int health = -1; + setCharacterHealthPoints(&testcharacter, -1); bool result; // act - result = playerAlive(health); + result = playerAlive(&testcharacter); // assert TEST_ASSERT_FALSE(result);