home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / y / bsdgames / bsd-game.000 / bsd-game / games / hunt / terminal.c < prev   
Encoding:
C/C++ Source or Header  |  1993-09-21  |  1.7 KB  |  111 lines

  1. /*
  2.  *  Hunt
  3.  *  Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
  4.  *  San Francisco, California
  5.  */
  6.  
  7. # include    "hunt.h"
  8. # define    TERM_WIDTH    80    /* Assume terminals are 80-char wide */
  9.  
  10. /*
  11.  * cgoto:
  12.  *    Move the cursor to the given position on the given player's
  13.  *    terminal.
  14.  */
  15. cgoto(pp, y, x)
  16. register PLAYER    *pp;
  17. register int    y, x;
  18. {
  19.     if (x == pp->p_curx && y == pp->p_cury)
  20.         return;
  21.     sendcom(pp, MOVE, y, x);
  22.     pp->p_cury = y;
  23.     pp->p_curx = x;
  24. }
  25.  
  26. /*
  27.  * outch:
  28.  *    Put out a single character.
  29.  */
  30. outch(pp, ch)
  31. register PLAYER    *pp;
  32. char        ch;
  33. {
  34.     if (++pp->p_curx >= TERM_WIDTH) {
  35.         pp->p_curx = 0;
  36.         pp->p_cury++;
  37.     }
  38.     (void) putc(ch, pp->p_output);
  39. }
  40.  
  41. /*
  42.  * outstr:
  43.  *    Put out a string of the given length.
  44.  */
  45. outstr(pp, str, len)
  46. register PLAYER    *pp;
  47. register char    *str;
  48. register int    len;
  49. {
  50.     pp->p_curx += len;
  51.     pp->p_cury += (pp->p_curx / TERM_WIDTH);
  52.     pp->p_curx %= TERM_WIDTH;
  53.     while (len--)
  54.         (void) putc(*str++, pp->p_output);
  55. }
  56.  
  57. /*
  58.  * clrscr:
  59.  *    Clear the screen, and reset the current position on the screen.
  60.  */
  61. clrscr(pp)
  62. register PLAYER    *pp;
  63. {
  64.     sendcom(pp, CLEAR);
  65.     pp->p_cury = 0;
  66.     pp->p_curx = 0;
  67. }
  68.  
  69. /*
  70.  * ce:
  71.  *    Clear to the end of the line
  72.  */
  73. ce(pp)
  74. PLAYER    *pp;
  75. {
  76.     sendcom(pp, CLRTOEOL);
  77. }
  78.  
  79. /*
  80.  * ref;
  81.  *    Refresh the screen
  82.  */
  83. ref(pp)
  84. register PLAYER    *pp;
  85. {
  86.     sendcom(pp, REFRESH);
  87. }
  88.  
  89. /*
  90.  * sendcom:
  91.  *    Send a command to the given user
  92.  */
  93. /* VARARGS2 */
  94. sendcom(pp, command, arg1, arg2)
  95. register PLAYER        *pp;
  96. register int    command;
  97. int            arg1, arg2;
  98. {
  99.     (void) putc(command, pp->p_output);
  100.     switch (command & 0377) {
  101.       case MOVE:
  102.         (void) putc(arg1, pp->p_output);
  103.         (void) putc(arg2, pp->p_output);
  104.         break;
  105.       case ADDCH:
  106.       case READY:
  107.         (void) putc(arg1, pp->p_output);
  108.         break;
  109.     }
  110. }
  111.