wm: glendy

Download patch

ref: d37a60b2f45acd3068de726679df12b1e03144b1
parent: 502841cc354c028d2ef5d7b602aa65e7fb3974af
author: mkf <mkf@cloud9p.org>
date: Tue May 7 08:40:14 EDT 2024

engine: enable networked games.

clients which wish to run a networked game shall set networked to 1
and sockfd to correct fd to the server. we assume nothing about how this is done.
It's is up to clients to set up correct connection and ensure it works.

--- a/engine.c
+++ b/engine.c
@@ -7,6 +7,7 @@
 #endif
 
 #include "engine.h"
+#include "netclient.h"
 
 int difficulty = DEasy;
 int state;
@@ -150,21 +151,25 @@
 domove(int dir)
 {
 	Point src, dst;
-	
+		
 	src = findglenda();
-	if(src.x == 0 || src.x == SzX-1 || src.y == 0 || src.y == SzY-1)
-		goto done;
-
 	dst = movedir(dir, src);
+
 	if(grid[dst.x][dst.y] == Wall)
 		return Wall;
 
+	if(networked)
+		return netmove(dir);
+
+	if(src.x == 0 || src.x == SzX-1 || src.y == 0 || src.y == SzY-1)
+		goto done;
+
 	grid[dst.x][dst.y] = Glenda;
 done:
 	grid[src.x][src.y] = Prev;
 
 	turn++;
-	return 0;
+	return Ok;
 }
 
 int
@@ -180,6 +185,9 @@
 	if(grid[p.x][p.y] == Glenda)
 		return Glenda;
 
+	if(networked)
+		return netput(p.x, p.y);
+	
 	/* take a copy for undo */
 	memcpy(pgrid, grid, sizeof grid);
 	grid[p.x][p.y] = Wall;
--- a/engine.h
+++ b/engine.h
@@ -28,6 +28,7 @@
 	/* player types */
 	Human = 0,
 	Computer,
+	Net,
 
 	PTrapper = 0,	
 	PGlenda,
@@ -45,22 +46,26 @@
 
 	Err = 0,
 	Ok,
-	
 };
 
+/* engine.c */
 extern int difficulty;
 extern int state;
 extern int turn;
 extern int ptype[2]; /* Human or Computer? */
 
+extern int grid[SzX][SzY];
+extern int pgrid[SzX][SzY]; /* for undo */
+extern int ogrid[SzX][SzY]; /* so we can restart levels */
+
+/* client code */
+extern int debug;
+
+/* net.c */
 /* we maybe be able to merge all this into one bit-array */
 extern int waitbit; /* 0 is go, 1 is wait */
 extern int networked; /* 0 is local, 1 is networked */
 extern int pside; /* Trapper, Glenda */
-
-extern int grid[SzX][SzY];
-extern int pgrid[SzX][SzY]; /* for undo */
-extern int ogrid[SzX][SzY]; /* so we can restart levels */
 
 void initlevel(void);
 Point movedir(int dir, Point p);