home *** CD-ROM | disk | FTP | other *** search
/ The CIA World Factbook 1992 / k3bimage.iso / sel / 04 / 0009 / disp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-02  |  5.4 KB  |  215 lines

  1. /* disp.c -- Most of the display-oriented functions for Targ-Hurt ESP
  2.              Trainer.
  3.  
  4.    History: 23-mar-87
  5. */
  6.  
  7. #include "colors.h"
  8. #include "mancon.h"
  9. #include "declares.h"
  10. #include <stdio.h>
  11. #define BLINK 16
  12.  
  13.  
  14. /* Terminal's foreground and background colors. */
  15. IMPORT gi_fg1, gi_fg2, gi_bg1, gi_bg2;
  16.  
  17.  
  18. /* disp_top -- Displays box-character drawing at top of screen.
  19. */
  20. void disp_top(title)
  21. char *title;
  22. {  int j;
  23.  
  24.    curlocat(1,31); colrprts(title, gi_fg1, gi_bg1);
  25.    curlocat(2,0);  colrprta(218, gi_fg1, gi_bg1);
  26.    for(j=1; j<79; j++) colrprta(196, gi_fg1, gi_bg1);
  27.    colrprtc(191, gi_fg1, gi_bg1);
  28.    curlocat(3,0);  colrprtc(179, gi_fg1, gi_bg1);
  29.    curlocat(3,79); colrprtc(179, gi_fg1, gi_bg1);
  30.    curlocat(4,0);  colrprta(212, gi_fg1, gi_bg1);
  31.    for(j=1; j<79; j++) colrprta(205, gi_fg1, gi_bg1);
  32.    colrprtc(190, gi_fg1, gi_bg1);
  33.  
  34.    curlocat(3,2);  colrprts("Hits:", gi_fg1, gi_bg1);
  35.    curlocat(3,13); colrprts("Tries:", gi_fg1, gi_bg1);
  36.    curlocat(3,26); colrprts("Hit %:", gi_fg1, gi_bg1);
  37. }
  38.  
  39.  
  40. /* disp_cbot -- Displays menu for clairvoyance mode at bottom of screen.
  41. */
  42. void disp_cbot()
  43. {
  44.    curlocat(24, 21);
  45.    colrprtf(0, gi_fg1, gi_bg1,
  46.       "Press: %c %c %c %c P)ass, R)eset, Q)uit",
  47.        24, 25, 27, 26
  48.       ); /* Characters 24-27 are displayed as arrows. */
  49. }
  50.  
  51.  
  52. /* disp_pbot -- Displays menu for precognition mode at bottom of screen.
  53. */
  54. void disp_pbot()
  55. {
  56.    curlocat(24, 11);
  57.    colrprtf(0, gi_fg1, gi_bg1,
  58.       "Press: %c %c %c %c P)ass, R)eset, C)hange-time-delay, Q)uit",
  59.        24, 25, 27, 26
  60.       ); /* Characters 24-27 are displayed as arrows. */
  61.  
  62. }
  63.  
  64.  
  65. /* disp_crtmode -- set video mode on color monitors
  66. */
  67. void disp_crtmode()
  68. {  IMPORT gi_vidmode;
  69.    int dummy;
  70.  
  71.    getscmod(&gi_vidmode, &dummy, &dummy);
  72.    if(gi_vidmode==7)
  73.    {  clrscrn();
  74.       gi_fg1=7;
  75.       gi_fg2=0;
  76.       gi_bg1=0;
  77.       gi_bg2=7;
  78.    }
  79.    else
  80.    {  setscmod(3);                     /* Set video mode to color 80x25 */
  81.       border(BLUE);
  82.       gi_fg1=WHITE;
  83.       gi_fg2=YELLOW;
  84.       gi_bg1=BLUE;
  85.       gi_bg2=RED;
  86.    }
  87. }
  88.  
  89.  
  90. /* disp_cls()  -- Clear the screen and fill it with color. */
  91. void disp_cls()
  92. {  IMPORT gi_fg1, gi_bg1;
  93.    clscolor(gi_fg1, gi_bg1);
  94. }
  95.  
  96.  
  97. /* disp_cursor -- Turns cursor on or off depending on the value of flag.
  98. */
  99. void disp_cursor(flag)
  100. int flag;
  101. {  IMPORT int gi_vidmode;
  102.    if(flag==ON)
  103.       if(gi_vidmode==7) curtype(0,12,13);  /* For monochrome. */
  104.       else              curtype(0, 6, 7);  /* For color.      */
  105.    else
  106.       curtype(1,0,0);
  107. }
  108.  
  109.  
  110. static struct blip {
  111.    int row, col;
  112.    char direction[25];
  113.    } blips[4] = { { 7, 27, "         NORTH        "},
  114.                   { 21,27, "         SOUTH        "},
  115.                   { 14,45, "         EAST         "},
  116.                   { 14,10, "         WEST         "},
  117.                 };
  118.  
  119.  
  120. /* disp_score -- Updates the scores display.
  121. */
  122. void disp_score()
  123. {  IMPORT int gi_hits, gi_tries;
  124.  
  125.    curlocat(3, 8);  colrprtf(0, gi_fg2, gi_bg2, "%-4d", gi_hits);
  126.    curlocat(3, 20); colrprtf(0, gi_fg1, gi_bg1, "%-5d", gi_tries);
  127.    curlocat(3, 33); colrprtf(0, gi_fg1, gi_bg1, "%-3d", (gi_tries<=0) ? 0 :
  128.       (int)(( (float)gi_hits / (float)gi_tries )*100.0) );
  129. }
  130.  
  131.  
  132. /* pf_display -- Displays machine's selection and updates encouragement
  133.                  message.
  134. */
  135. void pf_display()
  136. {
  137.    IMPORT int gi_encourage, gi_direction, gi_wasahit;
  138.    IMPORT struct encouragement gsa_enc[];
  139.    static old_encourage=0;
  140.  
  141.    disp_score();
  142.  
  143.    /* Update encouragement message. */
  144.    if(old_encourage!=gi_encourage)
  145.    {  old_encourage = gi_encourage;
  146.       curlocat(3, 38);
  147.       colrprtf(0, gi_fg1, gi_bg1, "%30s","");
  148.       curlocat(3, 38);
  149.       colrprtf(0, gi_fg2, gi_bg2, "%s", gsa_enc[gi_encourage].message);
  150.    }
  151.  
  152.    if(gi_direction==RESET) return;
  153.  
  154.    if(kbhit()==0)  /* Don't display machine's selection if keypress is
  155.                       waiting. */
  156.    {  curlocat(blips[gi_direction].row, blips[gi_direction].col);
  157.       colrprtf(0, gi_fg2+((gi_wasahit)? BLINK : 0), gi_bg2, "%s",
  158.          blips[gi_direction].direction);
  159.  
  160.       wait_keytime( gi_wasahit ? 10 : 1 );
  161.  
  162.       curlocat(blips[gi_direction].row, blips[gi_direction].col);
  163.       colrprtf(0, gi_fg1, gi_bg1, "%s", blips[gi_direction].direction);
  164.    }
  165.  
  166.  
  167. }
  168.  
  169.  
  170. /* pf_waitmsg -- Displays message acknowlegement message at center of
  171.                  screen (for mode_precognition).
  172. */
  173. void pf_waitmsg(toggle, string)
  174. int toggle;
  175. char *string;
  176. {  int foreg, backg;
  177.    
  178.    curlocat(14, 28);
  179.    if(toggle==ON) { foreg=gi_fg2; backg=gi_bg2; }
  180.    else           { foreg=gi_fg1; backg=gi_bg1; }
  181.    colrprtf(0, foreg, backg, "%-20s", string);
  182. }
  183.  
  184.  
  185. /* pf_change_delay -- Menu to update the delay between user input and
  186.                       machine selection (for mode_precognition).
  187. */
  188. void pf_change_delay(pdelay)
  189. int *pdelay;
  190. {
  191.    char temp='9';
  192.    char *validvals = {"123"};
  193.  
  194.    curlocat(24, 0);
  195.    coloreol(gi_fg1, gi_bg1);
  196.    curlocat(24, 5);
  197.    colrprts(" How long a delay do you want?  1) second, 2) seconds, 3) seconds ",
  198.       gi_fg1, gi_bg1);
  199.    
  200.    while(strchr(validvals, temp)==NULL)
  201.    {  curlocat(24, 77);
  202.       getkey(&temp);
  203.    }
  204.    
  205.    curlocat(24, 0);
  206.    coloreol(gi_fg1, gi_bg1);
  207.    disp_pbot();
  208.  
  209.    switch(temp)
  210.    {  case '1' : *pdelay=10; break;
  211.       case '2' : *pdelay=20; break;
  212.       case '3' : *pdelay=30; break;
  213.    }
  214. }
  215.