From 2338e83df9783d8b7845ad4ec887741fd2ec2da8 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 19 Nov 2022 17:15:05 +0100 Subject: [PATCH] move copy of the game to the game source file --- src/jeu.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/jeu.c b/src/jeu.c index 1c81444..06fc5b3 100644 --- a/src/jeu.c +++ b/src/jeu.c @@ -120,6 +120,38 @@ int selection_gagnant(Jeu *jeu, int *resultat) { return 1; } +Jeu *copie_jeu(Jeu *source) { + Jeu *res = malloc(sizeof(Jeu)); + + // Copie de J1 + res->j1 = malloc(sizeof(Joueur)); + res->j1->nom = source->j1->nom; + res->j1->couleur = source->j1->couleur; + res->j1->liste_jeton = copie_liste(source->j1->liste_jeton); + res->j1->nb_jeton = source->j1->nb_jeton; + + // Copie de J2 + res->j2 = malloc(sizeof(Joueur)); + res->j2->nom = source->j2->nom; + res->j2->couleur = source->j2->couleur; + res->j2->liste_jeton = copie_liste(source->j2->liste_jeton); + res->j2->nb_jeton = source->j2->nb_jeton; + + // Copie du plateau + for (int i = 0; i < LONGEUR; ++i) { + for (int j = 0; j < LARGEUR; ++j) { + Jeton *jeton = malloc(sizeof(Jeton)); + jeton->couleur = source->plateau[i][j]->couleur; + jeton->pos_i = source->plateau[i][j]->pos_i; + jeton->pos_j = source->plateau[i][j]->pos_j; + + res->plateau[i][j] = jeton; + } + } + + return res; +} + void free_jeu(Jeu *jeu) { free_liste(jeu->j1->liste_jeton); free(jeu->j1);