Browse Source

refactoring: also changed the getters

remotes/origin/encounter
János 2 years ago
parent
commit
0a10e4f5b9
  1. 13
      src/c/encounter.c
  2. 8
      src/c/encounter.h
  3. 6
      src/c/playerinput.c
  4. 6
      src/c/playerinput.h
  5. 6
      test/c/test_encounter.c

13
src/c/encounter.c

@ -82,20 +82,19 @@ int fight(int playerH, int playerDamage, int playerArmor, int playerAttack, enem
// Getter/Setter Funktionen // Getter/Setter Funktionen
void *setEnemyHealth(int *num, int health)
void setEnemyHealth(enemy* enemy, int newhealth)
{ {
*num = health;
// return health;
enemy->health = newhealth;
} }
void *setEnemyDamage(int *num, int damage)
void setEnemyDamage(enemy* enemy, int newdamage)
{ {
*num = damage;
enemy->damage = newdamage;
} }
void *setEnemyArmor(int *num, int armor)
void setEnemyArmor(enemy* enemy, int newarmor)
{ {
*num = armor;
enemy->armor = newarmor;
} }
int getEnemyHealth(enemy* enemy) int getEnemyHealth(enemy* enemy)

8
src/c/encounter.h

@ -20,13 +20,13 @@ int fight(int playerH, int playerDamage, int playerArmor, int playerAttack, enem
//Getter/Setter Funktionen //Getter/Setter Funktionen
//setEnemyHealth(&enemy.health, health);
void *setEnemyHealth(int *num, int health);
//setEnemyHealth(&enemy, health);
void setEnemyHealth(enemy* enemy, int newhealth);
//setEnemyDamage(&enemy.damage, damage); //setEnemyDamage(&enemy.damage, damage);
void *setEnemyDamage(int *num, int damage);
void setEnemyDamage(enemy* enemy, int newdamage);
//setEnemyArmor(&enemy.armor, armor); //setEnemyArmor(&enemy.armor, armor);
void *setEnemyArmor(int *num, int damage);
void setEnemyArmor(enemy* enemy, int newarmor);
//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 getEnemyAttack(enemy* enemy); int getEnemyAttack(enemy* enemy);
int getEnemyHealth(enemy* enemy); int getEnemyHealth(enemy* enemy);

6
src/c/playerinput.c

@ -0,0 +1,6 @@
#include "playerinput.h"
char playerInput(){
char c;
return c;
}

6
src/c/playerinput.h

@ -0,0 +1,6 @@
#ifndef PLAYERINPUT_H
#define PLAYERINPUT_H
char playerInput();
#endif

6
test/c/test_encounter.c

@ -66,7 +66,7 @@ void test_setEnemyHealth(void){
int health = 50, result; int health = 50, result;
//act //act
enemy test = {health*2}; enemy test = {health*2};
setEnemyHealth(&test.health, health);
setEnemyHealth(&test, health);
result = test.health; result = test.health;
//assert //assert
TEST_ASSERT_EQUAL(health, result); TEST_ASSERT_EQUAL(health, result);
@ -87,7 +87,7 @@ void test_setEnemyDamage(void){
int damage = 4, result; int damage = 4, result;
enemy test = {50, damage*2}; enemy test = {50, damage*2};
//act //act
setEnemyDamage(&test.damage, damage);
setEnemyDamage(&test, damage);
result = test.damage; result = test.damage;
//assert //assert
TEST_ASSERT_EQUAL(damage, result); TEST_ASSERT_EQUAL(damage, result);
@ -108,7 +108,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};
//act //act
setEnemyArmor(&test.armor, armor);
setEnemyArmor(&test, armor);
result = getEnemyArmor(&test); result = getEnemyArmor(&test);
//assert //assert
TEST_ASSERT_EQUAL(armor, result); TEST_ASSERT_EQUAL(armor, result);

Loading…
Cancel
Save