home *** CD-ROM | disk | FTP | other *** search
- /* control.c 9/12/91
- *
- * Copyright 1991 Perry R. Ross
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation without fee is hereby granted, subject to the restrictions
- * detailed in the README file, which is included here by reference.
- * Any other use requires written permission from the author. This software
- * is distributed "as is" without any warranty, including any implied
- * warranties of merchantability or fitness for a particular purpose.
- * The author shall not be liable for any damages resulting from the
- * use of this software. By using this software, the user agrees
- * to these terms.
- */
-
- #include "ldb.h"
-
- /*----------------------------------------------------------------------
- * control -- control a game
- *
- * This function is called to process the -control command line option.
- * It currently allows the following:
- * - The board may be inverted. The points are still numbered the
- * same, the board is merely drawn upside down. This can help users
- * who are playing a number of games simultaneously by allowing him
- * to make all of his games move in the same direction on the screen.
- * - The last packet sent may be resent. This is useful when moves
- * are lost in the mail, or if players forget whose turn it is.
- * Ldb rejects packets that have already been received, so both
- * players may simply resend their last packet, and ldb will display
- * the board to the player who is supposed to move.
- *----------------------------------------------------------------------
- */
-
- control()
- {
- register struct game *g;
- static char *m[] = {"Invert","Resend","Delete Game","Next Game","Quit",NULL};
- char buf[60], c, done;
- int mod;
-
- if (ghead == NULL) {
- printf("You don't have any games in progress.\n");
- printf("Use the -start option to start one.\n");
- usage(0);
- exit(1);
- }
- mod = 0; /* init to no mods */
- FeInitialize(); /* initialize front end */
- FeDrawScreen(); /* draw board outline */
- done = 0;
- for (g = ghead; (done < 2) && (g != NULL); g = g->next) {/* for all games */
- g->curbd = BD_CUR; /* make sure we draw the current bd */
- FeDrawGame(g);
- FeDrawMenu(m);
- sprintf(buf,"Current state: %s",states[g->state]);
- FeMessage(buf);
- done = 0;
- while (! done) {
- c = FeMenu(m,0,0," \n\r");
- switch (c) {
- case 'I': /* invert board */
- g->flags ^= F_INVERT; /* toggle invert bit */
- FeDrawGame(g); /* redraw the screen */
- mod++; /* games have been modified */
- break;
- case 'R': /* resend last packet */
- sendpkt(g,g->lastop);
- FeMessage("Last packet re-sent.");
- break;
- case 'D': /* delete game */
- mod++; /* games have been modified */
- if (g->flags & F_DELETE) { /* undelete */
- g->flags &= ~F_DELETE;
- FeMessage("Game undeleted.");
- }
- else {
- g->flags |= F_DELETE; /* delete */
- FeMessage(
- "Game deleted -- press D again to undelete.");
- }
- break;
- case 'Q': /* exit ldb */
- done = 2; /* 2 means Really done */
- break;
- case 'N':
- case ' ':
- case '\n':
- case '\r':
- done = 1; /* 1 means just done with this game */
- break; /* go to next game */
- }
- }
- }
- FeFinishSession();
- while (mod) {
- printf("Save changes? [yn]: ");
- if ( ( (c = getchar()) == 'y') || (c == 'Y') ) {
- writegames(rc.gfile,rc.gbackup);
- break;
- }
- if ( (c == 'n') || (c == 'N') ) {
- printf("Changes discarded.\n");
- break;
- }
- if ( (c != '\n') && (c != EOF) )
- while ( ( (c = getchar()) != '\n') && (c != EOF) );
- printf("Please respond with y or n.\n");
- }
- }
-