From 6c1a6334b03b2a164980f17ef168e03cd410f704 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sun, 29 Jan 2023 14:23:49 +0100 Subject: [PATCH 1/5] prod: created spellFreeze --- src/c/spell.c | 10 ++++++++++ src/c/spell.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/c/spell.c b/src/c/spell.c index 1266eec..35a53c9 100644 --- a/src/c/spell.c +++ b/src/c/spell.c @@ -43,4 +43,14 @@ SpellEffect spellRegeneration (Character *character) { regeneration.effect = SPELL_EFFECT_REGENERATION; regeneration.effectDuration = 2; return regeneration; +} + +SpellEffect spellFreeze(Character *character) { + SpellEffect freeze; + freeze.damage = 0; + freeze.healing = 0; + freeze.manaCost = 10; + freeze.effect = SPELL_EFFECT_FREEZE; + freeze.effectDuration = 2; + return freeze; } \ No newline at end of file diff --git a/src/c/spell.h b/src/c/spell.h index d9711cd..bcf4445 100644 --- a/src/c/spell.h +++ b/src/c/spell.h @@ -15,6 +15,7 @@ SpellEffect spellFireball(Character *character); SpellEffect spellHeal(Character *character); SpellEffect spellLightning(Character *character); SpellEffect spellRegeneration (Character *character); +SpellEffect spellFreeze(Character *character); #endif \ No newline at end of file From 991341e741dbb4016f892e215559d3a133c70aed Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sun, 29 Jan 2023 14:34:59 +0100 Subject: [PATCH 2/5] prod: created getter setter manaPoints --- src/c/character.c | 8 ++++++++ src/c/character.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/c/character.c b/src/c/character.c index 9c46cf7..4e3ef63 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -334,4 +334,12 @@ int checkStatus (Character *character) { return getCharacterStatus(character); break; } +} + +void setCharacterManaPoints (Character *character, int newManaPoints) { + character->manaPoints = newManaPoints; +} + +int getCharacterManaPoints (Character *character) { + return character->manaPoints; } \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index 2c8a708..0403686 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -136,4 +136,8 @@ void setCharacterStatusDuration (Character *character, int newStatusDuration); int getCharacterStatusDuration (Character *character); int checkStatus (Character *character); + +void setCharacterManaPoints (Character *character, int newManaPoints); + +int getCharacterManaPoints (Character *character); #endif \ No newline at end of file From 896b0934c8df343e60b96f2e943395641bf1b9d7 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Mon, 30 Jan 2023 13:46:10 +0100 Subject: [PATCH 3/5] prod: created function dodge --- src/c/character.c | 1 - src/c/encounter.c | 9 +++++++++ src/c/encounter.h | 1 + src/c/spell.c | 5 +++++ src/c/spell.h | 2 +- test/c/test_spell.c | 8 ++++---- 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/c/character.c b/src/c/character.c index 4e3ef63..0f05142 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -335,7 +335,6 @@ int checkStatus (Character *character) { break; } } - void setCharacterManaPoints (Character *character, int newManaPoints) { character->manaPoints = newManaPoints; } diff --git a/src/c/encounter.c b/src/c/encounter.c index 2c25444..d456dc1 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -5,6 +5,7 @@ #include "character.h" #include "encounter.h" +#include "spell.h" #include "playerinput.h" #include "helper.h" @@ -237,4 +238,12 @@ int createRandomEnemy(enemy* enemy) break; } return enemyType; +} + +bool dodge (Character *character, enemy* enemy) { + if (randomIntRange(1,20) + character->dexterity > 15) + { + return true; + } + return false; } \ No newline at end of file diff --git a/src/c/encounter.h b/src/c/encounter.h index 796f555..52b74d4 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -23,6 +23,7 @@ void enemyDamaged(enemy* enemy, Character* character); bool enemyChoosesHeal(enemy* enemy); int switchTurns(int currentTurn); int fight(Character *character, enemy* enemy); +bool dodge (Character *character, enemy* enemy); diff --git a/src/c/spell.c b/src/c/spell.c index 35a53c9..bd9b2a5 100644 --- a/src/c/spell.c +++ b/src/c/spell.c @@ -7,6 +7,7 @@ SpellEffect spellFireball(Character *character) { SpellEffect fireball; + fireball.id = 0; fireball.damage = 10 + (getCharacterIntelligence(character) / 2); fireball.healing = 0; fireball.manaCost = 10; @@ -17,6 +18,7 @@ SpellEffect spellFireball(Character *character) { SpellEffect spellHeal(Character *character) { SpellEffect heal; + heal.id = 1; heal.damage = 0; heal.healing = 10 + (getCharacterIntelligence(character) / 3); heal.manaCost = 10; @@ -27,6 +29,7 @@ SpellEffect spellHeal(Character *character) { SpellEffect spellLightning(Character *character) { SpellEffect lightning; + lightning.id = 2; lightning.damage = 10 + (getCharacterIntelligence(character) / 2); lightning.healing = 0; lightning.manaCost = 10; @@ -37,6 +40,7 @@ SpellEffect spellLightning(Character *character) { SpellEffect spellRegeneration (Character *character) { SpellEffect regeneration; + regeneration.id = 3; regeneration.damage = 0; regeneration.healing = 5 + (getCharacterIntelligence(character) / 4); regeneration.manaCost = 10; @@ -47,6 +51,7 @@ SpellEffect spellRegeneration (Character *character) { SpellEffect spellFreeze(Character *character) { SpellEffect freeze; + freeze.id = 4; freeze.damage = 0; freeze.healing = 0; freeze.manaCost = 10; diff --git a/src/c/spell.h b/src/c/spell.h index bcf4445..689007b 100644 --- a/src/c/spell.h +++ b/src/c/spell.h @@ -3,7 +3,7 @@ typedef struct { - int damage, healing, manaCost, effect, effectDuration; + int id,damage, healing, manaCost, effect, effectDuration; } SpellEffect; enum { diff --git a/test/c/test_spell.c b/test/c/test_spell.c index 00651aa..a1f5ead 100644 --- a/test/c/test_spell.c +++ b/test/c/test_spell.c @@ -32,10 +32,10 @@ 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); + SpellEffect result = spellFireball(&testCharacter); + TEST_ASSERT_EQUAL_INT(10,result.damage); + result = spellFireball(&testCharacter2); + TEST_ASSERT_EQUAL_INT(13,result.damage); } void test_spellHeal(void) From 17a4c084361d375055260c4673f6425017391573 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Wed, 1 Feb 2023 09:58:05 +0100 Subject: [PATCH 4/5] prod: created rest function --- src/c/encounter.c | 7 +++++++ src/c/encounter.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/c/encounter.c b/src/c/encounter.c index d456dc1..e104338 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -246,4 +246,11 @@ bool dodge (Character *character, enemy* enemy) { return true; } return false; +} + +void rest(Character *character) { + setCharacterHealthPoints(character, getCharacterMaxHealthPoints(character)); + setCharacterManaPoints(character, 10); + setCharacterStatus(character, SPELL_EFFECT_NONE); + setCharacterStatusDuration(character, 0); } \ No newline at end of file diff --git a/src/c/encounter.h b/src/c/encounter.h index 52b74d4..6373e7b 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -24,6 +24,7 @@ bool enemyChoosesHeal(enemy* enemy); int switchTurns(int currentTurn); int fight(Character *character, enemy* enemy); bool dodge (Character *character, enemy* enemy); +void rest(Character *character); From 64be330664c6ce88c15e4e65bc36eb570ad6148e Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Wed, 1 Feb 2023 10:06:54 +0100 Subject: [PATCH 5/5] refactoring: changed Character to Player in all Files --- src/c/character.c | 262 ++++++++++++++++++++-------------------- src/c/character.h | 88 +++++++------- src/c/encounter.c | 62 +++++----- src/c/encounter.h | 16 +-- src/c/spell.c | 18 +-- src/c/spell.h | 10 +- test/c/test_character.c | 152 +++++++++++------------ test/c/test_encounter.c | 44 +++---- test/c/test_spell.c | 52 ++++---- 9 files changed, 352 insertions(+), 352 deletions(-) diff --git a/src/c/character.c b/src/c/character.c index 0f05142..2236d29 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -5,106 +5,106 @@ #include "character.h" #include "spell.h" -Character character; +Player player; -void setCharacterHealthPoints (Character *character, int newHealthPoints){ - character->healthPoints = newHealthPoints; +void setPlayerHealthPoints (Player *player, int newHealthPoints){ + player->healthPoints = newHealthPoints; } -int getCharacterHealthPoints (Character *character) { - return character->healthPoints; +int getPlayerHealthPoints (Player *player) { + return player->healthPoints; } -void setCharacterStrength (Character *character, int newStrength) { - character->strength = newStrength; +void setPlayerStrength (Player *player, int newStrength) { + player->strength = newStrength; } -int getCharacterStrength (Character *character) { - return character->strength; +int getPlayerStrength (Player *player) { + return player->strength; } -void setCharacterDexterity (Character *character, int newDexterity) { - character->dexterity = newDexterity; +void setPlayerDexterity (Player *player, int newDexterity) { + player->dexterity = newDexterity; } -int getCharacterDexterity (Character *character) { - return character->dexterity; +int getPlayerDexterity (Player *player) { + return player->dexterity; } -void setCharacterIntelligence (Character *character, int newIntelligence) { - character->intelligence = newIntelligence; +void setPlayerIntelligence (Player *player, int newIntelligence) { + player->intelligence = newIntelligence; } -int getCharacterIntelligence (Character *character) { - return character->intelligence; +int getPlayerIntelligence (Player *player) { + return player->intelligence; } -void setCharacterLevel (Character *character, int newLevel) { - character->level = newLevel; +void setPlayerLevel (Player *player, int newLevel) { + player->level = newLevel; } -int getCharacterLevel (Character *character) { - return character->level; +int getPlayerLevel (Player *player) { + return player->level; } -void setCharacterExp (Character *character, int newExp) { - character->exp = newExp; +void setPlayerExp (Player *player, int newExp) { + player->exp = newExp; } -int getCharacterExp (Character *character) { - return character->exp; +int getPlayerExp (Player *player) { + return player->exp; } -void setCharacterMaxExp (Character *character, int newMaxExp) { - character->maxExp = newMaxExp; +void setPlayerMaxExp (Player *player, int newMaxExp) { + player->maxExp = newMaxExp; } -int getCharacterMaxExp (Character *character) { - return character->maxExp; +int getPlayerMaxExp (Player *player) { + return player->maxExp; } -int calculateStatIncrease (Character *character, int amount) { - return character->level*amount; +int calculateStatIncrease (Player *player, int amount) { + return player->level*amount; } -void setCharacterMaxHealthPoints (Character *character, int newMaxHealthPoints){ - character->maxHealthPoints = newMaxHealthPoints; +void setPlayerMaxHealthPoints (Player *player, int newMaxHealthPoints){ + player->maxHealthPoints = newMaxHealthPoints; } -int getCharacterMaxHealthPoints (Character *character){ - return character->maxHealthPoints; +int getPlayerMaxHealthPoints (Player *player){ + return player->maxHealthPoints; } -void setCharacterAttack (Character *character, int newAttack){ - character->attack = newAttack; +void setPlayerAttack (Player *player, int newAttack){ + player->attack = newAttack; } -int getCharacterAttack (Character *character){ - return character->attack; +int getPlayerAttack (Player *player){ + return player->attack; } -void setCharacterArmor (Character *character, int newArmor){ - character->armor = newArmor; +void setPlayerArmor (Player *player, int newArmor){ + player->armor = newArmor; } -int getCharacterArmor (Character *character){ - return character->armor; +int getPlayerArmor (Player *player){ + return player->armor; } -void setCharacterGold (Character *character, int newGold){ - character->gold = newGold; +void setPlayerGold (Player *player, int newGold){ + player->gold = newGold; } -int getCharacterGold (Character *character){ - return character->gold; +int getPlayerGold (Player *player){ + return player->gold; } -void setCharacterName (Character *character, char *newName) { - strcpy(character->name,newName); +void setPlayerName (Player *player, char *newName) { + strcpy(player->name,newName); } -char* getCharacterName (Character *character) { - return character->name; +char* getPlayerName (Player *player) { + return player->name; } int getWeaponAttack (Weapon *weapon) { @@ -123,81 +123,81 @@ int setWeaponDurability (Weapon *weapon, int newDurability) { weapon->durability = newDurability; } -void setCharacterWeaponClass (Character* character, int weaponClass) { - character->weaponClass = weaponClass; +void setPlayerWeaponClass (Player* player, int weaponClass) { + player->weaponClass = weaponClass; } -int getCharacterWeaponClass (Character* character) { - return character->weaponClass; +int getPlayerWeaponClass (Player* player) { + return player->weaponClass; } -void increaseStat (Character *character, int stat, int amount) { +void increaseStat (Player *player, int stat, int amount) { switch (stat) { case 1: - character->strength += amount;break; + player->strength += amount;break; case 2: - character->dexterity += amount;break; + player->dexterity += amount;break; case 3: - character->intelligence += amount;break; + player->intelligence += amount;break; case 4: - character->healthPoints += amount;break; + player->healthPoints += amount;break; case 5: - character->manaPoints += amount;break; + player->manaPoints += amount;break; case 6: - character->level += amount;break; + player->level += amount;break; case 7: - character->exp += amount;break; + player->exp += amount;break; case 8: - character->maxExp += amount;break; + player->maxExp += amount;break; default: break; } } -void levelUp (Character *character) { - if (getCharacterExp(character) > getCharacterMaxExp(character)) { - increaseStat(character,LEVEL,1); - setCharacterExp(character,getCharacterExp(character)-getCharacterMaxExp(character)); +void levelUp (Player *player) { + if (getPlayerExp(player) > getPlayerMaxExp(player)) { + increaseStat(player,LEVEL,1); + setPlayerExp(player,getPlayerExp(player)-getPlayerMaxExp(player)); } } -int calculateDamage (Character *character,Weapon *weapon) { - switch (character->weaponClass) +int calculateDamage (Player *player,Weapon *weapon) { + switch (player->weaponClass) { case 1: - return character->strength*weapon->attack; + return player->strength*weapon->attack; case 2: - return character->dexterity*weapon->attack; + return player->dexterity*weapon->attack; case 3: - return character->intelligence*weapon->attack; + return player->intelligence*weapon->attack; default: return 1; } } -void setCharacterStatPoints (Character* character, int newStatPoints) { - character->statPoints = newStatPoints; +void setPlayerStatPoints (Player* player, int newStatPoints) { + player->statPoints = newStatPoints; } -int getCharacterStatPoints (Character* character) { - return character->statPoints; +int getPlayerStatPoints (Player* player) { + return player->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 initializePlayer (Player *player,int weaponClass) { + setPlayerHealthPoints(player,100); + setPlayerStrength(player,10); + setPlayerDexterity(player,10); + setPlayerIntelligence(player,10); + setPlayerLevel(player,1); + setPlayerExp(player,0); + setPlayerMaxExp(player,100); + setPlayerMaxHealthPoints(player,100); + setPlayerAttack(player,10); + setPlayerArmor(player,0); + setPlayerGold(player,0); + setPlayerName(player,"Player"); + setPlayerWeaponClass(player,weaponClass); + setPlayerStatPoints(player,0); } void setItemID (Item *item, int newID) { @@ -248,97 +248,97 @@ char* getItemName (Item *item) { return item->name; } -void setCharacterStatus (Character *character, int newStatus) { - character->status = newStatus; +void setPlayerStatus (Player *player, int newStatus) { + player->status = newStatus; } -int getCharacterStatus (Character *character) { - return character->status; +int getPlayerStatus (Player *player) { + return player->status; } -void setCharacterStatusDuration (Character *character, int newStatusDuration) { - character->statusDuration = newStatusDuration; +void setPlayerStatusDuration (Player *player, int newStatusDuration) { + player->statusDuration = newStatusDuration; } -int getCharacterStatusDuration (Character *character) { - return character->statusDuration; +int getPlayerStatusDuration (Player *player) { + return player->statusDuration; } -void initializeInventory (Character *character) { +void initializeInventory (Player *player) { for (int i = 0; i < 10; i++) { - character->inventory[i] = NULL; + player->inventory[i] = NULL; } } -void putItemInInventory (Character *character, Item *item,int inventorySlot) { +void putItemInInventory (Player *player, 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) { + } else if (player->inventory[inventorySlot] == NULL) { printf("Inventory slot is already occupied\n"); } else { - character->inventory[inventorySlot] = item; + player->inventory[inventorySlot] = item; } } -Item * getItemInInventory (Character *character, int inventorySlot) { +Item * getItemInInventory (Player *player, 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) { + } else if (player->inventory[inventorySlot] == NULL) { printf("Inventory slot is empty\n"); return NULL; } else { - return character->inventory[inventorySlot]; + return player->inventory[inventorySlot]; } } -int checkStatus (Character *character) { - switch (character->status) +int checkStatus (Player *player) { + switch (player->status) { case SPELL_EFFECT_NONE: break; case SPELL_EFFECT_BURN: - setCharacterStatusDuration(character,getCharacterStatusDuration(character)-1); - if (getCharacterStatusDuration == 0) { - setCharacterStatus(character,SPELL_EFFECT_NONE); + setPlayerStatusDuration(player,getPlayerStatusDuration(player)-1); + if (getPlayerStatusDuration == 0) { + setPlayerStatus(player,SPELL_EFFECT_NONE); } - return getCharacterStatus(character); + return getPlayerStatus(player); break; case SPELL_EFFECT_FREEZE: - setCharacterStatusDuration(character,getCharacterStatusDuration(character)-1); - if (getCharacterStatusDuration == 0) { - setCharacterStatus(character,SPELL_EFFECT_NONE); + setPlayerStatusDuration(player,getPlayerStatusDuration(player)-1); + if (getPlayerStatusDuration == 0) { + setPlayerStatus(player,SPELL_EFFECT_NONE); } - return getCharacterStatus(character); + return getPlayerStatus(player); break; case SPELL_EFFECT_STUN: - setCharacterStatusDuration(character,getCharacterStatusDuration(character)-1); - if (getCharacterStatusDuration == 0) { - setCharacterStatus(character,SPELL_EFFECT_NONE); + setPlayerStatusDuration(player,getPlayerStatusDuration(player)-1); + if (getPlayerStatusDuration == 0) { + setPlayerStatus(player,SPELL_EFFECT_NONE); } - return getCharacterStatus(character); + return getPlayerStatus(player); break; case SPELL_EFFECT_REGENERATION: - setCharacterStatusDuration(character,getCharacterStatusDuration(character)-1); - if (getCharacterStatusDuration == 0) { - setCharacterStatus(character,SPELL_EFFECT_NONE); + setPlayerStatusDuration(player,getPlayerStatusDuration(player)-1); + if (getPlayerStatusDuration == 0) { + setPlayerStatus(player,SPELL_EFFECT_NONE); } - return getCharacterStatus(character); + return getPlayerStatus(player); break; default: - return getCharacterStatus(character); + return getPlayerStatus(player); break; } } -void setCharacterManaPoints (Character *character, int newManaPoints) { - character->manaPoints = newManaPoints; +void setPlayerManaPoints (Player *player, int newManaPoints) { + player->manaPoints = newManaPoints; } -int getCharacterManaPoints (Character *character) { - return character->manaPoints; +int getPlayerManaPoints (Player *player) { + return player->manaPoints; } \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index 0403686..ef403a4 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -10,7 +10,7 @@ typedef struct { int attack,armor,maxHealthPoints,gold,weaponClass,statPoints,status,statusDuration; char name [50]; Item *inventory[10]; -} Character; +} Player; typedef struct { int attack,durability; char name [50]; @@ -23,63 +23,63 @@ enum { STRENGTH = 1, DEXTERITY = 2, INTELLIGENCE = 3, HEALTHPOINTS = 4, MANAPOINTS = 5, LEVEL = 6, EXP = 7, MAXEXP = 8 }; -void setCharacterHealthPoints (Character *character, int newHealthPoints); +void setPlayerHealthPoints (Player *player, int newHealthPoints); -int getCharacterHealthPoints (Character *character); +int getPlayerHealthPoints (Player *player); -void setCharacterStrength (Character *character, int newStrength); +void setPlayerStrength (Player *player, int newStrength); -int getCharacterStrength (Character *character); +int getPlayerStrength (Player *player); -void setCharacterDexterity (Character *character, int newDexterity); +void setPlayerDexterity (Player *player, int newDexterity); -int getCharacterDexterity (Character *character); +int getPlayerDexterity (Player *player); -void setCharacterIntelligence (Character *character, int newIntelligence); +void setPlayerIntelligence (Player *player, int newIntelligence); -int getCharacterIntelligence (Character *character); +int getPlayerIntelligence (Player *player); -void setCharacterLevel (Character *character, int newLevel); +void setPlayerLevel (Player *player, int newLevel); -int getCharacterLevel (Character *character); +int getPlayerLevel (Player *player); -void setCharacterExp (Character *character, int newExp); +void setPlayerExp (Player *player, int newExp); -int getCharacterExp (Character *character); +int getPlayerExp (Player *player); -void setCharacterMaxExp (Character *character, int newMaxExp); +void setPlayerMaxExp (Player *player, int newMaxExp); -int getCharacterMaxExp (Character *character); +int getPlayerMaxExp (Player *player); -void increaseStat (Character *character, int stat, int amount); +void increaseStat (Player *player, int stat, int amount); -int calculateStatIncrease (Character *character, int amount); +int calculateStatIncrease (Player *player, int amount); -void setCharacterMaxHealthPoints (Character *character, int newMaxHealthPoints); +void setPlayerMaxHealthPoints (Player *player, int newMaxHealthPoints); -int getCharacterMaxHealthPoints (Character *character); +int getPlayerMaxHealthPoints (Player *player); -void setCharacterAttack (Character *character, int newAttack); +void setPlayerAttack (Player *player, int newAttack); -int getCharacterAttack (Character *character); +int getPlayerAttack (Player *player); -void setCharacterArmor (Character *character, int newArmor); +void setPlayerArmor (Player *player, int newArmor); -int getCharacterArmor (Character *character); +int getPlayerArmor (Player *player); -void setCharacterGold (Character *character, int newGold); +void setPlayerGold (Player *player, int newGold); -int getCharacterGold (Character *character); +int getPlayerGold (Player *player); -void levelUp (Character *character); +void levelUp (Player *player); -void setCharacterName (Character *character, char newName[]); +void setPlayerName (Player *player, char newName[]); -char* getCharacterName (Character *character); +char* getPlayerName (Player *player); -void setCharacterWeaponClass (Character *character, int newWeaponClass); +void setPlayerWeaponClass (Player *player, int newWeaponClass); -int getCharacterWeaponClass (Character *character); +int getPlayerWeaponClass (Player *player); int getWeaponAttack (Weapon *weapon); @@ -89,13 +89,13 @@ int getWeaponDurability (Weapon *weapon); int setWeaponDurability (Weapon *weapon, int newDurability); -int calculateDamage (Character *character,Weapon *weapon); +int calculateDamage (Player *player,Weapon *weapon); -void setCharacterStatPoints (Character *character, int newStatPoints); +void setPlayerStatPoints (Player *player, int newStatPoints); -int getCharacterStatPoints (Character *character); +int getPlayerStatPoints (Player *player); -void initializeCharacter (Character *character,int weaponClass); +void initializePlayer (Player *player,int weaponClass); void setItemID (Item *item, int newID); @@ -121,23 +121,23 @@ void setItemName (Item *item, char newName[]); char* getItemName (Item *item); -void putItemInInventory (Character *character, Item *item, int inventorySlot); +void putItemInInventory (Player *player, Item *item, int inventorySlot); -void initializeInventory (Character *character); +void initializeInventory (Player *player); -Item * getItemInInventory (Character *character, int inventorySlot); +Item * getItemInInventory (Player *player, int inventorySlot); -void setCharacterStatus (Character *character, int newStatus); +void setPlayerStatus (Player *player, int newStatus); -int getCharacterStatus (Character *character); +int getPlayerStatus (Player *player); -void setCharacterStatusDuration (Character *character, int newStatusDuration); +void setPlayerStatusDuration (Player *player, int newStatusDuration); -int getCharacterStatusDuration (Character *character); +int getPlayerStatusDuration (Player *player); -int checkStatus (Character *character); +int checkStatus (Player *player); -void setCharacterManaPoints (Character *character, int newManaPoints); +void setPlayerManaPoints (Player *player, int newManaPoints); -int getCharacterManaPoints (Character *character); +int getPlayerManaPoints (Player *player); #endif \ No newline at end of file diff --git a/src/c/encounter.c b/src/c/encounter.c index e104338..909362f 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -18,9 +18,9 @@ humanoide gegner haben heiltränke mit denen sie sich ggf heilen. heilung erfolgt dann, wenn bestimmte hp (50%) unterschritten wird. wird allerdings gewürfelt, je niedriger die hp%, desto höher die chance. */ -bool playerAlive(Character *character) +bool playerAlive(Player *player) { - if (getCharacterHealthPoints(character) > 0) + if (getPlayerHealthPoints(player) > 0) { return true; } @@ -30,24 +30,24 @@ bool playerAlive(Character *character) } } -int playerHeal(Character* character, int amount) +int playerHeal(Player* player, int amount) { - setCharacterHealthPoints(character, getCharacterHealthPoints(character)+ amount); - if (getCharacterHealthPoints(character) > getCharacterMaxHealthPoints(character)) + setPlayerHealthPoints(player, getPlayerHealthPoints(player)+ amount); + if (getPlayerHealthPoints(player) > getPlayerMaxHealthPoints(player)) { - setCharacterHealthPoints(character, getCharacterMaxHealthPoints(character)); + setPlayerHealthPoints(player, getPlayerMaxHealthPoints(player)); } - return getCharacterHealthPoints(character); + return getPlayerHealthPoints(player); } -int playerDamaged(enemy* enemy, Character* character) +int playerDamaged(enemy* enemy, Player* player) { - int damagedealt = getEnemyDamage(enemy) - getCharacterArmor(character); + int damagedealt = getEnemyDamage(enemy) - getPlayerArmor(player); if (damagedealt < 1) { damagedealt = 1; } - return getCharacterHealthPoints(character) - damagedealt; + return getPlayerHealthPoints(player) - damagedealt; } void enemyHeal(enemy *enemy, int healAmount) @@ -59,9 +59,9 @@ void enemyHeal(enemy *enemy, int healAmount) setEnemyHealth(enemy, getEnemyHealth(enemy) + healAmount); } -void enemyDamaged(enemy *enemy,Character* character) +void enemyDamaged(enemy *enemy,Player* player) { - int damagedealt = getCharacterAttack(character) - getEnemyArmor(enemy); + int damagedealt = getPlayerAttack(player) - getEnemyArmor(enemy); if (damagedealt < 1) { damagedealt = 1; @@ -77,23 +77,23 @@ int switchTurns(int currentTurn) return currentTurn; } -int fight(Character *character, enemy* enemy) +int fight(Player *player, enemy* enemy) { int playerH = 0; int currentTurn = 2; char decision; - while (playerAlive(character) && getEnemyHealth(enemy) > 0) + while (playerAlive(player) && getEnemyHealth(enemy) > 0) { if (currentTurn != 1) { decision = playerInputChar(); switch(decision){ case 'a': - enemyDamaged(enemy, character); + enemyDamaged(enemy, player); break; case 'h': - playerH = playerHeal(character,10); - setCharacterHealthPoints(character, playerH); + playerH = playerHeal(player,10); + setPlayerHealthPoints(player, playerH); break; case 'f': return 2; @@ -108,16 +108,16 @@ int fight(Character *character, enemy* enemy) } else { - playerH = playerDamaged(enemy, character); - setCharacterHealthPoints(character, playerH); + playerH = playerDamaged(enemy, player); + setPlayerHealthPoints(player, playerH); } } currentTurn = switchTurns(currentTurn); } - if (playerAlive(character)) + if (playerAlive(player)) { - setCharacterExp(character, getCharacterExp(character) + getEnemyExp(enemy)); - setCharacterGold(character, getCharacterGold(character) + getEnemyGold(enemy)); + setPlayerExp(player, getPlayerExp(player) + getEnemyExp(enemy)); + setPlayerGold(player, getPlayerGold(player) + getEnemyGold(enemy)); return 1; } else @@ -126,8 +126,8 @@ int fight(Character *character, enemy* enemy) } } -int rollInitiative (Character *character) { - return randomIntRange(1,20) + character->dexterity; +int rollInitiative (Player *player) { + return randomIntRange(1,20) + player->dexterity; } bool enemyChoosesHeal(enemy* enemy) @@ -240,17 +240,17 @@ int createRandomEnemy(enemy* enemy) return enemyType; } -bool dodge (Character *character, enemy* enemy) { - if (randomIntRange(1,20) + character->dexterity > 15) +bool dodge (Player *player, enemy* enemy) { + if (randomIntRange(1,20) + player->dexterity > 15) { return true; } return false; } -void rest(Character *character) { - setCharacterHealthPoints(character, getCharacterMaxHealthPoints(character)); - setCharacterManaPoints(character, 10); - setCharacterStatus(character, SPELL_EFFECT_NONE); - setCharacterStatusDuration(character, 0); +void rest(Player *player) { + setPlayerHealthPoints(player, getPlayerMaxHealthPoints(player)); + setPlayerManaPoints(player, 10); + setPlayerStatus(player, SPELL_EFFECT_NONE); + setPlayerStatusDuration(player, 0); } \ No newline at end of file diff --git a/src/c/encounter.h b/src/c/encounter.h index 6373e7b..2a9ea42 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -14,17 +14,17 @@ typedef struct enemy{ } enemy; -bool playerAlive(Character *character); -int playerHeal(Character* character,int amount); -int playerDamaged(enemy* enemy, Character* character); -int rollInitiative (Character *character); +bool playerAlive(Player *player); +int playerHeal(Player* player,int amount); +int playerDamaged(enemy* enemy, Player* player); +int rollInitiative (Player *player); void enemyHeal(enemy *enemy, int healAmount); -void enemyDamaged(enemy* enemy, Character* character); +void enemyDamaged(enemy* enemy, Player* player); bool enemyChoosesHeal(enemy* enemy); int switchTurns(int currentTurn); -int fight(Character *character, enemy* enemy); -bool dodge (Character *character, enemy* enemy); -void rest(Character *character); +int fight(Player *player, enemy* enemy); +bool dodge (Player *player, enemy* enemy); +void rest(Player *player); diff --git a/src/c/spell.c b/src/c/spell.c index bd9b2a5..19c8db6 100644 --- a/src/c/spell.c +++ b/src/c/spell.c @@ -5,10 +5,10 @@ #include "character.h" #include "spell.h" -SpellEffect spellFireball(Character *character) { +SpellEffect spellFireball(Player *player) { SpellEffect fireball; fireball.id = 0; - fireball.damage = 10 + (getCharacterIntelligence(character) / 2); + fireball.damage = 10 + (getPlayerIntelligence(player) / 2); fireball.healing = 0; fireball.manaCost = 10; fireball.effect = SPELL_EFFECT_NONE; @@ -16,21 +16,21 @@ SpellEffect spellFireball(Character *character) { return fireball; } -SpellEffect spellHeal(Character *character) { +SpellEffect spellHeal(Player *player) { SpellEffect heal; heal.id = 1; heal.damage = 0; - heal.healing = 10 + (getCharacterIntelligence(character) / 3); + heal.healing = 10 + (getPlayerIntelligence(player) / 3); heal.manaCost = 10; heal.effect = SPELL_EFFECT_NONE; heal.effectDuration = 0; return heal; } -SpellEffect spellLightning(Character *character) { +SpellEffect spellLightning(Player *player) { SpellEffect lightning; lightning.id = 2; - lightning.damage = 10 + (getCharacterIntelligence(character) / 2); + lightning.damage = 10 + (getPlayerIntelligence(player) / 2); lightning.healing = 0; lightning.manaCost = 10; lightning.effect = SPELL_EFFECT_STUN; @@ -38,18 +38,18 @@ SpellEffect spellLightning(Character *character) { return lightning; } -SpellEffect spellRegeneration (Character *character) { +SpellEffect spellRegeneration (Player *player) { SpellEffect regeneration; regeneration.id = 3; regeneration.damage = 0; - regeneration.healing = 5 + (getCharacterIntelligence(character) / 4); + regeneration.healing = 5 + (getPlayerIntelligence(player) / 4); regeneration.manaCost = 10; regeneration.effect = SPELL_EFFECT_REGENERATION; regeneration.effectDuration = 2; return regeneration; } -SpellEffect spellFreeze(Character *character) { +SpellEffect spellFreeze(Player *player) { SpellEffect freeze; freeze.id = 4; freeze.damage = 0; diff --git a/src/c/spell.h b/src/c/spell.h index 689007b..6a6c159 100644 --- a/src/c/spell.h +++ b/src/c/spell.h @@ -11,11 +11,11 @@ enum { }; -SpellEffect spellFireball(Character *character); -SpellEffect spellHeal(Character *character); -SpellEffect spellLightning(Character *character); -SpellEffect spellRegeneration (Character *character); -SpellEffect spellFreeze(Character *character); +SpellEffect spellFireball(Player *player); +SpellEffect spellHeal(Player *player); +SpellEffect spellLightning(Player *player); +SpellEffect spellRegeneration (Player *player); +SpellEffect spellFreeze(Player *player); #endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index cbe09e7..b6eb666 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -1,28 +1,28 @@ #ifdef TEST #include "unity.h" #include "character.h" -Character testCharacter; -Character testCharacter2; +Player testPlayer; +Player testPlayer2; Weapon testWeapon; 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; + testPlayer.healthPoints = 0; + testPlayer2.healthPoints = 15; + testPlayer.strength = 0; + testPlayer2.strength = 5; + testPlayer.dexterity = 0; + testPlayer2.dexterity = 5; + testPlayer.intelligence = 0; + testPlayer2.intelligence = 7; + testPlayer.level = 0; + testPlayer2.level = 5; + testPlayer.exp = 50; + testPlayer2.exp = 110; + testPlayer.maxExp = 100; + testPlayer2.maxExp = 100; + testPlayer.attack = 5; + testPlayer2.weaponClass = SWORD; testWeapon.attack = 5; testWeapon.durability = 100; @@ -32,112 +32,112 @@ void tearDown(void) { } -void test_setCharacterHealthPoints(void) +void test_setPlayerHealthPoints(void) { - TEST_ASSERT_EQUAL_INT(0,testCharacter.healthPoints); - setCharacterHealthPoints(&testCharacter,50); - TEST_ASSERT_EQUAL_INT(50,testCharacter.healthPoints); + TEST_ASSERT_EQUAL_INT(0,testPlayer.healthPoints); + setPlayerHealthPoints(&testPlayer,50); + TEST_ASSERT_EQUAL_INT(50,testPlayer.healthPoints); } -void test_getCharacterHealthPoints (void) { - TEST_ASSERT_EQUAL_INT(15,getCharacterHealthPoints(&testCharacter2)); +void test_getPlayerHealthPoints (void) { + TEST_ASSERT_EQUAL_INT(15,getPlayerHealthPoints(&testPlayer2)); } -void test_setCharacterStrenght(void) { - TEST_ASSERT_EQUAL_INT(0,testCharacter.strength); - setCharacterStrength(&testCharacter,50); - TEST_ASSERT_EQUAL_INT(50,testCharacter.strength); +void test_setPlayerStrenght(void) { + TEST_ASSERT_EQUAL_INT(0,testPlayer.strength); + setPlayerStrength(&testPlayer,50); + TEST_ASSERT_EQUAL_INT(50,testPlayer.strength); } -void test_getCharacterStrength(void) { - TEST_ASSERT_EQUAL_INT(5,getCharacterStrength(&testCharacter2)); +void test_getPlayerStrength(void) { + TEST_ASSERT_EQUAL_INT(5,getPlayerStrength(&testPlayer2)); } -void test_setCharacterDexterity(void) { - TEST_ASSERT_EQUAL_INT(0,testCharacter.dexterity); - setCharacterDexterity(&testCharacter,50); - TEST_ASSERT_EQUAL_INT(50,testCharacter.dexterity); +void test_setPlayerDexterity(void) { + TEST_ASSERT_EQUAL_INT(0,testPlayer.dexterity); + setPlayerDexterity(&testPlayer,50); + TEST_ASSERT_EQUAL_INT(50,testPlayer.dexterity); } -void test_getCharacterDexterity(void) { - TEST_ASSERT_EQUAL_INT(5,getCharacterDexterity(&testCharacter2)); +void test_getPlayerDexterity(void) { + TEST_ASSERT_EQUAL_INT(5,getPlayerDexterity(&testPlayer2)); } -void test_setCharacterIntelligence(void) { - TEST_ASSERT_EQUAL_INT(0,testCharacter.intelligence); - setCharacterIntelligence(&testCharacter,45); - TEST_ASSERT_EQUAL_INT(45,testCharacter.intelligence); +void test_setPlayerIntelligence(void) { + TEST_ASSERT_EQUAL_INT(0,testPlayer.intelligence); + setPlayerIntelligence(&testPlayer,45); + TEST_ASSERT_EQUAL_INT(45,testPlayer.intelligence); } -void test_getCharacterIntelligence(void) { - TEST_ASSERT_EQUAL_INT(7,getCharacterIntelligence(&testCharacter2)); +void test_getPlayerIntelligence(void) { + TEST_ASSERT_EQUAL_INT(7,getPlayerIntelligence(&testPlayer2)); } -void test_setCharacterLevel(void) { - TEST_ASSERT_EQUAL_INT(0,testCharacter.level); - setCharacterLevel(&testCharacter,1); - TEST_ASSERT_EQUAL_INT(1,testCharacter.level); +void test_setPlayerLevel(void) { + TEST_ASSERT_EQUAL_INT(0,testPlayer.level); + setPlayerLevel(&testPlayer,1); + TEST_ASSERT_EQUAL_INT(1,testPlayer.level); } -void test_getCharacterLevel(void) { - TEST_ASSERT_EQUAL_INT(5,getCharacterLevel(&testCharacter2)); +void test_getPlayerLevel(void) { + TEST_ASSERT_EQUAL_INT(5,getPlayerLevel(&testPlayer2)); } void test_increaseStat(void) { - increaseStat(&testCharacter2,STRENGTH,15); - TEST_ASSERT_EQUAL_INT(20,testCharacter2.strength); - increaseStat(&testCharacter2,INTELLIGENCE,15); - TEST_ASSERT_EQUAL_INT(22,testCharacter2.intelligence); - increaseStat(&testCharacter2,LEVEL,15); - TEST_ASSERT_EQUAL_INT(20,testCharacter2.level); + increaseStat(&testPlayer2,STRENGTH,15); + TEST_ASSERT_EQUAL_INT(20,testPlayer2.strength); + increaseStat(&testPlayer2,INTELLIGENCE,15); + TEST_ASSERT_EQUAL_INT(22,testPlayer2.intelligence); + increaseStat(&testPlayer2,LEVEL,15); + TEST_ASSERT_EQUAL_INT(20,testPlayer2.level); } void test_calculateStatIncrease(void) { - TEST_ASSERT_EQUAL_INT(5,testCharacter2.level); - TEST_ASSERT_EQUAL_INT(25,calculateStatIncrease(&testCharacter2,5)); + TEST_ASSERT_EQUAL_INT(5,testPlayer2.level); + TEST_ASSERT_EQUAL_INT(25,calculateStatIncrease(&testPlayer2,5)); } void test_levelUp_enoughExp (void) { - TEST_ASSERT_EQUAL_INT(5,testCharacter2.level); - levelUp(&testCharacter2); - TEST_ASSERT_EQUAL_INT(6,testCharacter2.level); + TEST_ASSERT_EQUAL_INT(5,testPlayer2.level); + levelUp(&testPlayer2); + TEST_ASSERT_EQUAL_INT(6,testPlayer2.level); } void test_levelUp_enoughExp_loseExp (void) { - TEST_ASSERT_EQUAL_INT(110,testCharacter2.exp); - TEST_ASSERT_EQUAL_INT(100,testCharacter2.maxExp); - levelUp(&testCharacter2); - TEST_ASSERT_EQUAL_INT(10,testCharacter2.exp); + TEST_ASSERT_EQUAL_INT(110,testPlayer2.exp); + TEST_ASSERT_EQUAL_INT(100,testPlayer2.maxExp); + levelUp(&testPlayer2); + TEST_ASSERT_EQUAL_INT(10,testPlayer2.exp); } void test_levelUp_notEnoughExp (void) { - TEST_ASSERT_EQUAL_INT(0,testCharacter.level); - levelUp(&testCharacter); - TEST_ASSERT_EQUAL_INT(0,testCharacter.level); + TEST_ASSERT_EQUAL_INT(0,testPlayer.level); + levelUp(&testPlayer); + TEST_ASSERT_EQUAL_INT(0,testPlayer.level); } void test_levelUp_notEnoughExp_loseExp (void) { - TEST_ASSERT_EQUAL_INT(50,testCharacter.exp); - TEST_ASSERT_EQUAL_INT(100,testCharacter.maxExp); - levelUp(&testCharacter); - TEST_ASSERT_EQUAL_INT(50,testCharacter.exp); + TEST_ASSERT_EQUAL_INT(50,testPlayer.exp); + TEST_ASSERT_EQUAL_INT(100,testPlayer.maxExp); + levelUp(&testPlayer); + TEST_ASSERT_EQUAL_INT(50,testPlayer.exp); } void test_calculateDamage_Sword (void) { - setCharacterWeaponClass(&testCharacter2,SWORD); + setPlayerWeaponClass(&testPlayer2,SWORD); - TEST_ASSERT_EQUAL_INT(25,calculateDamage(&testCharacter2,&testWeapon)); + TEST_ASSERT_EQUAL_INT(25,calculateDamage(&testPlayer2,&testWeapon)); } void test_calculateDamage_Bow (void) { - setCharacterWeaponClass(&testCharacter2,BOW); + setPlayerWeaponClass(&testPlayer2,BOW); - TEST_ASSERT_EQUAL_INT(25,calculateDamage(&testCharacter2,&testWeapon)); + TEST_ASSERT_EQUAL_INT(25,calculateDamage(&testPlayer2,&testWeapon)); } void test_calculateDamage_Staff (void) { - setCharacterWeaponClass(&testCharacter2,STAFF); + setPlayerWeaponClass(&testPlayer2,STAFF); - TEST_ASSERT_EQUAL_INT(35,calculateDamage(&testCharacter2,&testWeapon)); + TEST_ASSERT_EQUAL_INT(35,calculateDamage(&testPlayer2,&testWeapon)); } #endif // TEST \ No newline at end of file diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index d74591e..3d3ff77 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -9,14 +9,14 @@ #include "mock_helper.h" #include "utils.h" -Character testcharacter; +Player testplayer; enemy testenemy; void setUp(void) { - testcharacter.dexterity = 5; - testcharacter.healthPoints = 100; - testcharacter.maxHealthPoints = 100; - testcharacter.attack = 10; + testplayer.dexterity = 5; + testplayer.healthPoints = 100; + testplayer.maxHealthPoints = 100; + testplayer.attack = 10; testenemy.damage = 10; testenemy.health = 50; @@ -33,7 +33,7 @@ void test_isPlayerAlive_healthGreaterZero(void) int health = 100; bool result; // act - result = playerAlive(&testcharacter); + result = playerAlive(&testplayer); // assert TEST_ASSERT_TRUE(result); } @@ -41,10 +41,10 @@ void test_isPlayerAlive_healthGreaterZero(void) void test_isPlayerAlive_healthLowerZero(void) { // arrange - setCharacterHealthPoints(&testcharacter, -1); + setPlayerHealthPoints(&testplayer, -1); bool result; // act - result = playerAlive(&testcharacter); + result = playerAlive(&testplayer); // assert TEST_ASSERT_FALSE(result); @@ -55,7 +55,7 @@ void test_playerIsDamaged(void) // arrange int expectedHealth = 90; // act - int result = playerDamaged(&testenemy, &testcharacter); + int result = playerDamaged(&testenemy, &testplayer); // assert TEST_ASSERT_EQUAL(expectedHealth, result); } @@ -63,12 +63,12 @@ void test_playerIsDamaged(void) void test_playerIsNotOverhealed(void) { // arrange - setCharacterHealthPoints(&testcharacter, 95); + setPlayerHealthPoints(&testplayer, 95); int heal = 10; // act - int result = playerHeal(&testcharacter, heal); + int result = playerHeal(&testplayer, heal); // assert - TEST_ASSERT_EQUAL(getCharacterMaxHealthPoints(&testcharacter), result); + TEST_ASSERT_EQUAL(getPlayerMaxHealthPoints(&testplayer), result); } void test_setEnemyHealth(void) @@ -136,7 +136,7 @@ void test_PlayerAttacksEnemy_DoesDamage(void) // health - (damage - armor) int expectedEnemyHealth = 44; // act - enemyDamaged(&testenemy, &testcharacter); + enemyDamaged(&testenemy, &testplayer); // assert TEST_ASSERT_EQUAL(expectedEnemyHealth, getEnemyHealth(&testenemy)); } @@ -147,7 +147,7 @@ void test_PlayerAttacksEnemy_DoesMinDamage(void) // health - (damage - armor) int expectedEnemyHealth = 49; // act - enemyDamaged(&testenemy,&testcharacter); + enemyDamaged(&testenemy,&testplayer); // assert TEST_ASSERT_EQUAL(expectedEnemyHealth, getEnemyHealth(&testenemy)); } @@ -188,7 +188,7 @@ void test_FightPlayerWins(void) int result; // act //strength,dexterity,intelligence,healthPoints,manaPoints,level,exp,maxExp,attack,armor,maxHealthPoints; - Character testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; + Player testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; playerInputChar_ExpectAndReturn('a'); enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; result = fight(&testChar, &test); @@ -203,7 +203,7 @@ void test_FightEnemyWins(void) int enemyHealth = 100, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 100; int result; // act - Character testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; + Player testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; playerInputChar_ExpectAndReturn('a'); randomInt_ExpectAndReturn(1); enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; @@ -219,7 +219,7 @@ void test_FightPlayerChoosesAttack(void) int enemyHealth = 6, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 100; int result; // act - Character testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; + Player testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; playerInputChar_ExpectAndReturn('a'); enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; fight(&testChar, &test); @@ -235,7 +235,7 @@ void test_FightPlayerHeals_thenAttacks_Wins(void) int enemyHealth = 11, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 100; int result; // act - Character testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; + Player testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; playerInputChar_ExpectAndReturn('h'); randomInt_ExpectAndReturn(1); @@ -254,7 +254,7 @@ void test_FightPlayerFlees(void) int enemyHealth = 11, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 100; int result; // act - Character testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; + Player testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; playerInputChar_ExpectAndReturn('f'); result = fight(&testChar, &test); @@ -368,7 +368,7 @@ void test_enemyChoosesHeal_ThenAttackWins(void) int playerHealth = 10, playerDamage = 10, playerArmor = 0, playerMaxHealth = 10; enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth,1 }; //act - Character testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; + Player testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; playerInputChar_ExpectAndReturn('a'); randomInt_ExpectAndReturn(39); //39%20 = 19 , 19 + 1 = 20 playerInputChar_ExpectAndReturn('a'); @@ -392,8 +392,8 @@ void test_enemyHealsNoPotion(void) int test_rollInitiative (void) { - int initiative = rollInitiative(&testcharacter); + int initiative = rollInitiative(&testplayer); - TEST_ASSERT(testcharacter.dexterity + 1 <= initiative && testcharacter.dexterity + 20 >= initiative); + TEST_ASSERT(testplayer.dexterity + 1 <= initiative && testplayer.dexterity + 20 >= initiative); } #endif // TEST diff --git a/test/c/test_spell.c b/test/c/test_spell.c index a1f5ead..27e8ed7 100644 --- a/test/c/test_spell.c +++ b/test/c/test_spell.c @@ -3,27 +3,27 @@ #include "character.h" #include "spell.h" -Character testCharacter; -Character testCharacter2; +Player testPlayer; +Player testPlayer2; 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; + testPlayer.healthPoints = 0; + testPlayer2.healthPoints = 15; + testPlayer.strength = 0; + testPlayer2.strength = 5; + testPlayer.dexterity = 0; + testPlayer2.dexterity = 5; + testPlayer.intelligence = 0; + testPlayer2.intelligence = 7; + testPlayer.level = 0; + testPlayer2.level = 5; + testPlayer.exp = 50; + testPlayer2.exp = 110; + testPlayer.maxExp = 100; + testPlayer2.maxExp = 100; + testPlayer.attack = 5; + testPlayer2.weaponClass = SWORD; } void tearDown(void) @@ -32,34 +32,34 @@ void tearDown(void) void test_spellFireball(void) { - SpellEffect result = spellFireball(&testCharacter); + SpellEffect result = spellFireball(&testPlayer); TEST_ASSERT_EQUAL_INT(10,result.damage); - result = spellFireball(&testCharacter2); + result = spellFireball(&testPlayer2); TEST_ASSERT_EQUAL_INT(13,result.damage); } void test_spellHeal(void) { - int result = spellHeal(&testCharacter).healing; + int result = spellHeal(&testPlayer).healing; TEST_ASSERT_EQUAL_INT(10,result); - result = spellHeal(&testCharacter2).healing; + result = spellHeal(&testPlayer2).healing; TEST_ASSERT_EQUAL_INT(12,result); } void test_spellLightning(void) { - int result = spellLightning(&testCharacter).damage; + int result = spellLightning(&testPlayer).damage; TEST_ASSERT_EQUAL_INT(10,result); - result = spellLightning(&testCharacter2).damage; + result = spellLightning(&testPlayer2).damage; TEST_ASSERT_EQUAL_INT(13,result); } void test_spellRegeneration(void) { - int result = spellRegeneration(&testCharacter).healing; + int result = spellRegeneration(&testPlayer).healing; TEST_ASSERT_EQUAL_INT(5,result); - result = spellRegeneration(&testCharacter2).healing; + result = spellRegeneration(&testPlayer2).healing; TEST_ASSERT_EQUAL_INT(6,result); } #endif // TEST \ No newline at end of file