Browse Source

Call functions of StartMatch and EndMatch

master
Bastien 8 years ago
committed by Squiz
parent
commit
22d7dc1977
2 changed files with 32 additions and 4 deletions
  1. +1
    -1
      dummy.c
  2. +31
    -3
      main.c

+ 1
- 1
dummy.c View File

@ -8,7 +8,7 @@ void StartGame() {
puts("stratégie start game");
}
void StartMatch(const unsigned int nbJoueur, const enum player_t couleur) {
puts("stratégie start match");
printf("stratégie start match (%d players, color%d)\n", nbJoueur, couleur);
}
void EndMatch() {
puts("stratégie end match");


+ 31
- 3
main.c View File

@ -75,10 +75,10 @@ int main(int argc, char** argv) {
} else {
/* on initialise la bibliothèque */
char* error;
void (*library_init) ();
*(void **) (&library_init) = dlsym(player_branch[i].lib_strategy_p, "InitLibrary");
void (*library_init_pf)();
*(void **) (&library_init_pf) = dlsym(player_branch[i].lib_strategy_p, "InitLibrary");
if((error=dlerror()) == NULL) {
(*library_init)("toto"); // TODO : passer le nom de la stratégie en paramètre
(*library_init_pf)("toto"); // TODO : passer le nom de la stratégie en paramètre
}
#ifdef debug
else
@ -101,9 +101,37 @@ int main(int argc, char** argv) {
#endif
/* on démarre le jeu */
for(i=0 ; i < nb_player ; i++) {
if(player_branch[i].lib_strategy_p != NULL) {
char* error;
void (*library_start_match_pf)(const unsigned int, const enum player_t);
*(void **) (&library_start_match_pf) = dlsym(player_branch[i].lib_strategy_p, "StartMatch");
if((error=dlerror()) == NULL) {
(*library_start_match_pf)(nb_player, i+1);
}
#ifdef debug
else
fprintf(stderr,"function StartMatch not found in stratégie (%d)\n", i);
#endif
}
}
/* fin du jeu */
for(i=0 ; i < nb_player ; i++) {
if(player_branch[i].lib_strategy_p != NULL) {
char* error;
void (*library_end_match_pf)();
*(void **) (&library_end_match_pf) = dlsym(player_branch[i].lib_strategy_p, "EndMatch");
if((error=dlerror()) == NULL) {
(*library_end_match_pf)();
}
#ifdef debug
else
fprintf(stderr,"function EndMatch not found in stratégie (%d)\n", i);
#endif
}
}
/* on décharge toutes les stratégies */


Loading…
Cancel
Save