Browse Source

Added AttackValues and A better getter function

remotes/origin/encounter
János 2 years ago
parent
commit
608e76dbe4
  1. 32
      src/c/encounter.c
  2. 11
      src/c/encounter.h
  3. 15
      test/c/test_encounter.c

32
src/c/encounter.c

@ -3,7 +3,7 @@
#include <string.h>
#include <stdbool.h>
#include <encounter.h>
#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;
}
int getEnemyInt(int *structParam){
return *structParam;
}

11
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

15
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
Loading…
Cancel
Save