ref: 2f76aa950c0e7aba70b856f331bfc3227e47556f
parent: fcdcc0d9929f461f09f35bf901e3344c89b4efc5
author: sirjofri <sirjofri@sirjofri.de>
date: Fri Feb 13 19:31:38 EST 2026
status with statusmsg
--- a/dat.h
+++ b/dat.h
@@ -5,7 +5,14 @@
Spades,
} Color;
+typedef enum {+ Notstarted = 0,
+ Running,
+ Won,
+ Lost,
+} Status;
+
typedef struct State State;
struct State {int room[4];
@@ -14,7 +21,7 @@
int lastweaponkill;
int hp;
- int running;
+ Status status;
int canskip;
int hadpotion;
--- a/fns.h
+++ b/fns.h
@@ -1,6 +1,7 @@
void loadimages(char *path);
Image *getimage(int num);
+void initgame(void);
int c2n(int c, Color col);
State *getstate(void);
int roomaction(int c, int useweapon);
--- a/game.c
+++ b/game.c
@@ -131,7 +131,7 @@
continue;
c = drawcard();
if (c.value < 0) {- fprint(2, "error: drawcard. Empty deck?\n");
+ state.status = Won;
continue;
}
state.room[i] = c2n(c.value, c.col);
@@ -167,7 +167,7 @@
int cd, i, n;
Card card, weapon;
- if (!state.running)
+ if (state.status != Running)
return 0;
cd = state.room[c];
@@ -200,6 +200,11 @@
break;
}
+ if (state.hp <= 0) {+ state.status = Lost;
+ return 1;
+ }
+
state.canskip = 0;
n = 0;
@@ -219,10 +224,10 @@
startgame(void)
{int i;
- if (state.running)
+ if (state.status == Running)
return 0;
- state.running++;
+ state.status = Running;
state.canskip = 1;
state.hp = 20;
@@ -237,12 +242,18 @@
return 1;
}
+void
+initgame(void)
+{+ state.status = Notstarted;
+}
+
int
nextround(void)
{int i;
Card c;
- if (!state.running)
+ if (state.status != Running)
return 0;
if (!state.canskip)
return 0;
--- a/main.c
+++ b/main.c
@@ -23,7 +23,7 @@
Image *img;
for (i = 0; i < 4; i++) {- if (cards[i] < 0)
+ if (cards[i] <= 0)
continue;
img = getimage(cards[i]);
if (!img)
@@ -43,7 +43,7 @@
Point p;
Image *img;
- if (weapon < 0)
+ if (weapon <= 0)
return;
img = getimage(weapon);
@@ -95,6 +95,39 @@
}
static void
+drawdialog(State *state)
+{+ Point p, sp;
+ char *message;
+ if (state->status == Running)
+ return;
+
+ message = nil;
+ switch (state->status) {+ case Notstarted:
+ message = "Press 's' to start a new game";
+ break;
+ case Won:
+ message = "You won! Press 's' to start a new game";
+ break;
+ case Lost:
+ message = "You lost! Press 's' to start a new game";
+ break;
+ }
+
+ if (!message)
+ return;
+
+ sp.x = Dx(screen->r);
+ sp.y = Dy(screen->r);
+ p = stringsize(font, message);
+ p.x = (sp.x - p.x) / 2;
+ p.y = (sp.y - p.y) / 2;
+
+ stringbg(screen, addpt(p, screen->r.min), display->black, ZP, font, message, display->white, ZP);
+}
+
+static void
redraw(void)
{State *state;
@@ -102,12 +135,10 @@
state = getstate();
- if (!state->running)
- return;
-
drawroom(state->room);
drawweapon(state->weapon, state->lastweaponkill);
drawstats(state);
+ drawdialog(state);
}
void
@@ -195,6 +226,7 @@
srand(time(0));
loadimages("img");+ initgame();
/* 2 must be valid */
img = getimage(2);
--
⑨