Browse Source

prod: created function getItemInInventory

remotes/origin/nextcycle
Kai Kehres 2 years ago
parent
commit
ddf08bfef0
  1. 16
      src/c/character.c
  2. 2
      src/c/character.h

16
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];
}
}

2
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
Loading…
Cancel
Save