Browse Source

Plan 9 from Bell Labs 2006-01-13

David du Colombier 18 years ago
parent
commit
c6e705f013

+ 5 - 5
dist/replica/_plan9.db

@@ -7289,7 +7289,7 @@ sys/man/1/filter - 664 sys sys 1135083932 6142
 sys/man/1/fmt - 664 sys sys 1070032221 1557
 sys/man/1/fortune - 664 sys sys 944959673 449
 sys/man/1/freq - 664 sys sys 1136378272 735
-sys/man/1/games - 664 sys sys 1121367092 5355
+sys/man/1/games - 664 sys sys 1137080360 5373
 sys/man/1/grap - 664 sys sys 944959675 6417
 sys/man/1/graph - 664 sys sys 944959673 2858
 sys/man/1/grep - 664 sys sys 1136378273 2257
@@ -14112,10 +14112,10 @@ sys/src/games/catclock.c - 664 sys sys 1108184106 10354
 sys/src/games/eyes.p - 664 sys sys 1108184106 1128
 sys/src/games/juggle.c - 664 sys sys 1118153689 4471
 sys/src/games/mahjongg - 20000000775 sys sys 1095792293 0
-sys/src/games/mahjongg/graphics.c - 664 sys sys 1095792293 5794
-sys/src/games/mahjongg/level.c - 664 sys sys 1095792293 2522
-sys/src/games/mahjongg/mahjongg.c - 664 sys sys 1095792293 3452
-sys/src/games/mahjongg/mahjongg.h - 664 sys sys 1095792293 1606
+sys/src/games/mahjongg/graphics.c - 664 sys sys 1137080359 7054
+sys/src/games/mahjongg/level.c - 664 sys sys 1137080360 2560
+sys/src/games/mahjongg/mahjongg.c - 664 sys sys 1137080360 3631
+sys/src/games/mahjongg/mahjongg.h - 664 sys sys 1137080360 1687
 sys/src/games/mahjongg/mkfile - 664 sys sys 1095792293 230
 sys/src/games/memo.c - 664 sys sys 1130853201 6471
 sys/src/games/mkfile - 664 sys sys 1128271766 586

+ 5 - 5
dist/replica/plan9.db

@@ -7289,7 +7289,7 @@ sys/man/1/filter - 664 sys sys 1135083932 6142
 sys/man/1/fmt - 664 sys sys 1070032221 1557
 sys/man/1/fortune - 664 sys sys 944959673 449
 sys/man/1/freq - 664 sys sys 1136378272 735
-sys/man/1/games - 664 sys sys 1121367092 5355
+sys/man/1/games - 664 sys sys 1137080360 5373
 sys/man/1/grap - 664 sys sys 944959675 6417
 sys/man/1/graph - 664 sys sys 944959673 2858
 sys/man/1/grep - 664 sys sys 1136378273 2257
@@ -14112,10 +14112,10 @@ sys/src/games/catclock.c - 664 sys sys 1108184106 10354
 sys/src/games/eyes.p - 664 sys sys 1108184106 1128
 sys/src/games/juggle.c - 664 sys sys 1118153689 4471
 sys/src/games/mahjongg - 20000000775 sys sys 1095792293 0
-sys/src/games/mahjongg/graphics.c - 664 sys sys 1095792293 5794
-sys/src/games/mahjongg/level.c - 664 sys sys 1095792293 2522
-sys/src/games/mahjongg/mahjongg.c - 664 sys sys 1095792293 3452
-sys/src/games/mahjongg/mahjongg.h - 664 sys sys 1095792293 1606
+sys/src/games/mahjongg/graphics.c - 664 sys sys 1137080359 7054
+sys/src/games/mahjongg/level.c - 664 sys sys 1137080360 2560
+sys/src/games/mahjongg/mahjongg.c - 664 sys sys 1137080360 3631
+sys/src/games/mahjongg/mahjongg.h - 664 sys sys 1137080360 1687
 sys/src/games/mahjongg/mkfile - 664 sys sys 1095792293 230
 sys/src/games/memo.c - 664 sys sys 1130853201 6471
 sys/src/games/mkfile - 664 sys sys 1128271766 586

