diff --git a/src/c/encounter.c b/src/c/encounter.c index 6a46528..18f79d8 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -64,3 +64,14 @@ int switchTurns(int currentTurn){ currentTurn = currentTurn % 2 + 1; return currentTurn; } + +int fight(int playerHealth, int playerDamage, int playerArmor, int playerAttack, enemy enemy){ + int currentTurn = 0; + while(playerAlive(playerHealth) && getEnemyInt(&enemy.health) > 0){ + setEnemyHealth(&enemy.health, enemyDamaged(enemy, playerDamage)); + } + if(playerAlive(playerHealth)){ + return 1; + } + return 0; +} diff --git a/src/c/encounter.h b/src/c/encounter.h index 1e5ea08..540247e 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -15,6 +15,7 @@ bool playerAlive(int health); int playerHealth(int health, int damage); int enemyDamaged(enemy enemy, int damage); int switchTurns(int currentTurn); +int fight(int playerHealth, int playerDamage, int playerArmor, int playerAttack, enemy enemy); //Getter/Setter Funktionen diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index 09105c8..33edaa9 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -145,4 +145,17 @@ void test_switchingTurns(void) //assert TEST_ASSERT_EQUAL(1,result); } + +void test_FightPlayerWins(void) +{ + //arange + int playerHealth = 100, playerDamage = 10, playerArmor = 4, playerAttack = 5; + int enemyHealth = 1, enemyDamage = 4, enemyArmor = 4, enemyAttack = 5; + int result; + //arrange + enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyAttack}; + result = fight(playerHealth, playerDamage, playerArmor, playerAttack, test); + //assert + TEST_ASSERT_EQUAL(1, result); +} #endif // TEST