Mac10goesBRRRT
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 385 additions and 1 deletions
-
162src/c/character.c
-
53src/c/character.h
-
36src/c/encounter.c
-
2src/c/encounter.h
-
46src/c/spell.c
-
20src/c/spell.h
-
2test/c/test_character.c
-
65test/c/test_spell.c
@ -0,0 +1,46 @@ |
|||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
|
||||
|
#include "character.h" |
||||
|
#include "spell.h" |
||||
|
|
||||
|
SpellEffect spellFireball(Character *character) { |
||||
|
SpellEffect fireball; |
||||
|
fireball.damage = 10 + (getCharacterIntelligence(character) / 2); |
||||
|
fireball.healing = 0; |
||||
|
fireball.manaCost = 10; |
||||
|
fireball.effect = SPELL_EFFECT_NONE; |
||||
|
fireball.effectDuration = 0; |
||||
|
return fireball; |
||||
|
} |
||||
|
|
||||
|
SpellEffect spellHeal(Character *character) { |
||||
|
SpellEffect heal; |
||||
|
heal.damage = 0; |
||||
|
heal.healing = 10 + (getCharacterIntelligence(character) / 3); |
||||
|
heal.manaCost = 10; |
||||
|
heal.effect = SPELL_EFFECT_NONE; |
||||
|
heal.effectDuration = 0; |
||||
|
return heal; |
||||
|
} |
||||
|
|
||||
|
SpellEffect spellLightning(Character *character) { |
||||
|
SpellEffect lightning; |
||||
|
lightning.damage = 10 + (getCharacterIntelligence(character) / 2); |
||||
|
lightning.healing = 0; |
||||
|
lightning.manaCost = 10; |
||||
|
lightning.effect = SPELL_EFFECT_STUN; |
||||
|
lightning.effectDuration = 1; |
||||
|
return lightning; |
||||
|
} |
||||
|
|
||||
|
SpellEffect spellRegeneration (Character *character) { |
||||
|
SpellEffect regeneration; |
||||
|
regeneration.damage = 0; |
||||
|
regeneration.healing = 5 + (getCharacterIntelligence(character) / 4); |
||||
|
regeneration.manaCost = 10; |
||||
|
regeneration.effect = SPELL_EFFECT_REGENERATION; |
||||
|
regeneration.effectDuration = 2; |
||||
|
return regeneration; |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
#ifndef SPELL_H |
||||
|
#define SPELL_H |
||||
|
|
||||
|
|
||||
|
typedef struct { |
||||
|
int damage, healing, manaCost, effect, effectDuration; |
||||
|
} SpellEffect; |
||||
|
|
||||
|
enum { |
||||
|
SPELL_EFFECT_NONE = 0, SPELL_EFFECT_BURN = 1, SPELL_EFFECT_FREEZE = 2, SPELL_EFFECT_STUN =3 , SPELL_EFFECT_REGENERATION = 4 |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
SpellEffect spellFireball(Character *character); |
||||
|
SpellEffect spellHeal(Character *character); |
||||
|
SpellEffect spellLightning(Character *character); |
||||
|
SpellEffect spellRegeneration (Character *character); |
||||
|
|
||||
|
|
||||
|
#endif |
@ -0,0 +1,65 @@ |
|||||
|
#ifdef TEST |
||||
|
#include "unity.h" |
||||
|
#include "character.h" |
||||
|
#include "spell.h" |
||||
|
|
||||
|
Character testCharacter; |
||||
|
Character testCharacter2; |
||||
|
|
||||
|
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; |
||||
|
} |
||||
|
|
||||
|
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); |
||||
|
} |
||||
|
|
||||
|
void test_spellHeal(void) |
||||
|
{ |
||||
|
|
||||
|
int result = spellHeal(&testCharacter).healing; |
||||
|
TEST_ASSERT_EQUAL_INT(10,result); |
||||
|
result = spellHeal(&testCharacter2).healing; |
||||
|
TEST_ASSERT_EQUAL_INT(12,result); |
||||
|
} |
||||
|
|
||||
|
void test_spellLightning(void) |
||||
|
{ |
||||
|
int result = spellLightning(&testCharacter).damage; |
||||
|
TEST_ASSERT_EQUAL_INT(10,result); |
||||
|
result = spellLightning(&testCharacter2).damage; |
||||
|
TEST_ASSERT_EQUAL_INT(13,result); |
||||
|
} |
||||
|
|
||||
|
void test_spellRegeneration(void) |
||||
|
{ |
||||
|
int result = spellRegeneration(&testCharacter).healing; |
||||
|
TEST_ASSERT_EQUAL_INT(5,result); |
||||
|
result = spellRegeneration(&testCharacter2).healing; |
||||
|
TEST_ASSERT_EQUAL_INT(6,result); |
||||
|
} |
||||
|
#endif // TEST |
Write
Preview
Loading…
Cancel
Save
Reference in new issue