Browse Source

Added first implementation of Fighting System

remotes/origin/encounter
János 2 years ago
parent
commit
b0a5408cbb
  1. 11
      src/c/encounter.c
  2. 1
      src/c/encounter.h
  3. 13
      test/c/test_encounter.c

11
src/c/encounter.c

@ -64,3 +64,14 @@ int switchTurns(int currentTurn){
currentTurn = currentTurn % 2 + 1; currentTurn = currentTurn % 2 + 1;
return currentTurn; 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;
}

1
src/c/encounter.h

@ -15,6 +15,7 @@ bool playerAlive(int health);
int playerHealth(int health, int damage); int playerHealth(int health, int damage);
int enemyDamaged(enemy enemy, int damage); int enemyDamaged(enemy enemy, int damage);
int switchTurns(int currentTurn); int switchTurns(int currentTurn);
int fight(int playerHealth, int playerDamage, int playerArmor, int playerAttack, enemy enemy);
//Getter/Setter Funktionen //Getter/Setter Funktionen

13
test/c/test_encounter.c

@ -145,4 +145,17 @@ void test_switchingTurns(void)
//assert //assert
TEST_ASSERT_EQUAL(1,result); 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 #endif // TEST
Loading…
Cancel
Save