Browse Source

Merge pull request #11 from Mac10goesBRRRT/nextcycle

Nextcycle
remotes/origin/orga
Mac10goesBRRRT 2 years ago
committed by GitHub
parent
commit
b6bbdec1f4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 261
      src/c/character.c
  2. 88
      src/c/character.h
  3. 64
      src/c/encounter.c
  4. 14
      src/c/encounter.h
  5. 31
      src/c/spell.c
  6. 11
      src/c/spell.h
  7. 152
      test/c/test_character.c
  8. 44
      test/c/test_encounter.c
  9. 56
      test/c/test_spell.c

261
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,90 +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 setPlayerManaPoints (Player *player, int newManaPoints) {
player->manaPoints = newManaPoints;
}
int getPlayerManaPoints (Player *player) {
return player->manaPoints;
}

88
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,19 +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 setPlayerManaPoints (Player *player, int newManaPoints);
int getPlayerManaPoints (Player *player);
#endif

64
src/c/encounter.c

@ -5,6 +5,7 @@
#include "character.h"
#include "encounter.h"
#include "spell.h"
#include "playerinput.h"
#include "helper.h"
@ -17,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;
}
@ -29,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)
@ -58,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;
@ -76,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;
@ -107,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
@ -125,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)
@ -237,4 +238,19 @@ int createRandomEnemy(enemy* enemy)
break;
}
return enemyType;
}
bool dodge (Player *player, enemy* enemy) {
if (randomIntRange(1,20) + player->dexterity > 15)
{
return true;
}
return false;
}
void rest(Player *player) {
setPlayerHealthPoints(player, getPlayerMaxHealthPoints(player));
setPlayerManaPoints(player, 10);
setPlayerStatus(player, SPELL_EFFECT_NONE);
setPlayerStatusDuration(player, 0);
}

14
src/c/encounter.h

@ -14,15 +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);
int fight(Player *player, enemy* enemy);
bool dodge (Player *player, enemy* enemy);
void rest(Player *player);

31
src/c/spell.c

@ -5,9 +5,10 @@
#include "character.h"
#include "spell.h"
SpellEffect spellFireball(Character *character) {
SpellEffect spellFireball(Player *player) {
SpellEffect fireball;
fireball.damage = 10 + (getCharacterIntelligence(character) / 2);
fireball.id = 0;
fireball.damage = 10 + (getPlayerIntelligence(player) / 2);
fireball.healing = 0;
fireball.manaCost = 10;
fireball.effect = SPELL_EFFECT_NONE;
@ -15,19 +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.damage = 10 + (getCharacterIntelligence(character) / 2);
lightning.id = 2;
lightning.damage = 10 + (getPlayerIntelligence(player) / 2);
lightning.healing = 0;
lightning.manaCost = 10;
lightning.effect = SPELL_EFFECT_STUN;
@ -35,12 +38,24 @@ 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(Player *player) {
SpellEffect freeze;
freeze.id = 4;
freeze.damage = 0;
freeze.healing = 0;
freeze.manaCost = 10;
freeze.effect = SPELL_EFFECT_FREEZE;
freeze.effectDuration = 2;
return freeze;
}

11
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 {
@ -11,10 +11,11 @@ enum {
};
SpellEffect spellFireball(Character *character);
SpellEffect spellHeal(Character *character);
SpellEffect spellLightning(Character *character);
SpellEffect spellRegeneration (Character *character);
SpellEffect spellFireball(Player *player);
SpellEffect spellHeal(Player *player);
SpellEffect spellLightning(Player *player);
SpellEffect spellRegeneration (Player *player);
SpellEffect spellFreeze(Player *player);
#endif

152
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

44
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

56
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)
{
int result = spellFireball(&testCharacter).damage;
TEST_ASSERT_EQUAL_INT(10,result);
result = spellFireball(&testCharacter2).damage;
TEST_ASSERT_EQUAL_INT(13,result);
SpellEffect result = spellFireball(&testPlayer);
TEST_ASSERT_EQUAL_INT(10,result.damage);
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
Loading…
Cancel
Save