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
/
play_info.c
< prev
next >
Wrap
Text File
|
1988-07-28
|
4KB
|
167 lines
/* play_info.c
* get game configuration information from the user.
*/
#include "defs.h"
#include <curses.h>
#include <stdio.h>
/* #include <fcntl.h> */
#include <signal.h>
#define A_Bad_Number -1
/* size of configuration window */
#define Config_Length 17
#define Config_Width 29
extern WINDOW *Config_Win;
extern int BadStandout;
static char brand[3][10] = {"Human ", "Computer"};
int player_info(machine, Back_Window)
int machine[max_players];
WINDOW *Back_Window;
{
int i, cur_player = 0, player_count = 0, tmp_y, tmp_x;
char ch;
WINDOW *Config_Win;
getyx(Back_Window, tmp_y, tmp_x);
wmove(Back_Window, 0, 0);
wrefresh(Back_Window);
/* create configuration window */
Config_Win = newwin(Config_Length, Config_Width, 0, 0);
werase(Config_Win);
BoxUp(Config_Win, Config_Length, Config_Width);
touchwin(Config_Win);
/* set all players to machine by default */
for (i = 0; i < max_players; ++i)
machine[i] = TRUE;
if (! BadStandout)
wstandout(Config_Win);
mvwaddstr(Config_Win, 1, 5, "-- y a h t z e e --");
if (! BadStandout)
wstandend(Config_Win);
mvwaddstr(Config_Win, Config_Length - 2, 1,
"For on-line help press '?'");
while (player_count < 1 || player_count > max_players)
{
mvwaddstr(Config_Win, 3, 2, "number of players: ");
#ifndef SYS5_3
wrefresh(Config_Win);
#endif
/* get the number of players */
ch = wgetch(Config_Win);
if (ch >= '1' && ch <= Max_Players_Ch)
{
player_count = ch - '0';
waddch(Config_Win, ch);
}
else
{
player_count = A_Bad_Number;
switch (ch)
{
case 'b' : rools(Config_Win);
break;
case '?' : help_out(6, Config_Win);
break;
case 's' : dis_score(Config_Win);
break;
case Form_Feed : redraw(Config_Win);
break;
case 'q' : yahtzee_exit(0);
break;
case '!' : shell(Config_Win);
break;
case 'v' : version(Config_Win);
break;
#if defined(SYS5) || defined(SYS5_3)
case '$' : shwin(Config_Win);
break;
#endif
/* default case is bad input so tell the user the limits */
default : mvwprintw(Config_Win, Config_Length -
3, 3, "1 < player count < %d",
max_players);
wrefresh(Config_Win);
sleep(2);
wmove(Config_Win, Config_Length - 3,
3);
waddstr(Config_Win,
" ");
wrefresh(Config_Win);
}
}
}
/* determine which players will be human and which will be simulated */
for (i = 0; i < player_count; ++i)
mvwprintw(Config_Win, i + 5, 3, "%d %s", i, brand[machine[i]]);
do
{
wmove(Config_Win, cur_player + 5, 2);
#ifndef SYS5_3
wrefresh(Config_Win);
#endif
ch = wgetch(Config_Win);
switch(ch)
{
/* toggle between machine and human */
case ' ' : machine[cur_player] = ! machine[cur_player];
mvwprintw(Config_Win, cur_player + 5, 3,
"%d %s", cur_player,
brand[machine[cur_player]]);
break;
/* move cursor up */
case 'k' : --cur_player;
cur_player = wrap(cur_player, 0,
player_count - 1);
break;
/* move cursor down */
case 'j' : ++cur_player;
cur_player = wrap(cur_player, 0,
player_count - 1);
break;
case '?' : help_out(0, Config_Win);
break;
case 'q' : dis_score((WINDOW *) 0);
yahtzee_exit(0);
break;
case 's' : dis_score(Config_Win);
break;
case Form_Feed : redraw(Config_Win);
break;
case 'b' : rools(Config_Win);
break;
case '!' : shell(Config_Win);
break;
case 'v' : version(Config_Win);
break;
#if defined(SYS5) || defined(SYS5_3)
case '$' : shwin(Config_Win);
break;
case '\n' : break;
default : flash();
break;
#endif
}
} while (ch != '\n');
delwin(Config_Win);
/* restore previous window */
touchwin(Back_Window);
wmove(Back_Window, tmp_y, tmp_x);
wrefresh(Back_Window);
return(player_count);
}