From 6af6e3d224f5ea0d711aad937fc9be486dbe22ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos?= Date: Thu, 12 Jan 2023 13:26:21 +0100 Subject: [PATCH] added damage value and funtions to enemy struct --- src/c/encounter.c | 8 ++++++++ src/c/encounter.h | 10 ++++++++-- test/c/test_encounter.c | 13 +++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/c/encounter.c b/src/c/encounter.c index 9bd8a89..d6b8710 100644 --- a/src/c/encounter.c +++ b/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; +} diff --git a/src/c/encounter.h b/src/c/encounter.h index 4dd6bf3..6fbedfe 100644 --- a/src/c/encounter.h +++ b/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 \ No newline at end of file diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index eb40728..cc57da1 100644 --- a/test/c/test_encounter.c +++ b/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