+ 5 - 0
dist/replica/plan9.log

@@ -24795,3 +24795,8 @@
 1136656852 19 c 386/bin/fcp - 775 sys sys 1136656336 82190
 1136656852 20 c 386/lib/ape/libap.a - 664 sys sys 1136656401 809476
 1136912467 0 c sys/src/cmd/upas/ned/nedmail.c - 664 sys sys 1136911937 44584
+1137081716 0 c sys/man/1/games - 664 sys sys 1137080360 5373
+1137081716 1 c sys/src/games/mahjongg/graphics.c - 664 sys sys 1137080359 7054
+1137081716 2 c sys/src/games/mahjongg/level.c - 664 sys sys 1137080360 2560
+1137081716 3 c sys/src/games/mahjongg/mahjongg.c - 664 sys sys 1137080360 3631
+1137081716 4 c sys/src/games/mahjongg/mahjongg.h - 664 sys sys 1137080360 1687

+ 7 - 5
sys/man/1/games

@@ -1,6 +1,6 @@
 .TH GAMES 1
 .SH NAME
-mahjongg, sokoban, sudoku \- time wasters
+4s, 5s, juggle, mahjongg, sokoban, sudoku \- time wasters
 .SH SYNOPSIS
 .B games/4s
 .br
@@ -22,6 +22,8 @@ mahjongg, sokoban, sudoku \- time wasters
 [
 .B -c
 ] [
+.B -f
+] [
 .B -b
 .I background
 ] [
@@ -47,8 +49,6 @@ Try to fill complete rows using 4-square or 5-square tiles.
 Move tiles left or right by moving the mouse.
 Rotate tiles with buttons 1 and 3.
 Drop tiles for more points with button 2 or the space bar.
-Move the mouse out of or back into the play area to
-suspend or resume the game.
 Keys
 .LR a
 and 
@@ -107,8 +107,10 @@ and layout
 .RB (-l)
 images;
 .RB -c
-selects a true-color buffer image, use with
-drawterm or in case selecting a tile obscures it completely.
+selects a true-color buffer image, for use with
+drawterm or in case selecting a tile obscures it completely;
+.RB -f
+causes mahjongg to indicate non-blocked tiles on mouse-over.
 The 
 .LR N
 key will generate a new level, 

+ 67 - 0
sys/src/games/mahjongg/graphics.c

@@ -84,6 +84,9 @@ drawbrick(int d, int x, int y)
 	if(level.board[d][x][y].clicked)
 		draw(img, r, selected, nil, ZP);
 
+	if(level.l.d == d && eqpt(level.l.p, Pt(x, y)))
+		border(img, r, 2, litbrdr, level.board[d][x][y].start);
+
 	/* looks better without borders, uncomment to check it out with'em */
 //	r = Rpt(r.min, addpt(r.min, Pt(Tilex, Tiley)));
 //	draw(img, r, brdr, nil, ZP);
@@ -251,6 +254,70 @@ Found:
 	}
 }
 
