home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume28 / ldb / part01 / control.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-15  |  3.4 KB  |  111 lines

  1. /*    control.c        9/12/91
  2.  *
  3.  * Copyright 1991  Perry R. Ross
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation without fee is hereby granted, subject to the restrictions
  7.  * detailed in the README file, which is included here by reference.
  8.  * Any other use requires written permission from the author.  This software
  9.  * is distributed "as is" without any warranty, including any implied
  10.  * warranties of merchantability or fitness for a particular purpose.
  11.  * The author shall not be liable for any damages resulting from the
  12.  * use of this software.  By using this software, the user agrees
  13.  * to these terms.
  14.  */
  15.  
  16. #include "ldb.h"
  17.  
  18. /*----------------------------------------------------------------------
  19.  *    control -- control a game
  20.  *
  21.  * This function is called to process the -control command line option.
  22.  * It currently allows the following:
  23.  *    -    The board may be inverted.  The points are still numbered the
  24.  *    same, the board is merely drawn upside down.  This can help users
  25.  *    who are playing a number of games simultaneously by allowing him
  26.  *    to make all of his games move in the same direction on the screen.
  27.  *    - The last packet sent may be resent.  This is useful when moves
  28.  *    are lost in the mail, or if players forget whose turn it is.
  29.  *    Ldb rejects packets that have already been received, so both
  30.  *    players may simply resend their last packet, and ldb will display
  31.  *    the board to the player who is supposed to move.
  32.  *----------------------------------------------------------------------
  33.  */
  34.  
  35. control()
  36. {
  37. register struct game *g;
  38. static char *m[] = {"Invert","Resend","Delete Game","Next Game","Quit",NULL};
  39. char buf[60], c, done;
  40. int mod;
  41.  
  42. if (ghead == NULL) {
  43.     printf("You don't have any games in progress.\n");
  44.     printf("Use the -start option to start one.\n");
  45.     usage(0);
  46.     exit(1);
  47.     }
  48. mod = 0;                /* init to no mods */
  49. FeInitialize();                /* initialize front end */
  50. FeDrawScreen();                /* draw board outline */
  51. done = 0;
  52. for (g = ghead; (done < 2) && (g != NULL); g = g->next) {/* for all games */
  53.     g->curbd = BD_CUR;        /* make sure we draw the current bd */
  54.     FeDrawGame(g);
  55.     FeDrawMenu(m);
  56.     sprintf(buf,"Current state: %s",states[g->state]);
  57.     FeMessage(buf);
  58.     done = 0;
  59.     while (! done) {
  60.         c = FeMenu(m,0,0," \n\r");
  61.         switch (c) {
  62.         case 'I':            /* invert board */
  63.             g->flags ^= F_INVERT;    /* toggle invert bit */
  64.             FeDrawGame(g);        /* redraw the screen */
  65.             mod++;            /* games have been modified */
  66.             break;
  67.         case 'R':            /* resend last packet */
  68.             sendpkt(g,g->lastop);
  69.             FeMessage("Last packet re-sent.");
  70.             break;
  71.         case 'D':            /* delete game */
  72.             mod++;            /* games have been modified */
  73.             if (g->flags & F_DELETE) {    /* undelete */
  74.                 g->flags &= ~F_DELETE;
  75.                 FeMessage("Game undeleted.");
  76.                 }
  77.             else {
  78.                 g->flags |= F_DELETE;    /* delete */
  79.                 FeMessage(
  80.                  "Game deleted -- press D again to undelete.");
  81.                 }
  82.             break;
  83.         case 'Q':            /* exit ldb */
  84.             done = 2;        /* 2 means Really done */
  85.             break;
  86.         case 'N':
  87.         case ' ':
  88.         case '\n':
  89.         case '\r':
  90.             done = 1;    /* 1 means just done with this game */
  91.             break;        /* go to next game */
  92.             }
  93.         }
  94.     }
  95. FeFinishSession();
  96. while (mod) {
  97.     printf("Save changes? [yn]: ");
  98.     if ( ( (c = getchar()) == 'y') || (c == 'Y') ) {
  99.         writegames(rc.gfile,rc.gbackup);
  100.         break;
  101.         }
  102.     if ( (c == 'n') || (c == 'N') ) {
  103.         printf("Changes discarded.\n");
  104.         break;
  105.         }
  106.     if ( (c != '\n') && (c != EOF) )
  107.         while ( ( (c = getchar()) != '\n') && (c != EOF) );
  108.     printf("Please respond with y or n.\n");
  109.     }
  110. }
  111.