feat: Initial commit
This commit is contained in:
71
Laboratorio 7/Esercizio 1/inv.c
Normal file
71
Laboratorio 7/Esercizio 1/inv.c
Normal file
@@ -0,0 +1,71 @@
|
||||
// Laboratorio 7 - Esercizio 1 - inv.c
|
||||
// Matteo Schiff - s295565
|
||||
|
||||
#ifndef INV_C_DEFINED
|
||||
#define INV_C_DEFINED
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include "inv.h"
|
||||
|
||||
/* funzioni di input/output delle statistiche */
|
||||
void stat_read(FILE *fp, stat_t *statp) {
|
||||
fscanf(fp, " %d %d %d %d %d %d", &(statp->hp), &(statp->mp), &(statp->atk), &(statp->def), &(statp->mag), &(statp->spr));
|
||||
}
|
||||
|
||||
int zero_se_soglia(int a, int soglia) {
|
||||
if (a < soglia)
|
||||
return 0;
|
||||
return a;
|
||||
}
|
||||
|
||||
void stat_print(FILE *fp, stat_t *statp, int soglia) {
|
||||
fprintf(fp, "HP: %d, MP: %d, ATK: %d, DEF: %d, MAG: %d, SPR: %d\n",
|
||||
zero_se_soglia(statp->hp, soglia),
|
||||
zero_se_soglia(statp->mp, soglia),
|
||||
zero_se_soglia(statp->atk, soglia),
|
||||
zero_se_soglia(statp->def, soglia),
|
||||
zero_se_soglia(statp->mag, soglia),
|
||||
zero_se_soglia(statp->spr, soglia));
|
||||
}
|
||||
|
||||
void stat_copy(stat_t *a, stat_t *b) {
|
||||
a->atk = b->atk;
|
||||
a->def = b->def;
|
||||
a->hp = b->hp;
|
||||
a->mag = b->mag;
|
||||
a->mp = b->mp;
|
||||
a->spr = b->spr;
|
||||
}
|
||||
|
||||
void stat_sum(stat_t *a, stat_t *b) {
|
||||
a->atk += b->atk;
|
||||
a->def += b->def;
|
||||
a->hp += b->hp;
|
||||
a->mag += b->mag;
|
||||
a->mp += b->mp;
|
||||
a->spr += b->spr;
|
||||
}
|
||||
|
||||
/* funzioni di input/output di un oggetto dell'inventario */
|
||||
void inv_read(FILE *fp, inv_t *invp) {
|
||||
fscanf(fp, " %49s %49s", invp->nome, invp->tipo);
|
||||
stat_read(fp, &(invp->stat));
|
||||
}
|
||||
|
||||
void inv_print(FILE *fp, inv_t *invp) {
|
||||
fprintf(fp, " %s (%s) - ", invp->nome, invp->tipo);
|
||||
stat_print(fp, &(invp->stat),INT_MIN);
|
||||
}
|
||||
|
||||
/* ritorna il campo stat di un oggetto dell'inventario */
|
||||
stat_t inv_getStat(inv_t *invp) {
|
||||
return invp->stat;
|
||||
}
|
||||
|
||||
/* Si possono aggiungere altre funzioni se ritenute necessarie */
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user