/*
- * Netris -- A free networked version of Tetris
- * Copyright (C) 1994,1995 Mark Weaver <Mark_Weaver@brown.edu>
+ * Netris -- A free networked version of T*tris
+ * Copyright (C) 1994,1995,1996 Mark H. Weaver <mhw@netris.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
- * $Id: game.c,v 1.37 1995/07/11 08:53:23 mhw Exp $
+ * $Id: game.c,v 1.39 1999/05/16 06:56:27 mhw Exp $
*/
#define NOEXT
#include <sys/types.h>
#include <netinet/in.h>
-enum { KT_left, KT_rotate, KT_right, KT_drop,
- KT_down, KT_toggleSpy, KT_pause, KT_faster, KT_numKeys };
+enum { KT_left, KT_rotate, KT_right, KT_drop, KT_down,
+ KT_toggleSpy, KT_pause, KT_faster, KT_redraw, KT_numKeys };
static char *keyNames[KT_numKeys+1] = {
"Left", "Rotate", "Right", "Drop", "Down", "ToggleSpy", "Pause",
- "Faster", NULL };
+ "Faster", "Redraw", NULL };
static char *gameNames[GT_len] = { "OnePlayer", "ClassicTwo" };
-static char keyTable[KT_numKeys+1] = "jkl mspf";
+static char keyTable[KT_numKeys+1];
static int dropModeEnable = 0;
static char *robotProg;
+ExtFunc void MapKeys(char *newKeys)
+{
+ int i, k, ch;
+ char used[256];
+ int errs = 0;
+
+ /* XXX assumptions about ASCII encoding here */
+ for (i = k = 0; newKeys[i] && k < KT_numKeys; i++,k++) {
+ if (newKeys[i] == '^' && newKeys[i+1])
+ keyTable[k] = toupper(newKeys[++i]) - ('A' - 1);
+ else
+ keyTable[k] = newKeys[i];
+ }
+ memset(used, 0, sizeof(used));
+ for (k = 0; k < KT_numKeys; k++) {
+ ch = (unsigned char) keyTable[k];
+ if (used[ch]) {
+ if (iscntrl(ch) && ch < ' ')
+ sprintf(scratch, "Ctrl-%c", ch + ('A' - 1));
+ else if (isprint(ch))
+ sprintf(scratch, "\"%c\"", ch);
+ else
+ sprintf(scratch, "0x%X", ch);
+ if (!errs)
+ fprintf(stderr, "Duplicate key mappings:\n");
+ errs++;
+ fprintf(stderr, " %s mapped to both %s and %s\n",
+ scratch, keyNames[used[ch]-1], keyNames[k]);
+ }
+ used[ch] = k + 1;
+ }
+ if (errs)
+ exit(1);
+}
+
ExtFunc int StartNewPiece(int scr, Shape *shape)
{
curShape[scr] = shape;
if (!p)
break;
keyEvent:
- if (paused && (key != KT_pause))
+ if (paused && (key != KT_pause) && (key != KT_redraw))
break;
switch(key) {
case KT_left:
ShowDisplayInfo();
changed = 1;
break;
+ case KT_redraw:
+ ScheduleFullRedraw();
+ if (paused)
+ RefreshScreen();
+ break;
}
if (dropMode && DropPiece(scr) > 0) {
if (spied)
int initConn = 0, waitConn = 0, ch;
char *hostStr = NULL, *portStr = NULL;
- standoutEnable = 1;
+ standoutEnable = colorEnable = 1;
stepDownInterval = DEFAULT_INTERVAL;
- while ((ch = getopt(argc, argv, "hHRs:r:Fk:c:woDSp:i:")) != -1)
+ MapKeys(DEFAULT_KEYS);
+ while ((ch = getopt(argc, argv, "hHRs:r:Fk:c:woDSCp:i:")) != -1)
switch (ch) {
case 'c':
initConn = 1;
case 'D':
dropModeEnable = 1;
break;
+ case 'C':
+ colorEnable = 0;
+ break;
case 'S':
standoutEnable = 0;
break;
+ case 'k':
+ MapKeys(optarg);
+ break;
case 'H':
DistInfo();
exit(0);
case 'R':
Rules();
exit(0);
- case 'k':
- {
- int i;
-
- for (i=0;optarg[i] && i < KT_numKeys;i++)
- keyTable[i] = optarg[i];
- break;
- }
case 'h':
Usage();
exit(0);
return 0;
}
+/*
+ * vi: ts=4 ai
+ * vim: noai si
+ */