home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume2 / nchess / part03 / msgsw.c < prev    next >
C/C++ Source or Header  |  1987-11-25  |  2KB  |  89 lines

  1. /*
  2.  * Copyright 1987 Tom Anderson; 20831 Frank Waters Road;
  3.  * Stanwood, WA  98282.   All rights reserved.
  4.  */
  5.  
  6. /*
  7.  * message subwindow handling
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <ctype.h>
  12. #include <suntool/tool_hs.h>
  13. #include <suntool/panel.h>
  14. #include <strings.h>
  15.  
  16. #include "nchess.h"
  17.  
  18. struct toolsw * MessageSW;
  19. Panel MessagePanel;
  20.  
  21. Panel_item MessageItem;
  22.  
  23. /*
  24.  * set up the message subwindow
  25.  */
  26. void
  27. InitMsgSW()
  28. {
  29.     if ((MessageSW = panel_create(NchessTool, 0)) == NULL) {
  30.     fprintf(stderr, "Can't create message panel\n");
  31.     exit(1);
  32.     }
  33.     MessagePanel = MessageSW->ts_data;
  34.     /* create the message panel item */
  35.     MessageItem = panel_create_item(MessagePanel, PANEL_MESSAGE,
  36.     PANEL_LABEL_STRING, 
  37.         RestoringGame ? "Please wait..." :
  38.         SetupMode ? "Setup: left - source, middle - delete, right - end" :
  39.         IsMachine[Turn] || Turn != MyColor ? 
  40.         (Turn == WHITE ?
  41.             "Waiting for white to play..." : 
  42.             "Waiting for black to play...") :
  43.         "Your move" ,
  44.     PANEL_SHOW_ITEM, TRUE,
  45.     0);
  46.     panel_fit_height(MessagePanel); 
  47. }
  48.  
  49. void 
  50. Message(cp)
  51.     char * cp;
  52. {
  53.     panel_set(MessageItem,
  54.     PANEL_LABEL_STRING, cp,
  55.     PANEL_SHOW_ITEM, TRUE,
  56.     0);
  57. }
  58.  
  59. /*
  60.  * write the standard "your move", "waiting ..." message
  61.  * pre-pended with the passed string (if non-null)
  62.  */
  63. void
  64. WhoseMoveMessage(cp)
  65.     char * cp;
  66. {
  67.     char c1[256], c2[256];
  68.  
  69.     if (GameOver) 
  70.     strcpy(c2, "Game over");
  71.     else if (IsMachine[Turn] || Turn != MyColor)
  72.     strcpy(c2, Turn == WHITE ? 
  73.         "Waiting for white to play..." :
  74.         "Waiting for black to play...");
  75.     else if (InCheck())
  76.     strcpy(c2, "Your move (check)");
  77.     else
  78.     strcpy(c2, "Your move");
  79.  
  80.     if (cp != (char *) 0) {
  81.     c2[0] = tolower(c2[0]);
  82.     strcpy(c1, cp);
  83.     strcat(c1, " - ");
  84.     Message(strcat(c1, c2));
  85.     } else 
  86.     Message(c2);
  87. }
  88.  
  89.