From 896b0934c8df343e60b96f2e943395641bf1b9d7 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Mon, 30 Jan 2023 13:46:10 +0100 Subject: [PATCH] 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)