home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / yahtzee.t.Z / yahtzee.t / rools.c < prev    next >
Text File  |  1988-07-28  |  3KB  |  133 lines

  1. /* rools.c
  2.  *    put the rules of yahtzee on the screen in neatly overlayed
  3.  *    curses windows (makes a vax look like an Amiga!).
  4.  */
  5. #include <curses.h>
  6. #include <stdio.h>
  7. #include "defs.h"
  8. #include "rools.h"
  9.  
  10. /* length and width of each window */
  11. #define Rule_Window_Length 18
  12. #define Rule_Window_Width (RULE_WIDTH + 2)
  13.  
  14. /* length of the text that will appear on each window */
  15. #define Text_Length (Rule_Window_Length - 2)
  16.  
  17. /* number of windows required to display all the rules (all constants) */
  18. #define Window_Count ((RULE_LENGTH / Text_Length) + 1)
  19.  
  20. rools(Screen)
  21.  
  22. WINDOW *Screen;
  23.  
  24.     {
  25.     int i, j, Y_Move_Increment, X_Move_Increment, y = 0, x = 0,
  26.         Text_Counter = 0, Window_Up, Window_Demanded, tmp_y, tmp_x;
  27.     WINDOW *Rules_Window[Window_Count];
  28.     char ch;
  29.  
  30.     getyx(Screen, tmp_y, tmp_x);
  31.     wmove(Screen, 0, 0);
  32.     wrefresh(Screen);
  33.  
  34. /* determine how far each window will overlap the next */
  35.     X_Move_Increment = (COLS - Rule_Window_Width) / Window_Count;
  36.     Y_Move_Increment = (LINES - Rule_Window_Length) / Window_Count;
  37.  
  38.     for (i = 0; i < Window_Count; ++i)
  39.         {
  40.  
  41. /* create a new rules window */
  42.         Rules_Window[i] = newwin(Rule_Window_Length, Rule_Window_Width,
  43.             y, x);
  44.         werase(Rules_Window[i]);
  45.  
  46. /* load the text for that window */
  47.         for (j = 1; j < Text_Length && Text_Counter < RULE_LENGTH; ++j)
  48.             {
  49.             mvwaddstr(Rules_Window[i], j, 1, rules[Text_Counter]);
  50.             ++Text_Counter;
  51.             }
  52.         BoxUp(Rules_Window[i], Rule_Window_Length, Rule_Window_Width);
  53.  
  54. /* determine position on screen for next window */
  55.         y += Y_Move_Increment;
  56.         x += X_Move_Increment;
  57.         }
  58.  
  59. /* display each window as it is demanded, the first window is
  60.  * displayed without being demanded */
  61.     Window_Up = -1;
  62.     Window_Demanded = 0;
  63.     do
  64.         {
  65.         if (Window_Demanded != Window_Up)
  66.             {
  67.  
  68. /* if window is demanded then bring it to the fore with touchwin */
  69.             touchwin(Rules_Window[Window_Demanded]);
  70.             wrefresh(Rules_Window[Window_Demanded]);
  71.             Window_Up = Window_Demanded;
  72.             }
  73.  
  74. /* give prompt to move through windows */
  75.         mvwaddstr(Rules_Window[Window_Up], Rule_Window_Length - 2, 1,
  76.             "--(m)ore, (q)uit, (b)ack or ?--");
  77. #ifndef SYS5_3
  78.         wrefresh(Rules_Window[Window_Up]);
  79. #endif
  80.         ch = wgetch(Rules_Window[Window_Up]);
  81.  
  82. /* erase prompt */
  83.         mvwaddstr(Rules_Window[Window_Up], Rule_Window_Length - 2, 1,
  84.             "                               ");
  85.         wmove(Rules_Window[Window_Up], Rule_Window_Length - 2, 1);
  86.         wrefresh(Rules_Window[Window_Up]);
  87.         switch (ch)
  88.             {
  89.  
  90. /* display next window */
  91.             case ' ' : ++Window_Demanded;
  92.                    break;
  93.  
  94. /* display next window */
  95.             case 'm' : ++Window_Demanded;
  96.                    break;
  97.  
  98. /* display previous window */
  99.             case 'b' : --Window_Demanded;
  100.                    break;
  101.             case Form_Feed : redraw(Rules_Window[Window_Up]);
  102.                    break;
  103.             case '?' : help_out(4, Rules_Window[Window_Up]);
  104.                    break;
  105.             case 's' : dis_score(Rules_Window[Window_Up]);
  106.                    break;
  107.             case '!' : shell(Rules_Window[Window_Up]);
  108.                    break;
  109.             case 'v' : version(Rules_Window[Window_Up]);
  110.                    break;
  111. #if defined(SYS5) || defined(SYS5_3)
  112.             case '$' : shwin(Rules_Window[Window_Up]);
  113.                    break;
  114.             case 'q' : break;
  115.             default : flash();
  116.                   break;
  117. #endif
  118.             }
  119.  
  120. /* ensure wraparound */
  121.         Window_Demanded = wrap(Window_Demanded, 0, Window_Count - 1);
  122.         } while (ch != 'q');
  123.  
  124. /* remove rule windows */
  125.     for (i = 1; i < Window_Count; ++i)
  126.         delwin(Rules_Window[i]);
  127.  
  128. /* restore previous screen */
  129.     touchwin(Screen);
  130.     wmove(Screen, tmp_y, tmp_x);
  131.     wrefresh(Screen);
  132.     }
  133.