From 395e906c3f960847984db64664c7f7fc0dfc4506 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Mon, 7 Apr 2025 09:07:49 +0200 Subject: [PATCH] working on inventory --- w/w.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/w/w.c b/w/w.c index 4f80297..cbb6ae5 100644 --- a/w/w.c +++ b/w/w.c @@ -4,9 +4,10 @@ #include #define CMD_LEN 10 -#define NAME_LEN 20 +#define NAME_LEN 64 #define POV_3D_SIZE 10 #define POV_SIZE 3 +#define INVENTORY_SIZE 255 #define CMD_NULL "-" #define CMD_FWD 's' @@ -37,6 +38,16 @@ #define TILE_DOOR 'd' #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 { char action; int herodmg; @@ -60,7 +71,8 @@ typedef struct { typedef struct { Character hero; - Position position; + Position position; + Item inventory[INVENTORY_SIZE]; char screen; } Gamestate; @@ -97,6 +109,11 @@ Character monsters[2] = { { "vilaine araignée", 5, 8, 2, 1 } }; +Item items[2] = { + { ITEM_POTION, "potion", 20, 0 }, + { ITEM_TRUC, "truc", 2000, 0 }, +}; + int dice() { return 1 + (rand() % 6); @@ -623,7 +640,10 @@ void update(char* command) } else if (state.screen == SC_MARKET) { - + if (c == CMD_BACKTOSTATION) + { + gotostation(); + } } } @@ -754,8 +774,15 @@ void draw() } else if (state.screen == SC_MARKET) { - printf("Super space market\n\n"); - printf("1: Composé protomol.: 10\n"); + printf("%s est au super space\nmarket.\n\n", state.hero.name); + + 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)