shithub: cflood

Download patch

ref: 1ddcc3285eb5ade62c7ce95c800c0665981e3361
parent: 47de140b5fbf8498bf8da6f43cbfd50227f04d7e
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Sun Dec 16 19:18:41 EST 2012

games/cflood: custom size/turns; manual page

--- a/games/cflood.c
+++ b/games/cflood.c
@@ -7,6 +7,7 @@
 	Ssmall,
 	Snormal,
 	Slarge,
+	Scustom,
 
 	Tgame,
 	Twin,
@@ -20,9 +21,9 @@
 	ButtonSize = 32
 };
 
-const int sizes[] = {14, 21, 28};
-const int turns[] = {25, 35, 50};
-const ulong srccolors[NumColors] = {
+static int sizes[] = {14, 21, 28, 1};
+static int turns[] = {25, 35, 50, 1};
+static const ulong srccolors[NumColors] = {
 	0x6060a8ff,
 	0xf6f61dff,
 	0x46b0e0ff,
@@ -30,7 +31,7 @@
 	0xf070a0ff,
 	0xdc4a20ff
 };
-char *mstr[] = {
+static char *mstr[] = {
 	"14x14 / 25",
 	"25x25 / 35",
 	"28x28 / 50",
@@ -43,7 +44,7 @@
 static int type;
 static int wait4click;
 static int turnsleft;
-static uchar cells[28*28]; // enough for maximal size
+static uchar *cells; // enough for maximal size
 static Image *colors[NumColors];
 static Rectangle buttons[NumColors];
 
@@ -164,6 +165,11 @@
 	size = sizes[sid];
 	turnsleft = turns[sid];
 
+	if(cells == nil) {
+		int maxsize = size > sizes[Slarge] ? size : sizes[Slarge];
+		cells = malloc(maxsize*maxsize);
+	}
+
 	// randomize
 	uchar *c = &cells[0];
 	for(int i = 0; i < size*size; i++) {
@@ -183,7 +189,14 @@
 	redraw(screen);
 }
 
-void main(int, char**) {
+static void
+usage(void)
+{
+	fprint(2, "usage: cflood [-s size] [-t turns]\n");
+	exits("usage");
+}
+
+void main(int argc, char** argv) {
 	Menu menu;
 
 	if(initdraw(0, 0, "cflood") < 0)
@@ -199,6 +212,19 @@
 	srand(time(0));
 
 	sid = Snormal;
+	ARGBEGIN {
+	case 's':
+		sid = Scustom;
+		sizes[sid] = atoi(ARGF());
+		break;
+	case 't':
+		sid = Scustom;
+		turns[sid] = atoi(ARGF());
+		break;
+	default:
+		usage();
+	}ARGEND
+
 	newgame(sid);
 
 	for(int mold = 0;;) {
--- /dev/null
+++ b/games/cflood.man
@@ -1,0 +1,34 @@
+.TH CFLOOD 1
+.SH NAME
+cflood \- a timewaster
+.SH SYNOPSIS
+.B cflood
+[
+.I -s size
+]
+[
+.I -t turns
+]
+.SH DESCRIPTION
+.I cflood
+is a game in which player must fill an area with one color in limited number of turns.
+.PP
+The
+.B -s
+option sets the size of the area to
+.IR size
+x
+.IR size .
+.PP
+The
+.B -t
+option sets the number of
+.IR turns .
+.EE
+.PP
+There are three predefined area sizes in the game menu (invoked by button 3).
+.EE
+.SH SOURCE
+http://bitbucket.org/ftrvxmtrx/p9
+.SH BUGS
+Probably.
--- a/games/mkfile
+++ b/games/mkfile
@@ -1,7 +1,14 @@
 </$objtype/mkfile
+MAN=/sys/man/1
 
-TARG=cflood
-OFILES=cflood.$O
+TARG=\
+	cflood\
+
 BIN=/$objtype/bin
 
-</sys/src/cmd/mkone
+</sys/src/cmd/mkmany
+
+install: $MAN/cflood
+
+$MAN/cflood: cflood.man
+	cp cflood.man $MAN/cflood