From 133c4fe8c3c4d11e91532f5b3a6d850944e7c336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos?= Date: Fri, 13 Jan 2023 20:42:56 +0100 Subject: [PATCH] refactoring: replaced getter func w universal func --- src/c/encounter.c | 15 +-------------- src/c/encounter.h | 4 +--- test/c/test_encounter.c | 6 +++--- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/c/encounter.c b/src/c/encounter.c index 29678c8..5ee3f85 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -30,7 +30,7 @@ int playerHealth(int health, int damage){ } int enemyDamaged(enemy enemy, int damage){ - int armor = getEnemyArmor(enemy); + int armor = getEnemyInt(&enemy.armor); int damagedealt = damage - armor; if(damagedealt < 1){ damagedealt = 1; @@ -47,27 +47,14 @@ void *setEnemyHealth(int *num, int health){ //return health; } -int getEnemyHealth(enemy enemy){ - //gibt health zurück, benötigt keine adress pointer - return enemy.health; -} - void *setEnemyDamage(int *num, int damage){ *num = damage; } -int getEnemyDamage(enemy enemy){ - return enemy.damage; -} - void *setEnemyArmor(int *num, int armor){ *num = armor; } -int getEnemyArmor(enemy enemy){ - return enemy.armor; -} - int getEnemyInt(int *structParam){ return *structParam; } diff --git a/src/c/encounter.h b/src/c/encounter.h index 0beafea..d6ddb68 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -21,13 +21,11 @@ int enemyDamaged(enemy enemy, int damage); //setEnemyHealth(&enemy.health, health); void *setEnemyHealth(int *num, int health); -int getEnemyHealth(enemy enemy); + //setEnemyDamage(&enemy.damage, damage); void *setEnemyDamage(int *num, int damage); -int getEnemyDamage(enemy enemy); //setEnemyArmor(&enemy.armor, armor); void *setEnemyArmor(int *num, int damage); -int getEnemyArmor(enemy enemy); //Function to get the value of Data in a struct, needs a pointer to the struct int getEnemyInt(int *structParam); diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index e68f866..f6782dd 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -59,7 +59,7 @@ void test_getEnemyHealth(void){ int health = 50, result; //act enemy test = {health}; - result = getEnemyHealth(test); + result = getEnemyInt(&test.health); //assert TEST_ASSERT_EQUAL(health, result); } @@ -74,7 +74,7 @@ void test_setEnemyDamage(void){ void test_getEnemyDamage(void){ int damage = 4, result; enemy test = {50, damage}; - result = getEnemyDamage(test); + result = getEnemyInt(&test.damage); TEST_ASSERT_EQUAL(damage, result); } @@ -82,7 +82,7 @@ void test_get_setEnemyArmor(void){ int armor = 4, result; enemy test = {50, 4, armor*2}; setEnemyArmor(&test.armor, armor); - result = getEnemyArmor(test); + result = getEnemyInt(&test.armor); TEST_ASSERT_EQUAL(armor, result); }