improve inventory
This commit is contained in:
parent
395e906c3f
commit
f2eb437ac1
134
w/w.c
134
w/w.c
|
@ -2,12 +2,13 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define CMD_LEN 10
|
#define CMD_LEN 10
|
||||||
#define NAME_LEN 64
|
#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 INVENTORY_SIZE 2
|
||||||
|
|
||||||
#define CMD_NULL "-"
|
#define CMD_NULL "-"
|
||||||
#define CMD_FWD 's'
|
#define CMD_FWD 's'
|
||||||
|
@ -38,8 +39,8 @@
|
||||||
#define TILE_DOOR 'd'
|
#define TILE_DOOR 'd'
|
||||||
#define TILE_START 's'
|
#define TILE_START 's'
|
||||||
|
|
||||||
#define ITEM_POTION 0
|
#define ITEM_POTION '0'
|
||||||
#define ITEM_TRUC 1
|
#define ITEM_TRUC '1'
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char id;
|
char id;
|
||||||
|
@ -109,11 +110,6 @@ 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);
|
||||||
|
@ -156,6 +152,26 @@ void drawmap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawpov3d()
|
||||||
|
{
|
||||||
|
int shift = 9;
|
||||||
|
for (int i = 0; i < shift; i++) printf(" ");
|
||||||
|
printf("o----------o\n");
|
||||||
|
|
||||||
|
for (int i = 0; i < POV_3D_SIZE; i++)
|
||||||
|
{
|
||||||
|
for (int s = 0; s < shift; s++) printf(" ");
|
||||||
|
printf("|");
|
||||||
|
for (int j = 0; j < POV_3D_SIZE; j++)
|
||||||
|
{
|
||||||
|
printf("%c", pov3d[i][j]);
|
||||||
|
}
|
||||||
|
printf("|\n");
|
||||||
|
}
|
||||||
|
for (int i = 0; i < shift; i++) printf(" ");
|
||||||
|
printf("o----------o");
|
||||||
|
}
|
||||||
|
|
||||||
void savestate()
|
void savestate()
|
||||||
{
|
{
|
||||||
FILE* file = fopen(statepath, "w");
|
FILE* file = fopen(statepath, "w");
|
||||||
|
@ -467,6 +483,11 @@ void createhero(char* name)
|
||||||
state.hero.gold = 0;
|
state.hero.gold = 0;
|
||||||
state.hero.atk = 1;
|
state.hero.atk = 1;
|
||||||
state.hero.def = 1;
|
state.hero.def = 1;
|
||||||
|
|
||||||
|
Item potion = { ITEM_POTION, "potion", 20, 0 };
|
||||||
|
Item truc = { ITEM_TRUC, "truc", 2000, 0 };
|
||||||
|
state.inventory[0] = potion;
|
||||||
|
state.inventory[1] = truc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void createround(char action, int herodmg, int monsterdmg)
|
void createround(char action, int herodmg, int monsterdmg)
|
||||||
|
@ -518,6 +539,36 @@ void gotomarket()
|
||||||
state.screen = SC_MARKET;
|
state.screen = SC_MARKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void debugoutput()
|
||||||
|
{
|
||||||
|
//drawmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawrounds()
|
||||||
|
{
|
||||||
|
printf("Rencontre avec %s.\n\n", currentmonster.name);
|
||||||
|
Round* p = firstround;
|
||||||
|
int n = 1;
|
||||||
|
while (p)
|
||||||
|
{
|
||||||
|
printf("Tour %d\n", n++);
|
||||||
|
if (p->action == CMD_ATTACK)
|
||||||
|
{
|
||||||
|
printf("%s perd %d points de vie\n", currentmonster.name, p->monsterdmg);
|
||||||
|
printf("%s perd %d points de vie\n\n", state.hero.name, p->herodmg);
|
||||||
|
}
|
||||||
|
else if (p->action == CMD_FLEE)
|
||||||
|
{
|
||||||
|
printf("%s n'arrive pas à fuir et perd %d points de vie\n\n", state.hero.name, p->herodmg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("??\n");
|
||||||
|
}
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void update(char* command)
|
void update(char* command)
|
||||||
{
|
{
|
||||||
char c = command[0];
|
char c = command[0];
|
||||||
|
@ -644,38 +695,19 @@ void update(char* command)
|
||||||
{
|
{
|
||||||
gotostation();
|
gotostation();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void debugoutput()
|
|
||||||
{
|
|
||||||
//drawmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawrounds()
|
|
||||||
{
|
|
||||||
printf("Rencontre avec %s.\n\n", currentmonster.name);
|
|
||||||
Round* p = firstround;
|
|
||||||
int n = 1;
|
|
||||||
while (p)
|
|
||||||
{
|
|
||||||
printf("Tour %d\n", n++);
|
|
||||||
if (p->action == CMD_ATTACK)
|
|
||||||
{
|
|
||||||
printf("%s perd %d points de vie\n", currentmonster.name, p->monsterdmg);
|
|
||||||
printf("%s perd %d points de vie\n\n", state.hero.name, p->herodmg);
|
|
||||||
}
|
|
||||||
else if (p->action == CMD_FLEE)
|
|
||||||
{
|
|
||||||
printf("%s n'arrive pas à fuir et perd %d points de vie\n\n", state.hero.name, p->herodmg);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("??\n");
|
for (int i = 0; i < INVENTORY_SIZE; i++)
|
||||||
|
{
|
||||||
|
Item item = state.inventory[i];
|
||||||
|
if (c == item.id && item.price <= state.hero.gold)
|
||||||
|
{
|
||||||
|
state.hero.gold -= item.price;
|
||||||
|
state.inventory[i].count++;
|
||||||
|
debugoutput("%d\n", item.count);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p = p->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -717,22 +749,8 @@ void draw()
|
||||||
else if (state.screen == SC_MAP)
|
else if (state.screen == SC_MAP)
|
||||||
{
|
{
|
||||||
update3dpov();
|
update3dpov();
|
||||||
int shift = 9;
|
drawpov3d();
|
||||||
for (int i = 0; i < shift; i++) printf(" ");
|
//drawmap();
|
||||||
printf("o----------o\n");
|
|
||||||
|
|
||||||
for (int i = 0; i < POV_3D_SIZE; i++)
|
|
||||||
{
|
|
||||||
for (int s = 0; s < shift; s++) printf(" ");
|
|
||||||
printf("|");
|
|
||||||
for (int j = 0; j < POV_3D_SIZE; j++)
|
|
||||||
{
|
|
||||||
printf("%c", pov3d[i][j]);
|
|
||||||
}
|
|
||||||
printf("|\n");
|
|
||||||
}
|
|
||||||
for (int i = 0; i < shift; i++) printf(" ");
|
|
||||||
printf("o----------o");
|
|
||||||
|
|
||||||
if (charatpos(state.position.x, state.position.y) == TILE_START)
|
if (charatpos(state.position.x, state.position.y) == TILE_START)
|
||||||
{
|
{
|
||||||
|
@ -775,11 +793,13 @@ void draw()
|
||||||
else if (state.screen == SC_MARKET)
|
else if (state.screen == SC_MARKET)
|
||||||
{
|
{
|
||||||
printf("%s est au super space\nmarket.\n\n", state.hero.name);
|
printf("%s est au super space\nmarket.\n\n", state.hero.name);
|
||||||
|
|
||||||
int count = sizeof(items) / sizeof(Item);
|
for (int i = 0; i < INVENTORY_SIZE; i++)
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
{
|
||||||
printf("%d: %s - %d\n", (i+1), items[i].name, items[i].price);
|
Item item = state.inventory[i];
|
||||||
|
printf("%c: %s\n", item.id, item.name);
|
||||||
|
printf("price: %d\n", item.price);
|
||||||
|
printf("owned: %d\n", item.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\nr: Retour à la station\n");
|
printf("\nr: Retour à la station\n");
|
||||||
|
|
Loading…
Reference in New Issue