Browse Source

prod: created function putItemInInventory

remotes/origin/nextcycle
Kai Kehres 2 years ago
parent
commit
09893d1efa
  1. 60
      src/c/character.c
  2. 13
      src/c/character.h
  3. 2
      test/c/test_character.c

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

13
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

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

Loading…
Cancel
Save