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)); }