From 788b458687faf6499e98fb628b520a62ba6ec371 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 14 Jan 2023 18:24:02 +0100 Subject: [PATCH] prod/test: added Level stat and created test_setCharacterLevel and setCharacterLevel --- src/c/character.c | 10 +++++++--- src/c/character.h | 7 ++++--- test/c/test_character.c | 8 ++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/c/character.c b/src/c/character.c index 40051d6..1b12e2c 100644 --- a/src/c/character.c +++ b/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; } -} \ No newline at end of file +} diff --git a/src/c/character.h b/src/c/character.h index 02b4630..411a1e3 100644 --- a/src/c/character.h +++ b/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 \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index 20d175c..8dff325 100644 --- a/test/c/test_character.c +++ b/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);