+void
+light(Point coord)
+{
+	Point p;
+	int d;
+
+	/* ugly on purpose */
+
+	for(d = Depth - 1; d >= 0; d--) {
+		p = Pt((coord.x + TileDxy*d)/(Facex/2), (coord.y + TileDxy*d)/(Facey/2));
+		switch(level.board[d][p.x][p.y].which) {
+		case 0:
+			break;
+		case 1:
+			goto Found;
+		case 2:
+			p = Pt(p.x-1, p.y);
+			goto Found;
+		case 3:
+			p = Pt(p.x-1, p.y-1);
+			goto Found;
+		case 4:
+			p = Pt(p.x, p.y-1);
+			goto Found;
+		}
+	}
+
+	return;
+
+Found:
+	if(level.l.d == d && eqpt(level.l.p, p))
+		return;
+
+	if(freeup(d, p) && (freeleft(d, p) || freeright(d, p))) {
+		Point tmpp;
+		int tmpd;
+
+		tmpd = level.l.d;
+		tmpp = level.l.p;
+
+		level.l.d = d;
+		level.l.p = p;
+		drawbrick(d, p.x, p.y);
+
+		/* clean up the previously lit brick */
+		if(tmpd != -1 && level.board[tmpd][tmpp.x][tmpp.y].which == 1) 
+			drawbrick(tmpd, tmpp.x, tmpp.y);
+			
+		draw(screen, screen->r, img, nil, ZP);
+		flushimage(display, 1);
+	} else if(level.l.d != -1) {
+		d = level.l.d;
+		p = level.l.p;
+		level.l.d = -1;
+		level.l.p = Pt(0, 0);
+
+		if(level.board[d][p.x][p.y].which == 1) {
+			drawbrick(d, p.x, p.y);
+			draw(screen, screen->r, img, nil, ZP);
+			flushimage(display, 1);
+		}
+	}
+}
+
 /* below only for testing */
 
 Point

+ 2 - 0
sys/src/games/mahjongg/level.c

@@ -145,6 +145,8 @@ generate(uint seed)
 
 	orig.c.d = -1;
 	orig.c.p = Pt(0, 0);
+	orig.l.d = -1;
+	orig.l.p = Pt(0, 0);
 	orig.done = 0;
 	level = orig;
 }

+ 11 - 2
sys/src/games/mahjongg/mahjongg.c

@@ -14,6 +14,8 @@ char *defbackgr = "/sys/games/lib/mahjongg/backgrounds/default.bit";
 char *deflayout = "/sys/games/lib/mahjongg/layouts/default.layout";
 ulong defchan;
 
+int trace;
+
 
 char *buttons[] = 
 {
@@ -32,7 +34,7 @@ Menu menu =
 void
 usage(char *progname)
 {
-	fprint(2, "usage: %s [-b background] [-l layout] [-t tileset] -c\n", progname);
+	fprint(2, "usage: %s [-b background] [-l layout] [-t tileset] [-c] [-f]\n", progname);
 	exits("usage");
 }
 
@@ -74,6 +76,7 @@ allocimages(void)
 	Rectangle one = Rect(0, 0, 1, 1);
 	
 	selected = eallocimage(one, 1, RGBA32, setalpha(DPalebluegreen, 0x5f));
+	litbrdr = eallocimage(one, 1, RGBA32, DGreen);
 	img = eallocimage(Rect(0, 0, Sizex, Sizey), 0, defchan ? defchan : screen->chan, DBlack);
 
 	background = eloadfile(defbackgr);
@@ -104,6 +107,9 @@ main(int argc, char **argv)
 	ARGBEGIN{
 	case 'h':
 		usage(argv0);
+	case 'f':
+		trace = 1;
+		break;
 	case 'b':
 		defbackgr = EARGF(usage(argv0));
 		break;
@@ -148,8 +154,11 @@ main(int argc, char **argv)
 					clickety = 1;
 					clicked(subpt(m.xy, addpt(screen->r.min, Pt(30, 30))));
 				}
-			} else 
+			} else {
 				clickety = 0;
+				if(trace)
+					light(subpt(m.xy, addpt(screen->r.min, Pt(30, 30))));
+			}
 			if(m.buttons&2) {
 				/* nothing here for the moment */
 			}

+ 3 - 0
sys/src/games/mahjongg/mahjongg.h

@@ -55,6 +55,7 @@ typedef struct {
 typedef struct {
 	Brick 	board[Depth][Lx][Ly];
 	Click		c; 		/* player has a brick selected */
+	Click		l; 		/* mouse-over-brick indicator */
 	int			done;
 	int 		remaining;
 } Level;
@@ -69,12 +70,14 @@ Image *brdr;
 Image *mask;
 Image *background;
 Image *selected;
+Image *litbrdr;
 Image *gameover;
 
 /* graphics.c */
 void drawlevel(void);
 void resize(Point);
 void clicked(Point);
+void light(Point);
 void hint(void);
 void done(void);
 void clearlevel(void);