home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume6 / connect4 / screen.c < prev    next >
C/C++ Source or Header  |  1989-07-06  |  3KB  |  183 lines

  1. #include <stdio.h>
  2. #include <curses.h>
  3. #include "c4.h"
  4.  
  5. #define  BASEY 0
  6. #define  BASEX 0 
  7. #define  LINE0  "    0       1       2       3       4       5       6    "
  8. #define  LINE1  ".-------------------------------------------------------."
  9. #define  LINE2  "|       |       |       |       |       |       |       |"
  10. #define  LINE3  "|-------+-------+-------+-------+-------+-------+-------|"
  11. #define  LINE4  "`-------------------------------------------------------'"
  12.  
  13. char  *filler[] = {"XXXXXXX", "OOOOOOO" };
  14.  
  15. static int row_levels[] = {5, 5, 5, 5, 5, 5, 5};
  16.  
  17. void
  18. init_screen()
  19. {
  20.     initscr();
  21.     crmode();
  22.     noecho();
  23.     plot_screen();
  24. }
  25.  
  26. void
  27. plot_screen()
  28. {
  29.     register int i;
  30.     register int j;
  31.  
  32.     clear();
  33.     move(0,60);
  34.     standout();
  35.     printw("C O N N E C T   4");
  36.     standend();
  37.     move(4,60);
  38.     printw("  YOUR MOVE:  ");
  39.     move(7,60);
  40.     printw("    MY MOVE:  ");
  41.     move(BASEY,BASEX);
  42.     printw(LINE0);
  43.     move(BASEY+1,BASEX);
  44.     printw(LINE1);
  45.     for (i = 0; i < 6; i++){
  46.         for (j = 0; j < 2; j++){
  47.             move(BASEY + 2 + 3*i + j , BASEX);
  48.             printw(LINE2);
  49.         }
  50.         move(BASEY + 4 + 3*i , BASEX);
  51.         printw(LINE3);
  52.     }
  53.     move(BASEY + 19, BASEX);
  54.     printw(LINE4);  
  55.     refresh();
  56. }
  57.  
  58. void
  59. show_move(column, who)
  60. int column;
  61. int who;
  62. {
  63.     int row;
  64.     int other_row;
  65.  
  66.     if (who == OURS){
  67.         row = 7;
  68.         other_row = 4;
  69.     }
  70.     else{
  71.         row = 4;
  72.         other_row = 7;
  73.     }
  74.  
  75.     move(row, 73);
  76.     printw("%1d",column);
  77.     move(other_row, 73);
  78.     printw(" ");
  79.     move(other_row, 73);
  80.     refresh();
  81.  
  82. void
  83. accept_move(who)
  84. int who;
  85. {
  86.     int row;
  87.  
  88.     if (who == OURS)
  89.         row = 7;
  90.     else
  91.         row = 4;
  92.  
  93.     move(row, 73);
  94.     printw(" ");
  95.     move(row, 73);
  96.     refresh();
  97. }
  98.  
  99.  
  100. /* VARARGS1 */
  101. void
  102. report(fmt, a, b, c, d, e, f)
  103. char *fmt;
  104. char *a, *b, *c, *d, *e, *f;
  105. {
  106.     move(22, 0);
  107.     printw(fmt, a, b, c, d, e, f);
  108.     refresh();
  109. }
  110.  
  111. void
  112. plot_finish()
  113. {
  114.     move(23,0);
  115.     refresh();
  116.     nocrmode();
  117.     echo();
  118. }
  119.  
  120.  
  121. void
  122. fill_column(column, colour)
  123. int column;
  124. int colour;
  125. {
  126.     register int i;
  127.     register int row;
  128.  
  129.     row = row_levels[column];
  130.     row_levels[column]--;
  131.  
  132.     for (i = 2; i < 4; i++){
  133.         move(BASEY + i + 3*row, BASEX + 1 + 8*column);
  134.         if (colour == OURS) {
  135.             standout();
  136.             printw(filler[colour]);
  137.             standend();
  138.         }
  139.         else{
  140.             printw(filler[colour]);
  141.         }
  142.     }
  143.     refresh();
  144. }
  145.  
  146. void
  147. fill_square(square, colour)
  148. int square;
  149. int colour;
  150. {
  151.     register int i;
  152.     register int row;
  153.     register int column;
  154.  
  155.     row = square / 7;
  156.     column = square % 7;
  157.  
  158.     for (i = 2; i < 4; i++){
  159.         move(BASEY + i + 3*row, BASEX + 1 + 8*column);
  160.         if (colour == OURS) {
  161.             standout();
  162.             printw(filler[colour]);
  163.             standend();
  164.         }
  165.         else{
  166.             printw(filler[colour]);
  167.         }
  168.     }
  169.     refresh();
  170. }
  171.  
  172.  
  173. void
  174. reset_row_levels()
  175. {
  176.     register int i;
  177.  
  178.     for (i = 0; i < COLUMNS; i++){
  179.         row_levels[i] = 5;
  180.     }
  181. }
  182.