diff --git a/src/c/character.c b/src/c/character.c index 3ccf7ba..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; @@ -172,4 +173,165 @@ 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; +} + +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); +} + +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 setCharacterStatus (Character *character, int newStatus) { + character->status = newStatus; +} + +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++) + { + 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"); + } 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; + } +} +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]; + } +} + +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 dff4d81..2c8a708 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -1,10 +1,15 @@ #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; + int attack,armor,maxHealthPoints,gold,weaponClass,statPoints,status,statusDuration; char name [50]; + Item *inventory[10]; } Character; typedef struct { int attack,durability; @@ -85,4 +90,50 @@ 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); + +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); + +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); + +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/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 diff --git a/src/c/spell.c b/src/c/spell.c new file mode 100644 index 0000000..1266eec --- /dev/null +++ b/src/c/spell.c @@ -0,0 +1,46 @@ +#include +#include +#include + +#include "character.h" +#include "spell.h" + +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; +} + +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; +} + +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; +} + +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 new file mode 100644 index 0000000..d9711cd --- /dev/null +++ b/src/c/spell.h @@ -0,0 +1,20 @@ +#ifndef SPELL_H +#define SPELL_H + + +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); +SpellEffect spellLightning(Character *character); +SpellEffect spellRegeneration (Character *character); + + +#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)); } diff --git a/test/c/test_spell.c b/test/c/test_spell.c new file mode 100644 index 0000000..00651aa --- /dev/null +++ b/test/c/test_spell.c @@ -0,0 +1,65 @@ +#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) +{ + 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) +{ + + int result = spellHeal(&testCharacter).healing; + TEST_ASSERT_EQUAL_INT(10,result); + result = spellHeal(&testCharacter2).healing; + 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); +} + +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