From 608e76dbe475e62b92c9c516d78ea4edd0a35392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos?= Date: Fri, 13 Jan 2023 20:23:34 +0100 Subject: [PATCH] Added AttackValues and A better getter function --- src/c/encounter.c | 32 ++++++++++++++++---------------- src/c/encounter.h | 11 ++++++++--- test/c/test_encounter.c | 15 +++++++++++++-- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/c/encounter.c b/src/c/encounter.c index fe37c67..29678c8 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -3,7 +3,7 @@ #include #include -#include +#include "encounter.h" /*Gegner mit AC, damagedealt = damage-AC, kann nicht kleiner 1 sein evtl. lair bonus der dem gegner ein wenig mehr/weniger damage erlaubt gegner erhalten eine zufällige menge Gold, die beim tod an den spieler gegeben werden @@ -29,13 +29,19 @@ int playerHealth(int health, int damage){ return health; } -/* enemy createEnemy(int health) -{ - enemy test; - test.health = health; - return test; -} */ +int enemyDamaged(enemy enemy, int damage){ + int armor = getEnemyArmor(enemy); + int damagedealt = damage - armor; + if(damagedealt < 1){ + damagedealt = 1; + } + enemy.health = enemy.health - damagedealt; + return enemy.health; +} + + +//Getter/Setter Funktionen void *setEnemyHealth(int *num, int health){ *num = health; //return health; @@ -62,12 +68,6 @@ int getEnemyArmor(enemy enemy){ return enemy.armor; } -int enemyDamaged(enemy enemy, int damage){ - int armor = getEnemyArmor(enemy); - int damagedealt = damage - armor; - if(damagedealt < 1){ - damagedealt = 1; - } - enemy.health = enemy.health - damagedealt; - return enemy.health; -} \ No newline at end of file +int getEnemyInt(int *structParam){ + return *structParam; +} diff --git a/src/c/encounter.h b/src/c/encounter.h index d2b0fba..0beafea 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -7,11 +7,17 @@ typedef struct { int health; int damage; int armor; + int attack; } enemy; bool playerAlive(int health); int playerHealth(int health, int damage); +int enemyDamaged(enemy enemy, int damage); + + + +//Getter/Setter Funktionen //setEnemyHealth(&enemy.health, health); void *setEnemyHealth(int *num, int health); @@ -22,8 +28,7 @@ int getEnemyDamage(enemy enemy); //setEnemyArmor(&enemy.armor, armor); void *setEnemyArmor(int *num, int damage); int getEnemyArmor(enemy enemy); - -int enemyDamaged(enemy enemy, int damage); - +//Function to get the value of Data in a struct, needs a pointer to the struct +int getEnemyInt(int *structParam); #endif \ No newline at end of file diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index 1f501ae..e68f866 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -56,11 +56,12 @@ void test_setEnemyHealth(void){ void test_getEnemyHealth(void){ //arrange - int health = 50; + int health = 50, result; //act enemy test = {health}; + result = getEnemyHealth(test); //assert - TEST_ASSERT_EQUAL(health, getEnemyHealth(test)); + TEST_ASSERT_EQUAL(health, result); } void test_setEnemyDamage(void){ @@ -114,4 +115,14 @@ void test_PlayerAttacksEnemy_DoesMinDamage(void) //assert TEST_ASSERT_EQUAL(expectedEnemyHealth, test.health); } + +//A better way to get the value of a struct, REFACTORING if it works +void test_getterWithParams(void){ + int health = 50, armor = 4, damage = 4, attack = 5; + enemy test = {health, damage, armor, attack}; + TEST_ASSERT_EQUAL(health, getEnemyInt(&test.health)); + TEST_ASSERT_EQUAL(armor, getEnemyInt(&test.armor)); + TEST_ASSERT_EQUAL(damage, getEnemyInt(&test.damage)); + TEST_ASSERT_EQUAL(attack, getEnemyInt(&test.attack)); +} #endif // TEST