move copy of the game to the game source file

This commit is contained in:
Mylloon 2022-11-19 17:15:05 +01:00
parent 9d3e8b0914
commit 2338e83df9
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -120,6 +120,38 @@ int selection_gagnant(Jeu *jeu, int *resultat) {
return 1; 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) { void free_jeu(Jeu *jeu) {
free_liste(jeu->j1->liste_jeton); free_liste(jeu->j1->liste_jeton);
free(jeu->j1); free(jeu->j1);