Browse Source

refactoring: prod combined addCharacterHealthPoints and addCharacterStrength to increaseStat function also

remotes/origin/characterStats
Kai Kehres 2 years ago
parent
commit
4ac4f2b6d8
  1. 28
      src/c/character.c
  2. 10
      src/c/character.h
  3. 7
      test/c/test_character.c

28
src/c/character.c

@ -3,6 +3,7 @@
#include <string.h>
#include "character.h"
Character character;
void setCharacterHealthPoints (Character *character, int newHealthPoints){
@ -13,10 +14,6 @@ int getCharacterHealthPoints (Character *character) {
return character->healthPoints;
}
void addCharacterHealthPoints (Character *character, int addedHealthPoints) {
character->healthPoints += addedHealthPoints;
}
void setCharacterStrength (Character *character, int newStrength) {
character->strength = newStrength;
}
@ -25,10 +22,6 @@ int getCharacterStrength (Character *character) {
return character->strength;
}
void addCharacterStrength (Character *character, int addStrength) {
character->strength += addStrength;
}
void setCharacterDexterity (Character *character, int newDexterity) {
character->dexterity = newDexterity;
}
@ -43,4 +36,23 @@ void setCharacterIntelligence (Character *character, int newIntelligence) {
int getCharacterIntelligence (Character *character) {
return character->intelligence;
}
void increaseStat (Character *character, int Stat, int amount) {
switch (Stat)
{
case 1:
character->strength += amount;break;
case 2:
character->dexterity += amount;break;
case 3:
character->intelligence += amount;break;
case 4:
character->healthPoints += amount;break;
case 5:
character->manaPoints += amount;break;
default:
break;
}
}

10
src/c/character.h

@ -6,18 +6,18 @@ typedef struct {
char name [50];
} Character;
enum {
STRENGTH = 1, DEXTERITY = 2, INTELLIGENCE = 3, HEALTHPOINTS = 4, MANAPOINTS = 5
};
void setCharacterHealthPoints (Character *character, int newHealthPoints);
int getCharacterHealthPoints (Character *character);
void addCharacterHealthPoints (Character *character, int addedHealthPoints);
void setCharacterStrength (Character *character, int newStrength);
int getCharacterStrength (Character *character);
void addCharacterStrength (Character *character, int addStrength);
void setCharacterDexterity (Character *character, int newDexterity);
int getCharacterDexterity (Character *character);
@ -26,4 +26,6 @@ void setCharacterIntelligence (Character *character, int newIntelligence);
int getCharacterIntelligence (Character *character);
void increaseStat (Character *character, int Stat, int amount);
#endif

7
test/c/test_character.c

@ -32,9 +32,8 @@ void test_getCharacterHealthPoints (void) {
}
void test_addCharacterHealthPoints (void) {
addCharacterHealthPoints(&testCharacter2,5);
increaseStat(&testCharacter2,HEALTHPOINTS,5);
TEST_ASSERT_EQUAL_INT(20,testCharacter2.healthPoints);
}
void test_setCharacterStrenght(void) {
@ -48,8 +47,8 @@ void test_getCharacterStrength(void) {
}
void test_addCharacterStrength (void) {
addCharacterStrength(&testCharacter2,15);
TEST_ASSERT_EQUAL_INT(20,testCharacter2.strength);
increaseStat(&testCharacter2,STRENGTH,5);
TEST_ASSERT_EQUAL_INT(10,testCharacter2.strength);
}
void test_setCharacterDexterity(void) {

Loading…
Cancel
Save