Browse Source

prod/test: added Level stat and created test_setCharacterLevel and setCharacterLevel

remotes/origin/characterStats
Kai Kehres 2 years ago
parent
commit
788b458687
  1. 10
      src/c/character.c
  2. 7
      src/c/character.h
  3. 8
      test/c/test_character.c

10
src/c/character.c

@ -38,9 +38,13 @@ int getCharacterIntelligence (Character *character) {
return character->intelligence;
}
void setCharacterLevel (Character *character, int newLevel) {
character->level = newLevel;
}
void increaseStat (Character *character, int Stat, int amount) {
switch (Stat)
void increaseStat (Character *character, int stat, int amount) {
switch (stat)
{
case 1:
character->strength += amount;break;
@ -55,4 +59,4 @@ void increaseStat (Character *character, int Stat, int amount) {
default:
break;
}
}
}

7
src/c/character.h

@ -2,12 +2,12 @@
#define CHARACTER_H
typedef struct {
int strength,dexterity,intelligence,healthPoints,manaPoints;
int strength,dexterity,intelligence,healthPoints,manaPoints,level;
char name [50];
} Character;
enum {
STRENGTH = 1, DEXTERITY = 2, INTELLIGENCE = 3, HEALTHPOINTS = 4, MANAPOINTS = 5
STRENGTH = 1, DEXTERITY = 2, INTELLIGENCE = 3, HEALTHPOINTS = 4, MANAPOINTS = 5, LEVEL = 6
};
void setCharacterHealthPoints (Character *character, int newHealthPoints);
@ -26,6 +26,7 @@ void setCharacterIntelligence (Character *character, int newIntelligence);
int getCharacterIntelligence (Character *character);
void increaseStat (Character *character, int Stat, int amount);
void setCharacterLevel (Character *character, int newLevel);
void increaseStat (Character *character, int stat, int amount);
#endif

8
test/c/test_character.c

@ -14,6 +14,8 @@ void setUp(void)
testCharacter2.dexterity = 5;
testCharacter.intelligence = 0;
testCharacter2.intelligence = 7;
testCharacter.level = 0;
testCharacter2.level = 5;
}
void tearDown(void)
@ -61,6 +63,12 @@ void test_getCharacterIntelligence(void) {
TEST_ASSERT_EQUAL_INT(7,testCharacter2.intelligence);
}
void test_setCharacterLevel(void) {
TEST_ASSERT_EQUAL_INT(0,testCharacter.level);
setCharacterLevel(&testCharacter,1);
TEST_ASSERT_EQUAL_INT(1,testCharacter.level);
}
void test_increaseStat(void) {
increaseStat(&testCharacter2,STRENGTH,15);
TEST_ASSERT_EQUAL_INT(20,testCharacter2.strength);

Loading…
Cancel
Save