working on inventory

This commit is contained in:
quenousimporte 2025-04-07 09:07:49 +02:00
parent 3fe5ad472a
commit 395e906c3f
1 changed files with 32 additions and 5 deletions

35
w/w.c
View File

@ -4,9 +4,10 @@
#include <time.h> #include <time.h>
#define CMD_LEN 10 #define CMD_LEN 10
#define NAME_LEN 20 #define NAME_LEN 64
#define POV_3D_SIZE 10 #define POV_3D_SIZE 10
#define POV_SIZE 3 #define POV_SIZE 3
#define INVENTORY_SIZE 255
#define CMD_NULL "-" #define CMD_NULL "-"
#define CMD_FWD 's' #define CMD_FWD 's'
@ -37,6 +38,16 @@
#define TILE_DOOR 'd' #define TILE_DOOR 'd'
#define TILE_START 's' #define TILE_START 's'
#define ITEM_POTION 0
#define ITEM_TRUC 1
typedef struct {
char id;
char name[NAME_LEN];
int price;
int count;
} Item;
typedef struct Round { typedef struct Round {
char action; char action;
int herodmg; int herodmg;
@ -61,6 +72,7 @@ typedef struct {
typedef struct { typedef struct {
Character hero; Character hero;
Position position; Position position;
Item inventory[INVENTORY_SIZE];
char screen; char screen;
} Gamestate; } Gamestate;
@ -97,6 +109,11 @@ Character monsters[2] = {
{ "vilaine araignée", 5, 8, 2, 1 } { "vilaine araignée", 5, 8, 2, 1 }
}; };
Item items[2] = {
{ ITEM_POTION, "potion", 20, 0 },
{ ITEM_TRUC, "truc", 2000, 0 },
};
int dice() int dice()
{ {
return 1 + (rand() % 6); return 1 + (rand() % 6);
@ -623,7 +640,10 @@ void update(char* command)
} }
else if (state.screen == SC_MARKET) else if (state.screen == SC_MARKET)
{ {
if (c == CMD_BACKTOSTATION)
{
gotostation();
}
} }
} }
@ -754,8 +774,15 @@ void draw()
} }
else if (state.screen == SC_MARKET) else if (state.screen == SC_MARKET)
{ {
printf("Super space market\n\n"); printf("%s est au super space\nmarket.\n\n", state.hero.name);
printf("1: Composé protomol.: 10\n");
int count = sizeof(items) / sizeof(Item);
for (int i = 0; i < count; i++)
{
printf("%d: %s - %d\n", (i+1), items[i].name, items[i].price);
}
printf("\nr: Retour à la station\n");
} }
if (state.screen != SC_TITLE && state.screen != SC_SETNAME) if (state.screen != SC_TITLE && state.screen != SC_SETNAME)