Browse Source

structs for enemies and a way to set values

remotes/origin/encounter
János 2 years ago
parent
commit
b28be0a441
  1. 1
      project.yml
  2. 16
      src/c/encounter.c
  3. 6
      src/c/encounter.h
  4. 13
      test/c/test_encounter.c

1
project.yml

@ -98,4 +98,5 @@
:enabled:
- stdout_pretty_tests_report
- module_generator
- xml_tests_report
...

16
src/c/encounter.c

@ -22,3 +22,19 @@ int playerHealth(int health, int damage){
}
return health;
}
enemy createEnemy(int health)
{
enemy test;
test.health = health;
return test;
}
void *setEnemyHealth(int *num, int health){
*num = health;
//return health;
}
int getEnemyHealth(enemy enemy){
return enemy.health;
}

6
src/c/encounter.h

@ -3,6 +3,12 @@
#include <stdbool.h>
typedef struct {
int health;
} enemy;
//setEnemyHealth(&enemy.health, health);
void *setEnemyHealth(int *num, int health);
bool playerAlive(int health);
int playerHealth(int health, int damage);

13
test/c/test_encounter.c

@ -3,6 +3,7 @@
#include "encounter.h"
void setUp(void){
}
@ -43,4 +44,16 @@ void test_playerIsNotOverhealed(void){
TEST_ASSERT_EQUAL(expectedHealth, health);
}
void test_setEnemyHealth(void){
//arrange
int health = 50, result;
//act
enemy test = {health*2};
setEnemyHealth(&test.health, health);
//assert
TEST_ASSERT_EQUAL(health, test.health);
}
#endif // TEST
Loading…
Cancel
Save