add market (wip)

This commit is contained in:
quenousimporte 2025-04-06 15:47:23 +00:00
parent e69fbe2dcd
commit 3fe5ad472a
1 changed files with 41 additions and 20 deletions

61
w/w.c
View File

@ -16,6 +16,7 @@
#define CMD_LEFT 'w' #define CMD_LEFT 'w'
#define CMD_BACKTOSTATION 'r' #define CMD_BACKTOSTATION 'r'
#define CMD_GOTOMAZE 'v' #define CMD_GOTOMAZE 'v'
#define CMD_GOTOMARKET 'm'
#define SC_TITLE 0 #define SC_TITLE 0
#define SC_SETNAME 1 #define SC_SETNAME 1
@ -24,6 +25,7 @@
#define SC_MONSTER 4 #define SC_MONSTER 4
#define SC_GAMEOVER 5 #define SC_GAMEOVER 5
#define SC_WON 6 #define SC_WON 6
#define SC_MARKET 7
#define NORTH 0 #define NORTH 0
#define EAST 1 #define EAST 1
@ -58,7 +60,6 @@ typedef struct {
typedef struct { typedef struct {
Character hero; Character hero;
Character monster;
Position position; Position position;
char screen; char screen;
} Gamestate; } Gamestate;
@ -67,9 +68,10 @@ const char* statepath = "w.state";
char pov[POV_SIZE][POV_SIZE]; char pov[POV_SIZE][POV_SIZE];
unsigned char pov3d[POV_3D_SIZE][POV_3D_SIZE]; unsigned char pov3d[POV_3D_SIZE][POV_3D_SIZE];
Gamestate state; Gamestate state;
Character currentmonster;
struct Round* firstround = NULL; Round* firstround = NULL;
struct Round* currentround = NULL; Round* currentround = NULL;
int mapsize = 15; int mapsize = 15;
char map[15][15] = { char map[15][15] = {
@ -79,14 +81,14 @@ char map[15][15] = {
"w w w d w w w", "w w w d w w w",
"w w w w w w w", "w w w w w w w",
"w w w w w w", "w w w w w w",
"wdwwwwwdwwwwwdw", "wdwwwwwdwwwdwdw",
"w w w w w", "w w w w w w",
"w www w w", "w www w w w",
"ws w w w", "ws w w w w",
"wwwwwww w w", "wwwwwww w w w",
"w w w", "w w w w",
"w w w", "w w w w",
"w d w", "w w",
"wwwwwwwwwwwwwww" "wwwwwwwwwwwwwww"
}; };
@ -485,7 +487,7 @@ void freerounds()
void gotomonster() void gotomonster()
{ {
int index = dice() == 6 ? 1 : 0; int index = dice() == 6 ? 1 : 0;
memcpy(&state.monster, &(monsters[index]), sizeof(Character)); memcpy(&currentmonster, &(monsters[index]), sizeof(Character));
state.screen = SC_MONSTER; state.screen = SC_MONSTER;
} }
@ -494,6 +496,11 @@ void gotostation()
state.screen = SC_STATION; state.screen = SC_STATION;
} }
void gotomarket()
{
state.screen = SC_MARKET;
}
void update(char* command) void update(char* command)
{ {
char c = command[0]; char c = command[0];
@ -553,6 +560,10 @@ void update(char* command)
state.position.orientation = NORTH; state.position.orientation = NORTH;
updatepov(); updatepov();
} }
else if (c == CMD_GOTOMARKET)
{
gotomarket();
}
} }
else if (state.screen == SC_MONSTER) else if (state.screen == SC_MONSTER)
{ {
@ -578,18 +589,18 @@ void update(char* command)
int herodmg = 0; int herodmg = 0;
if (!fleefails) if (!fleefails)
{ {
monsterdmg = attack(&state.hero, &state.monster); monsterdmg = attack(&state.hero, &currentmonster);
} }
if (state.monster.hp <= 0) if (currentmonster.hp <= 0)
{ {
state.hero.gold += state.monster.gold; state.hero.gold += currentmonster.gold;
state.screen = SC_WON; state.screen = SC_WON;
} }
else else
{ {
// monster attacks // monster attacks
herodmg = attack(&state.monster, &state.hero); herodmg = attack(&currentmonster, &state.hero);
if (state.hero.hp <= 0) if (state.hero.hp <= 0)
{ {
state.hero.hp = 0; state.hero.hp = 0;
@ -610,6 +621,10 @@ void update(char* command)
state.screen = SC_MAP; state.screen = SC_MAP;
freerounds(); freerounds();
} }
else if (state.screen == SC_MARKET)
{
}
} }
@ -621,7 +636,7 @@ void debugoutput()
void drawrounds() void drawrounds()
{ {
printf("Rencontre avec %s.\n\n", state.monster.name); printf("Rencontre avec %s.\n\n", currentmonster.name);
Round* p = firstround; Round* p = firstround;
int n = 1; int n = 1;
while (p) while (p)
@ -629,7 +644,7 @@ void drawrounds()
printf("Tour %d\n", n++); printf("Tour %d\n", n++);
if (p->action == CMD_ATTACK) if (p->action == CMD_ATTACK)
{ {
printf("%s perd %d points de vie\n", state.monster.name, p->monsterdmg); 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); printf("%s perd %d points de vie\n\n", state.hero.name, p->herodmg);
} }
else if (p->action == CMD_FLEE) else if (p->action == CMD_FLEE)
@ -716,6 +731,7 @@ void draw()
printf("\n"); printf("\n");
printf("v: Partir en vaisseau\n"); printf("v: Partir en vaisseau\n");
printf("m: Aller au super space market\n");
} }
else if (state.screen == SC_MONSTER) else if (state.screen == SC_MONSTER)
{ {
@ -728,14 +744,19 @@ void draw()
{ {
drawrounds(); drawrounds();
printf("%s est vaincu.\n", state.monster.name); printf("%s est vaincu.\n", currentmonster.name);
printf("%s gagne %d crédits galactiques.\n", state.hero.name, state.monster.gold); printf("%s gagne %d crédits galactiques.\n", state.hero.name, currentmonster.gold);
} }
else if (state.screen == SC_GAMEOVER) else if (state.screen == SC_GAMEOVER)
{ {
drawrounds(); drawrounds();
printf("%s est fatigué.e.\nIel retourne à la station.\n", state.hero.name); printf("%s est fatigué.e.\nIel retourne à la station.\n", state.hero.name);
} }
else if (state.screen == SC_MARKET)
{
printf("Super space market\n\n");
printf("1: Composé protomol.: 10\n");
}
if (state.screen != SC_TITLE && state.screen != SC_SETNAME) if (state.screen != SC_TITLE && state.screen != SC_SETNAME)
{ {