Browse Source

refactoring: changed player Alive function parameters to struct character

remotes/origin/thirdcycle
Kai Kehres 2 years ago
parent
commit
6b0a6f6f64
  1. 8
      src/c/encounter.c
  2. 2
      src/c/encounter.h
  3. 7
      test/c/test_encounter.c

8
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));

2
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);

7
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);

Loading…
Cancel
Save