Browse Source

refactoring: replaced getter func w universal func

remotes/origin/encounter
János 2 years ago
parent
commit
133c4fe8c3
  1. 15
      src/c/encounter.c
  2. 4
      src/c/encounter.h
  3. 6
      test/c/test_encounter.c

15
src/c/encounter.c

@ -30,7 +30,7 @@ int playerHealth(int health, int damage){
} }
int enemyDamaged(enemy enemy, int damage){ int enemyDamaged(enemy enemy, int damage){
int armor = getEnemyArmor(enemy);
int armor = getEnemyInt(&enemy.armor);
int damagedealt = damage - armor; int damagedealt = damage - armor;
if(damagedealt < 1){ if(damagedealt < 1){
damagedealt = 1; damagedealt = 1;
@ -47,27 +47,14 @@ void *setEnemyHealth(int *num, int health){
//return 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){ void *setEnemyDamage(int *num, int damage){
*num = damage; *num = damage;
} }
int getEnemyDamage(enemy enemy){
return enemy.damage;
}
void *setEnemyArmor(int *num, int armor){ void *setEnemyArmor(int *num, int armor){
*num = armor; *num = armor;
} }
int getEnemyArmor(enemy enemy){
return enemy.armor;
}
int getEnemyInt(int *structParam){ int getEnemyInt(int *structParam){
return *structParam; return *structParam;
} }

4
src/c/encounter.h

@ -21,13 +21,11 @@ int enemyDamaged(enemy enemy, int damage);
//setEnemyHealth(&enemy.health, health); //setEnemyHealth(&enemy.health, health);
void *setEnemyHealth(int *num, int health); void *setEnemyHealth(int *num, int health);
int getEnemyHealth(enemy enemy);
//setEnemyDamage(&enemy.damage, damage); //setEnemyDamage(&enemy.damage, damage);
void *setEnemyDamage(int *num, int damage); void *setEnemyDamage(int *num, int damage);
int getEnemyDamage(enemy enemy);
//setEnemyArmor(&enemy.armor, armor); //setEnemyArmor(&enemy.armor, armor);
void *setEnemyArmor(int *num, int damage); 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 //Function to get the value of Data in a struct, needs a pointer to the struct
int getEnemyInt(int *structParam); int getEnemyInt(int *structParam);

6
test/c/test_encounter.c

@ -59,7 +59,7 @@ void test_getEnemyHealth(void){
int health = 50, result; int health = 50, result;
//act //act
enemy test = {health}; enemy test = {health};
result = getEnemyHealth(test);
result = getEnemyInt(&test.health);
//assert //assert
TEST_ASSERT_EQUAL(health, result); TEST_ASSERT_EQUAL(health, result);
} }
@ -74,7 +74,7 @@ void test_setEnemyDamage(void){
void test_getEnemyDamage(void){ void test_getEnemyDamage(void){
int damage = 4, result; int damage = 4, result;
enemy test = {50, damage}; enemy test = {50, damage};
result = getEnemyDamage(test);
result = getEnemyInt(&test.damage);
TEST_ASSERT_EQUAL(damage, result); TEST_ASSERT_EQUAL(damage, result);
} }
@ -82,7 +82,7 @@ void test_get_setEnemyArmor(void){
int armor = 4, result; int armor = 4, result;
enemy test = {50, 4, armor*2}; enemy test = {50, 4, armor*2};
setEnemyArmor(&test.armor, armor); setEnemyArmor(&test.armor, armor);
result = getEnemyArmor(test);
result = getEnemyInt(&test.armor);
TEST_ASSERT_EQUAL(armor, result); TEST_ASSERT_EQUAL(armor, result);
} }

Loading…
Cancel
Save