diff --git a/src/c/character.h b/src/c/character.h index 2afa7d4..d50b076 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -2,7 +2,8 @@ #define CHARACTER_H typedef struct { - int strength,dexterity,intelligence,healthPoints,manaPoints,level,exp,maxExp,attack,armor,maxHealthPoints,gold; + int strength,dexterity,intelligence,healthPoints,manaPoints,level,exp,maxExp; + int attack,armor,maxHealthPoints,gold; char name [50]; } Character; diff --git a/src/c/encounter.c b/src/c/encounter.c index b3440a0..8c820f7 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -29,15 +29,14 @@ bool playerAlive(Character *character) } } -int playerHeal(int health, int damage, Character* character) +int playerHeal(Character* character, int amount) { - int maxhealth = getCharacterMaxHealthPoints(character); - health = health + damage; - if (health > maxhealth) + setCharacterHealthPoints(character, getCharacterHealthPoints(character)+ amount); + if (getCharacterHealthPoints(character) > getCharacterMaxHealthPoints(character)) { - health = maxhealth; + setCharacterHealthPoints(character, getCharacterMaxHealthPoints(character)); } - return health; + return getCharacterHealthPoints(character); } int playerDamaged(int health, int damage, int armor, Character* character) @@ -96,7 +95,7 @@ int fight(Character *character, enemy* enemy) enemyDamaged(enemy, getCharacterAttack(character)); break; case 'h': - playerH = playerHeal(getCharacterHealthPoints(character), 10, character); + playerH = playerHeal(character,10); setCharacterHealthPoints(character, playerH); break; case 'f': diff --git a/src/c/encounter.h b/src/c/encounter.h index 68d0d71..4ae48ae 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -15,7 +15,7 @@ typedef struct enemy{ bool playerAlive(Character *character); -int playerHeal(int health, int damage, Character* character); +int playerHeal(Character* character,int amount); int playerDamaged(int health, int damage, int armor, Character* character); int rollInitiative (Character *character); void enemyHeal(enemy *enemy, int healAmount); diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index 49f25e8..3c33f55 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -14,6 +14,7 @@ void setUp(void) { testcharacter.dexterity = 5; testcharacter.healthPoints = 100; + testcharacter.maxHealthPoints = 100; } void teardown(void) @@ -60,15 +61,11 @@ void test_playerIsDamaged(void) void test_playerIsNotOverhealed(void) { // arrange - int health = 95; - int armor = 0; + setCharacterHealthPoints(&testcharacter, 95); int heal = 10; - int expectedHealth = 100; // act - Character testChar = {10,10,10,health,100,1,0,100,10,armor,100}; - health = playerHeal(health, heal, &testChar); // assert - TEST_ASSERT_EQUAL(expectedHealth, health); + TEST_ASSERT_EQUAL(getCharacterMaxHealthPoints(&testcharacter), playerHeal(&testcharacter,heal)); } void test_setEnemyHealth(void)