feat: Initial commit
This commit is contained in:
49
Laboratorio 6/Esercizio 3/pg.c
Normal file
49
Laboratorio 6/Esercizio 3/pg.c
Normal file
@@ -0,0 +1,49 @@
|
||||
// Laboratorio 6 - Esercizio 3 - pg.c
|
||||
// Matteo Schiff - s295565
|
||||
|
||||
#ifndef PG_C_DEFINED
|
||||
#define PG_C_DEFINED
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "equipArray.h"
|
||||
#include "pg.h"
|
||||
|
||||
void pg_calc_stats(pg_t *pgp) {
|
||||
stat_copy(&pgp->eq_stat, &pgp->b_stat);
|
||||
equipArray_apply_modifier(&pgp->eq_stat, pgp->equip);
|
||||
}
|
||||
|
||||
/* lettura e scrittura su file */
|
||||
int pg_read(FILE *fp, pg_t *pgp) {
|
||||
if (fscanf(fp, " %49s %49s %49s", pgp->cod, pgp->nome, pgp->classe) != 3)
|
||||
return 0;
|
||||
|
||||
stat_read(fp, &(pgp->b_stat));
|
||||
pgp->equip = equipArray_init();
|
||||
pg_calc_stats(pgp);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/* non essendo struct dinamica, pulisce chiamando il distruttore di equipArray */
|
||||
void pg_clean(pg_t *pgp) {
|
||||
free(pgp->equip);
|
||||
}
|
||||
|
||||
void pg_print(FILE *fp, pg_t *pgp, invArray_t invArray) {
|
||||
fprintf(fp, "%s (%s)\n Classe: %s\n Statistiche - ", pgp->nome, pgp->cod, pgp->classe);
|
||||
stat_print(fp, &(pgp->eq_stat), 0);
|
||||
equipArray_print(fp, pgp->equip, invArray);
|
||||
}
|
||||
/* modifica personaggio aggiungendo/togliendo un equipaggiamento selezionato da inventario:
|
||||
di fatto e' sufficiente chiamare l'opportuna funzione dal modulo equipArray */
|
||||
void pg_updateEquip(pg_t *pgp, invArray_t invArray) {
|
||||
equipArray_update(pgp->equip, invArray);
|
||||
pg_calc_stats(pgp);
|
||||
}
|
||||
|
||||
/* Si possono aggiungere altre funzioni se ritenute necessarie */
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user