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 >
Wrap
Text File
|
1988-07-28
|
3KB
|
133 lines
/* rools.c
* put the rules of yahtzee on the screen in neatly overlayed
* curses windows (makes a vax look like an Amiga!).
*/
#include <curses.h>
#include <stdio.h>
#include "defs.h"
#include "rools.h"
/* length and width of each window */
#define Rule_Window_Length 18
#define Rule_Window_Width (RULE_WIDTH + 2)
/* length of the text that will appear on each window */
#define Text_Length (Rule_Window_Length - 2)
/* number of windows required to display all the rules (all constants) */
#define Window_Count ((RULE_LENGTH / Text_Length) + 1)
rools(Screen)
WINDOW *Screen;
{
int i, j, Y_Move_Increment, X_Move_Increment, y = 0, x = 0,
Text_Counter = 0, Window_Up, Window_Demanded, tmp_y, tmp_x;
WINDOW *Rules_Window[Window_Count];
char ch;
getyx(Screen, tmp_y, tmp_x);
wmove(Screen, 0, 0);
wrefresh(Screen);
/* determine how far each window will overlap the next */
X_Move_Increment = (COLS - Rule_Window_Width) / Window_Count;
Y_Move_Increment = (LINES - Rule_Window_Length) / Window_Count;
for (i = 0; i < Window_Count; ++i)
{
/* create a new rules window */
Rules_Window[i] = newwin(Rule_Window_Length, Rule_Window_Width,
y, x);
werase(Rules_Window[i]);
/* load the text for that window */
for (j = 1; j < Text_Length && Text_Counter < RULE_LENGTH; ++j)
{
mvwaddstr(Rules_Window[i], j, 1, rules[Text_Counter]);
++Text_Counter;
}
BoxUp(Rules_Window[i], Rule_Window_Length, Rule_Window_Width);
/* determine position on screen for next window */
y += Y_Move_Increment;
x += X_Move_Increment;
}
/* display each window as it is demanded, the first window is
* displayed without being demanded */
Window_Up = -1;
Window_Demanded = 0;
do
{
if (Window_Demanded != Window_Up)
{
/* if window is demanded then bring it to the fore with touchwin */
touchwin(Rules_Window[Window_Demanded]);
wrefresh(Rules_Window[Window_Demanded]);
Window_Up = Window_Demanded;
}
/* give prompt to move through windows */
mvwaddstr(Rules_Window[Window_Up], Rule_Window_Length - 2, 1,
"--(m)ore, (q)uit, (b)ack or ?--");
#ifndef SYS5_3
wrefresh(Rules_Window[Window_Up]);
#endif
ch = wgetch(Rules_Window[Window_Up]);
/* erase prompt */
mvwaddstr(Rules_Window[Window_Up], Rule_Window_Length - 2, 1,
" ");
wmove(Rules_Window[Window_Up], Rule_Window_Length - 2, 1);
wrefresh(Rules_Window[Window_Up]);
switch (ch)
{
/* display next window */
case ' ' : ++Window_Demanded;
break;
/* display next window */
case 'm' : ++Window_Demanded;
break;
/* display previous window */
case 'b' : --Window_Demanded;
break;
case Form_Feed : redraw(Rules_Window[Window_Up]);
break;
case '?' : help_out(4, Rules_Window[Window_Up]);
break;
case 's' : dis_score(Rules_Window[Window_Up]);
break;
case '!' : shell(Rules_Window[Window_Up]);
break;
case 'v' : version(Rules_Window[Window_Up]);
break;
#if defined(SYS5) || defined(SYS5_3)
case '$' : shwin(Rules_Window[Window_Up]);
break;
case 'q' : break;
default : flash();
break;
#endif
}
/* ensure wraparound */
Window_Demanded = wrap(Window_Demanded, 0, Window_Count - 1);
} while (ch != 'q');
/* remove rule windows */
for (i = 1; i < Window_Count; ++i)
delwin(Rules_Window[i]);
/* restore previous screen */
touchwin(Screen);
wmove(Screen, tmp_y, tmp_x);
wrefresh(Screen);
}