Browse Source

added damage value and funtions to enemy struct

remotes/origin/encounter
János 2 years ago
parent
commit
6af6e3d224
  1. 8
      src/c/encounter.c
  2. 10
      src/c/encounter.h
  3. 13
      test/c/test_encounter.c

8
src/c/encounter.c

@ -39,3 +39,11 @@ 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;
}

10
src/c/encounter.h

@ -5,12 +5,18 @@
typedef struct {
int health;
int damage;
} enemy;
bool playerAlive(int health);
int playerHealth(int health, int damage);
//setEnemyHealth(&enemy.health, health);
void *setEnemyHealth(int *num, int health);
int getEnemyHealth(enemy enemy);
bool playerAlive(int health);
int playerHealth(int health, int damage);
//setEnemyDamage(&enemy.damage, damage);
void *setEnemyDamage(int *num, int damage);
int getEnemyDamage(enemy enemy);
#endif

13
test/c/test_encounter.c

@ -63,6 +63,19 @@ void test_getEnemyHealth(void){
TEST_ASSERT_EQUAL(health, getEnemyHealth(test));
}
void test_setEnemyDamage(void){
int damage = 4, result;
enemy test = {50, damage*2};
setEnemyDamage(&test.damage, damage);
TEST_ASSERT_EQUAL(damage, test.damage);
}
void test_getEnemyDamage(void){
int damage = 4, result;
enemy test = {50, damage};
result = getEnemyDamage(test);
TEST_ASSERT_EQUAL(damage, result);
}
#endif // TEST
Loading…
Cancel
Save