From ac50591e76f4f81130773b24dcb80de171c1cedd Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 28 Jan 2023 18:32:16 +0100 Subject: [PATCH 01/15] prod: new Stat and getter Setter --- src/c/character.c | 8 ++++++++ src/c/character.h | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/c/character.c b/src/c/character.c index 3ccf7ba..fe3a73e 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -172,4 +172,12 @@ int calculateDamage (Character *character,Weapon *weapon) { default: return 1; } +} + +void setCharacterStatPoints (Character* character, int newStatPoints) { + character->statPoints = newStatPoints; +} + +int getCharacterStatPoints (Character* character) { + return character->statPoints; } \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index dff4d81..c7b8056 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -3,7 +3,7 @@ typedef struct { int strength,dexterity,intelligence,healthPoints,manaPoints,level,exp,maxExp; - int attack,armor,maxHealthPoints,gold,items[10],weaponClass; + int attack,armor,maxHealthPoints,gold,items[10],weaponClass,statPoints; char name [50]; } Character; typedef struct { @@ -85,4 +85,8 @@ int getWeaponDurability (Weapon *weapon); int setWeaponDurability (Weapon *weapon, int newDurability); int calculateDamage (Character *character,Weapon *weapon); + +void setCharacterStatPoints (Character *character, int newStatPoints); + +int getCharacterStatPoints (Character *character); #endif \ No newline at end of file From cb948599c8037329aca3c82cb09a1935dc7a085d Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 28 Jan 2023 18:34:47 +0100 Subject: [PATCH 02/15] prod: new function initializeCharacter --- src/c/character.c | 17 +++++++++++++++++ src/c/character.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/c/character.c b/src/c/character.c index fe3a73e..b49a45b 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -180,4 +180,21 @@ void setCharacterStatPoints (Character* character, int newStatPoints) { int getCharacterStatPoints (Character* character) { return character->statPoints; +} + +void initializeCharacter (Character *character,int weaponClass) { + setCharacterHealthPoints(character,100); + setCharacterStrength(character,10); + setCharacterDexterity(character,10); + setCharacterIntelligence(character,10); + setCharacterLevel(character,1); + setCharacterExp(character,0); + setCharacterMaxExp(character,100); + setCharacterMaxHealthPoints(character,100); + setCharacterAttack(character,10); + setCharacterArmor(character,0); + setCharacterGold(character,0); + setCharacterName(character,"Player"); + setCharacterWeaponClass(character,weaponClass); + setCharacterStatPoints(character,0); } \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index c7b8056..99d354e 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -89,4 +89,6 @@ int calculateDamage (Character *character,Weapon *weapon); void setCharacterStatPoints (Character *character, int newStatPoints); int getCharacterStatPoints (Character *character); + +void initializeCharacter (Character *character,int weaponClass); #endif \ No newline at end of file From 6c6e4d32ed09f1528302db208466025bc0a7b344 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 28 Jan 2023 18:51:10 +0100 Subject: [PATCH 03/15] prod: created function create randomized enemy --- src/c/encounter.c | 36 ++++++++++++++++++++++++++++++++++++ src/c/encounter.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/src/c/encounter.c b/src/c/encounter.c index aa8287d..2c25444 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -201,4 +201,40 @@ void setEnemyExp(enemy* enemy, int newExp){ int getEnemyGold(enemy* enemy){ return enemy->gold; +} +int setEnemyGold(enemy* enemy, int newGold){ + enemy->gold = newGold; +} + +int createRandomEnemy(enemy* enemy) +{ + int enemyType = randomIntRange(1, 3); + switch(enemyType) + { + case 1: + setEnemyHealth(enemy, 20); + setEnemyDamage(enemy, 5); + setEnemyArmor(enemy, 2); + setEnemyHealPotions(enemy, 1); + setEnemyExp(enemy, 10); + setEnemyGold(enemy, 10); + break; + case 2: + setEnemyHealth(enemy, 30); + setEnemyDamage(enemy, 10); + setEnemyArmor(enemy, 5); + setEnemyHealPotions(enemy, 2); + setEnemyExp(enemy, 20); + setEnemyGold(enemy, 20); + break; + case 3: + setEnemyHealth(enemy, 40); + setEnemyDamage(enemy, 15); + setEnemyArmor(enemy, 10); + setEnemyHealPotions(enemy, 3); + setEnemyExp(enemy, 30); + setEnemyGold(enemy, 30); + break; + } + return enemyType; } \ No newline at end of file diff --git a/src/c/encounter.h b/src/c/encounter.h index 071861f..796f555 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -46,4 +46,6 @@ void setEnemyHealPotions(enemy* enemy, int newPotions); int getEnemyExp(enemy* enemy); void setEnemyExp(enemy* enemy, int newExp); +int createRandomEnemy(enemy* enemy); + #endif \ No newline at end of file From a9711f8a7818e95ef3fc21113a2736b6afe52364 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 28 Jan 2023 19:26:46 +0100 Subject: [PATCH 04/15] prod: created new struct item and getter setter --- src/c/character.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/c/character.h b/src/c/character.h index 99d354e..849f08e 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -3,13 +3,18 @@ typedef struct { int strength,dexterity,intelligence,healthPoints,manaPoints,level,exp,maxExp; - int attack,armor,maxHealthPoints,gold,items[10],weaponClass,statPoints; + int attack,armor,maxHealthPoints,gold,*items[10],weaponClass,statPoints; char name [50]; } Character; typedef struct { int attack,durability; char name [50]; } Weapon; +typedef struct { + int id,amount,damage,healing,mana; + char name [50]; + } Item; + enum { SWORD = 1, BOW = 2, STAFF = 3 @@ -91,4 +96,30 @@ void setCharacterStatPoints (Character *character, int newStatPoints); int getCharacterStatPoints (Character *character); void initializeCharacter (Character *character,int weaponClass); + +void setItemID (Item *item, int newID); + +int getItemID (Item *item); + +void setItemAmount (Item *item, int newAmount); + +int getItemAmount (Item *item); + +void setItemDamage (Item *item, int newDamage); + +int getItemDamage (Item *item); + +void setItemHealing (Item *item, int newHealing); + +int getItemHealing (Item *item); + +void setItemMana (Item *item, int newMana); + +int getItemMana (Item *item); + +void setItemName (Item *item, char newName[]); + +char* getItemName (Item *item); + + #endif \ No newline at end of file From 09893d1efa371bbdf773f65ed9d1b5b50c7cfcf6 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 28 Jan 2023 19:48:15 +0100 Subject: [PATCH 05/15] prod: created function putItemInInventory --- src/c/character.c | 60 +++++++++++++++++++++++++++++++++++++++++ src/c/character.h | 13 ++++----- test/c/test_character.c | 2 ++ 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/c/character.c b/src/c/character.c index b49a45b..7bc246b 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -197,4 +197,64 @@ void initializeCharacter (Character *character,int weaponClass) { setCharacterName(character,"Player"); setCharacterWeaponClass(character,weaponClass); setCharacterStatPoints(character,0); +} + +void setItemID (Item *item, int newID) { + item->id = newID; +} + +int getItemID (Item *item) { + return item->id; +} + +void setItemAmount (Item *item, int newAmount) { + item->amount = newAmount; +} + +int getItemAmount (Item *item) { + return item->amount; +} + +void setItemDamage (Item *item, int newDamage) { + item->damage = newDamage; +} + +int getItemDamage (Item *item) { + return item->damage; +} + +void setItemHealing (Item *item, int newHealing) { + item->healing = newHealing; +} + +int getItemHealing (Item *item) { + return item->healing; +} + +void setItemMana (Item *item, int newMana) { + item->mana = newMana; +} + +int getItemMana (Item *item) { + return item->mana; +} + +void setItemName (Item *item, char newName[]) { + strcpy(item->name,newName); +} + +char* getItemName (Item *item) { + return item->name; +} + +void putItemInInventory (Character *character, Item *item,int inventorySlot) { + if(inventorySlot > 9) { + printf("Inventory slot is out of range (0-9)\n"); + } else if (inventorySlot < 0) { + printf("Inventory slot is out of range (0-9)\n"); + } else if (character->inventory[inventorySlot] != NULL) { + printf("Inventory slot is already occupied\n"); + } else { + character->inventory[inventorySlot] = item; + } } \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index 849f08e..4ff39f2 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -1,20 +1,20 @@ #ifndef CHARACTER_H #define CHARACTER_H +typedef struct { + int id,amount,damage,healing,mana; + char name [50]; + } Item; typedef struct { int strength,dexterity,intelligence,healthPoints,manaPoints,level,exp,maxExp; - int attack,armor,maxHealthPoints,gold,*items[10],weaponClass,statPoints; + int attack,armor,maxHealthPoints,gold,weaponClass,statPoints; char name [50]; + Item *inventory[10]; } Character; typedef struct { int attack,durability; char name [50]; } Weapon; -typedef struct { - int id,amount,damage,healing,mana; - char name [50]; - } Item; - enum { SWORD = 1, BOW = 2, STAFF = 3 @@ -121,5 +121,6 @@ void setItemName (Item *item, char newName[]); char* getItemName (Item *item); +void putItemInInventory (Character *character, Item *item, int inventorySlot); #endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index 5733e4d..cbe09e7 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -124,6 +124,8 @@ void test_levelUp_notEnoughExp_loseExp (void) { } void test_calculateDamage_Sword (void) { + setCharacterWeaponClass(&testCharacter2,SWORD); + TEST_ASSERT_EQUAL_INT(25,calculateDamage(&testCharacter2,&testWeapon)); } From daea02f10a70bfd69fd65d13074e12c3b4bb6b95 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 28 Jan 2023 20:15:44 +0100 Subject: [PATCH 06/15] prod: created initializeInventory function --- src/c/character.c | 7 +++++++ src/c/character.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/c/character.c b/src/c/character.c index 7bc246b..141be76 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -247,6 +247,13 @@ char* getItemName (Item *item) { return item->name; } +void initializeInventory (Character *character) { + for (int i = 0; i < 10; i++) + { + character->inventory[i] = NULL; + } +} + void putItemInInventory (Character *character, Item *item,int inventorySlot) { if(inventorySlot > 9) { printf("Inventory slot is out of range (0-9)\n"); diff --git a/src/c/character.h b/src/c/character.h index 4ff39f2..c47f8f6 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -123,4 +123,5 @@ char* getItemName (Item *item); void putItemInInventory (Character *character, Item *item, int inventorySlot); +void initializeInventory (Character *character); #endif \ No newline at end of file From ddf08bfef0eaa55ae7aeca2873bb75f9d4ada484 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 28 Jan 2023 21:00:41 +0100 Subject: [PATCH 07/15] prod: created function getItemInInventory --- src/c/character.c | 16 +++++++++++++++- src/c/character.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/c/character.c b/src/c/character.c index 141be76..148ed4f 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -259,9 +259,23 @@ void putItemInInventory (Character *character, Item *item,int inventorySlot) { printf("Inventory slot is out of range (0-9)\n"); } else if (inventorySlot < 0) { printf("Inventory slot is out of range (0-9)\n"); - } else if (character->inventory[inventorySlot] != NULL) { + } else if (character->inventory[inventorySlot] == NULL) { printf("Inventory slot is already occupied\n"); } else { character->inventory[inventorySlot] = item; } +} +Item * getItemInInventory (Character *character, int inventorySlot) { + if(inventorySlot > 9) { + printf("Inventory slot is out of range (0-9)\n"); + return NULL; + } else if (inventorySlot < 0) { + printf("Inventory slot is out of range (0-9)\n"); + return NULL; + } else if (character->inventory[inventorySlot] == NULL) { + printf("Inventory slot is empty\n"); + return NULL; + } else { + return character->inventory[inventorySlot]; + } } \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index c47f8f6..d7fb70f 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -124,4 +124,6 @@ char* getItemName (Item *item); void putItemInInventory (Character *character, Item *item, int inventorySlot); void initializeInventory (Character *character); + +Item * getItemInInventory (Character *character, int inventorySlot); #endif \ No newline at end of file From 40fcf6746ce9e89e4c62a72ccda6919480a9d279 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sun, 29 Jan 2023 11:44:27 +0100 Subject: [PATCH 08/15] prod/test: created new files spell.c /.h and test_spell.c and function spellFireball --- src/c/spell.c | 10 ++++++++++ src/c/spell.h | 6 ++++++ test/c/test_spell.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 src/c/spell.c create mode 100644 src/c/spell.h create mode 100644 test/c/test_spell.c diff --git a/src/c/spell.c b/src/c/spell.c new file mode 100644 index 0000000..ea368b2 --- /dev/null +++ b/src/c/spell.c @@ -0,0 +1,10 @@ +#include +#include +#include + +#include "character.h" + +int spellFireball(Character *character) { + int damage = 10 + (getCharacterIntelligence(character) / 2); + return damage; +} \ No newline at end of file diff --git a/src/c/spell.h b/src/c/spell.h new file mode 100644 index 0000000..bc7b657 --- /dev/null +++ b/src/c/spell.h @@ -0,0 +1,6 @@ +#ifndef SPELL_H +#define SPELL_H + +int spellFireball(Character *character); + +#endif \ No newline at end of file diff --git a/test/c/test_spell.c b/test/c/test_spell.c new file mode 100644 index 0000000..a8d4ab0 --- /dev/null +++ b/test/c/test_spell.c @@ -0,0 +1,38 @@ +#ifdef TEST +#include "unity.h" +#include "character.h" +#include "spell.h" + +Character testCharacter; +Character testCharacter2; + +void setUp(void) +{ + testCharacter.healthPoints = 0; + testCharacter2.healthPoints = 15; + testCharacter.strength = 0; + testCharacter2.strength = 5; + testCharacter.dexterity = 0; + testCharacter2.dexterity = 5; + testCharacter.intelligence = 0; + testCharacter2.intelligence = 7; + testCharacter.level = 0; + testCharacter2.level = 5; + testCharacter.exp = 50; + testCharacter2.exp = 110; + testCharacter.maxExp = 100; + testCharacter2.maxExp = 100; + testCharacter.attack = 5; + testCharacter2.weaponClass = SWORD; +} + +void tearDown(void) +{ +} + +void test_spellFireball(void) +{ + TEST_ASSERT_EQUAL_INT(10,spellFireball(&testCharacter)); + TEST_ASSERT_EQUAL_INT(13,spellFireball(&testCharacter2)); +} +#endif // TEST \ No newline at end of file From 8910a0d9a1ab0a348bd67eb490ae58d382e62bba Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sun, 29 Jan 2023 11:57:03 +0100 Subject: [PATCH 09/15] prod/test: creates spellHeal function and test --- src/c/spell.c | 6 ++++++ src/c/spell.h | 3 +++ test/c/test_spell.c | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/src/c/spell.c b/src/c/spell.c index ea368b2..b8ce864 100644 --- a/src/c/spell.c +++ b/src/c/spell.c @@ -7,4 +7,10 @@ int spellFireball(Character *character) { int damage = 10 + (getCharacterIntelligence(character) / 2); return damage; +} + + +int spellHeal(Character *character) { + int heal = 10 + (getCharacterIntelligence(character) / 3); + return heal; } \ No newline at end of file diff --git a/src/c/spell.h b/src/c/spell.h index bc7b657..fec8dd8 100644 --- a/src/c/spell.h +++ b/src/c/spell.h @@ -1,6 +1,9 @@ #ifndef SPELL_H #define SPELL_H +#include "character.h" + int spellFireball(Character *character); +int spellHeal(Character *character); #endif \ No newline at end of file diff --git a/test/c/test_spell.c b/test/c/test_spell.c index a8d4ab0..86e55ee 100644 --- a/test/c/test_spell.c +++ b/test/c/test_spell.c @@ -35,4 +35,10 @@ void test_spellFireball(void) TEST_ASSERT_EQUAL_INT(10,spellFireball(&testCharacter)); TEST_ASSERT_EQUAL_INT(13,spellFireball(&testCharacter2)); } + +void test_spellHeal(void) +{ + TEST_ASSERT_EQUAL_INT(10,spellHeal(&testCharacter)); + TEST_ASSERT_EQUAL_INT(12,spellHeal(&testCharacter2)); +} #endif // TEST \ No newline at end of file From 28b4f0e1ac3c5d7c89812d8e9b55679e7333a21a Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sun, 29 Jan 2023 12:36:26 +0100 Subject: [PATCH 10/15] refactoring: changed the return type of spells to new Struct SpellEffect and updated tests to resemble this --- src/c/spell.c | 24 +++++++++++++++++------- src/c/spell.h | 13 +++++++++++-- test/c/test_spell.c | 15 +++++++++++---- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/c/spell.c b/src/c/spell.c index b8ce864..4fca537 100644 --- a/src/c/spell.c +++ b/src/c/spell.c @@ -3,14 +3,24 @@ #include #include "character.h" +#include "spell.h" -int spellFireball(Character *character) { - int damage = 10 + (getCharacterIntelligence(character) / 2); - return damage; +SpellEffect spellFireball(Character *character) { + SpellEffect fireball; + fireball.damage = 10 + (getCharacterIntelligence(character) / 2); + fireball.healing = 0; + fireball.manaCost = 10; + fireball.effect = SPELL_EFFECT_NONE; + fireball.effectDuration = 0; + return fireball; } - -int spellHeal(Character *character) { - int heal = 10 + (getCharacterIntelligence(character) / 3); +SpellEffect spellHeal(Character *character) { + SpellEffect heal; + heal.damage = 0; + heal.healing = 10 + (getCharacterIntelligence(character) / 3); + heal.manaCost = 10; + heal.effect = SPELL_EFFECT_NONE; + heal.effectDuration = 0; return heal; -} \ No newline at end of file +} diff --git a/src/c/spell.h b/src/c/spell.h index fec8dd8..6b94b8e 100644 --- a/src/c/spell.h +++ b/src/c/spell.h @@ -3,7 +3,16 @@ #include "character.h" -int spellFireball(Character *character); -int spellHeal(Character *character); +typedef struct { + int damage, healing, manaCost, effect, effectDuration; +} SpellEffect; + +enum { + SPELL_EFFECT_NONE = 0, SPELL_EFFECT_BURN = 1, SPELL_EFFECT_FREEZE = 2, SPELL_EFFECT_STUN =3 , SPELL_EFFECT_REGENERATION = 4 +}; + + +SpellEffect spellFireball(Character *character); +SpellEffect spellHeal(Character *character); #endif \ No newline at end of file diff --git a/test/c/test_spell.c b/test/c/test_spell.c index 86e55ee..dce3114 100644 --- a/test/c/test_spell.c +++ b/test/c/test_spell.c @@ -32,13 +32,20 @@ void tearDown(void) void test_spellFireball(void) { - TEST_ASSERT_EQUAL_INT(10,spellFireball(&testCharacter)); - TEST_ASSERT_EQUAL_INT(13,spellFireball(&testCharacter2)); + int result = spellFireball(&testCharacter).damage; + TEST_ASSERT_EQUAL_INT(10,result); + result = spellFireball(&testCharacter2).damage; + TEST_ASSERT_EQUAL_INT(13,result); } void test_spellHeal(void) { - TEST_ASSERT_EQUAL_INT(10,spellHeal(&testCharacter)); - TEST_ASSERT_EQUAL_INT(12,spellHeal(&testCharacter2)); + + int result = spellHeal(&testCharacter).healing; + TEST_ASSERT_EQUAL_INT(10,result); + result = spellHeal(&testCharacter2).healing; + TEST_ASSERT_EQUAL_INT(12,result); } + + #endif // TEST \ No newline at end of file From c4cadbbec05db12f33f5890a526a0a3b9973f64f Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sun, 29 Jan 2023 12:49:11 +0100 Subject: [PATCH 11/15] prod: created getter and setter for character status --- src/c/character.c | 8 ++++++++ src/c/character.h | 6 +++++- src/c/spell.h | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/c/character.c b/src/c/character.c index 148ed4f..075d072 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -247,6 +247,14 @@ char* getItemName (Item *item) { return item->name; } +void setCharacterStatus (Character *character, int newStatus) { + character->status = newStatus; +} + +int getCharacterStatus (Character *character) { + return character->status; +} + void initializeInventory (Character *character) { for (int i = 0; i < 10; i++) { diff --git a/src/c/character.h b/src/c/character.h index d7fb70f..0380a89 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -7,7 +7,7 @@ typedef struct { } Item; typedef struct { int strength,dexterity,intelligence,healthPoints,manaPoints,level,exp,maxExp; - int attack,armor,maxHealthPoints,gold,weaponClass,statPoints; + int attack,armor,maxHealthPoints,gold,weaponClass,statPoints,status; char name [50]; Item *inventory[10]; } Character; @@ -126,4 +126,8 @@ void putItemInInventory (Character *character, Item *item, int inventorySlot); void initializeInventory (Character *character); Item * getItemInInventory (Character *character, int inventorySlot); + +void setCharacterStatus (Character *character, int newStatus); + +int getCharacterStatus (Character *character); #endif \ No newline at end of file diff --git a/src/c/spell.h b/src/c/spell.h index 6b94b8e..b5d65f0 100644 --- a/src/c/spell.h +++ b/src/c/spell.h @@ -15,4 +15,6 @@ enum { SpellEffect spellFireball(Character *character); SpellEffect spellHeal(Character *character); + + #endif \ No newline at end of file From 08d666542dd6732f2ae72a6cdf42c6ef139ccaa3 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sun, 29 Jan 2023 12:54:54 +0100 Subject: [PATCH 12/15] prod: created getter and setter StatusDuration --- src/c/character.c | 8 ++++++++ src/c/character.h | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/c/character.c b/src/c/character.c index 075d072..3f52d2d 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -255,6 +255,14 @@ int getCharacterStatus (Character *character) { return character->status; } +void setCharacterStatusDuration (Character *character, int newStatusDuration) { + character->statusDuration = newStatusDuration; +} + +int getCharacterStatusDuration (Character *character) { + return character->statusDuration; +} + void initializeInventory (Character *character) { for (int i = 0; i < 10; i++) { diff --git a/src/c/character.h b/src/c/character.h index 0380a89..62cc4c7 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -7,7 +7,7 @@ typedef struct { } Item; typedef struct { int strength,dexterity,intelligence,healthPoints,manaPoints,level,exp,maxExp; - int attack,armor,maxHealthPoints,gold,weaponClass,statPoints,status; + int attack,armor,maxHealthPoints,gold,weaponClass,statPoints,status,statusDuration; char name [50]; Item *inventory[10]; } Character; @@ -130,4 +130,8 @@ Item * getItemInInventory (Character *character, int inventorySlot); void setCharacterStatus (Character *character, int newStatus); int getCharacterStatus (Character *character); + +void setCharacterStatusDuration (Character *character, int newStatusDuration); + +int getCharacterStatusDuration (Character *character); #endif \ No newline at end of file From 8f0b7bf08810c13005ea74253da8a1de56ae71d4 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sun, 29 Jan 2023 13:05:09 +0100 Subject: [PATCH 13/15] prod/test: creatd function spellLighning --- src/c/spell.c | 10 ++++++++++ src/c/spell.h | 2 +- test/c/test_spell.c | 8 +++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/c/spell.c b/src/c/spell.c index 4fca537..e14482b 100644 --- a/src/c/spell.c +++ b/src/c/spell.c @@ -24,3 +24,13 @@ SpellEffect spellHeal(Character *character) { heal.effectDuration = 0; return heal; } + +SpellEffect spellLightning(Character *character) { + SpellEffect lightning; + lightning.damage = 10 + (getCharacterIntelligence(character) / 2); + lightning.healing = 0; + lightning.manaCost = 10; + lightning.effect = SPELL_EFFECT_STUN; + lightning.effectDuration = 1; + return lightning; +} diff --git a/src/c/spell.h b/src/c/spell.h index b5d65f0..cd3b1c9 100644 --- a/src/c/spell.h +++ b/src/c/spell.h @@ -14,7 +14,7 @@ enum { SpellEffect spellFireball(Character *character); SpellEffect spellHeal(Character *character); - +SpellEffect spellLightning(Character *character); #endif \ No newline at end of file diff --git a/test/c/test_spell.c b/test/c/test_spell.c index dce3114..58dc18e 100644 --- a/test/c/test_spell.c +++ b/test/c/test_spell.c @@ -47,5 +47,11 @@ void test_spellHeal(void) TEST_ASSERT_EQUAL_INT(12,result); } - +void test_spellLightning(void) +{ + int result = spellLightning(&testCharacter).damage; + TEST_ASSERT_EQUAL_INT(10,result); + result = spellLightning(&testCharacter2).damage; + TEST_ASSERT_EQUAL_INT(13,result); +} #endif // TEST \ No newline at end of file From cf7d5d026d0aae22bff5a1643a268e34616b9ad9 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sun, 29 Jan 2023 13:53:51 +0100 Subject: [PATCH 14/15] prod: created spellRegeneration --- src/c/spell.c | 10 ++++++++++ src/c/spell.h | 1 + test/c/test_spell.c | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/src/c/spell.c b/src/c/spell.c index e14482b..1266eec 100644 --- a/src/c/spell.c +++ b/src/c/spell.c @@ -34,3 +34,13 @@ SpellEffect spellLightning(Character *character) { lightning.effectDuration = 1; return lightning; } + +SpellEffect spellRegeneration (Character *character) { + SpellEffect regeneration; + regeneration.damage = 0; + regeneration.healing = 5 + (getCharacterIntelligence(character) / 4); + regeneration.manaCost = 10; + regeneration.effect = SPELL_EFFECT_REGENERATION; + regeneration.effectDuration = 2; + return regeneration; +} \ No newline at end of file diff --git a/src/c/spell.h b/src/c/spell.h index cd3b1c9..0c31a09 100644 --- a/src/c/spell.h +++ b/src/c/spell.h @@ -15,6 +15,7 @@ enum { SpellEffect spellFireball(Character *character); SpellEffect spellHeal(Character *character); SpellEffect spellLightning(Character *character); +SpellEffect spellRegeneration (Character *character); #endif \ No newline at end of file diff --git a/test/c/test_spell.c b/test/c/test_spell.c index 58dc18e..00651aa 100644 --- a/test/c/test_spell.c +++ b/test/c/test_spell.c @@ -54,4 +54,12 @@ void test_spellLightning(void) result = spellLightning(&testCharacter2).damage; TEST_ASSERT_EQUAL_INT(13,result); } + +void test_spellRegeneration(void) +{ + int result = spellRegeneration(&testCharacter).healing; + TEST_ASSERT_EQUAL_INT(5,result); + result = spellRegeneration(&testCharacter2).healing; + TEST_ASSERT_EQUAL_INT(6,result); +} #endif // TEST \ No newline at end of file From 1e32d9cce661675153e48f80feee99d4953b0e95 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sun, 29 Jan 2023 14:11:48 +0100 Subject: [PATCH 15/15] prod: created new function checkStatus --- src/c/character.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/c/character.h | 2 ++ src/c/spell.h | 1 - 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/c/character.c b/src/c/character.c index 3f52d2d..9c46cf7 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -3,6 +3,7 @@ #include #include "character.h" +#include "spell.h" Character character; @@ -294,4 +295,43 @@ Item * getItemInInventory (Character *character, int inventorySlot) { } else { return character->inventory[inventorySlot]; } +} + +int checkStatus (Character *character) { + switch (character->status) + { + case SPELL_EFFECT_NONE: + break; + case SPELL_EFFECT_BURN: + setCharacterStatusDuration(character,getCharacterStatusDuration(character)-1); + if (getCharacterStatusDuration == 0) { + setCharacterStatus(character,SPELL_EFFECT_NONE); + } + return getCharacterStatus(character); + break; + case SPELL_EFFECT_FREEZE: + setCharacterStatusDuration(character,getCharacterStatusDuration(character)-1); + if (getCharacterStatusDuration == 0) { + setCharacterStatus(character,SPELL_EFFECT_NONE); + } + return getCharacterStatus(character); + break; + case SPELL_EFFECT_STUN: + setCharacterStatusDuration(character,getCharacterStatusDuration(character)-1); + if (getCharacterStatusDuration == 0) { + setCharacterStatus(character,SPELL_EFFECT_NONE); + } + return getCharacterStatus(character); + break; + case SPELL_EFFECT_REGENERATION: + setCharacterStatusDuration(character,getCharacterStatusDuration(character)-1); + if (getCharacterStatusDuration == 0) { + setCharacterStatus(character,SPELL_EFFECT_NONE); + } + return getCharacterStatus(character); + break; + default: + return getCharacterStatus(character); + break; + } } \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index 62cc4c7..2c8a708 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -134,4 +134,6 @@ int getCharacterStatus (Character *character); void setCharacterStatusDuration (Character *character, int newStatusDuration); int getCharacterStatusDuration (Character *character); + +int checkStatus (Character *character); #endif \ No newline at end of file diff --git a/src/c/spell.h b/src/c/spell.h index 0c31a09..d9711cd 100644 --- a/src/c/spell.h +++ b/src/c/spell.h @@ -1,7 +1,6 @@ #ifndef SPELL_H #define SPELL_H -#include "character.h" typedef struct { int damage, healing, manaCost, effect, effectDuration;