home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource4
/
240_01
/
bg2.c
< prev
next >
Wrap
Text File
|
1987-07-31
|
40KB
|
1,538 lines
/*
** bg2.c -- initialization; major utils: play, arrange, etc.
*/
#include "backgmmn.h"
/*==========================================================================
INITIALIZATION and NEWBOARD commands -- start of a new game, or cold
===========================================================================*/
static char *getAtkn() {
if (tokenstyle) return( get5tkn() );
else return( get1tkn() );
}
static char *getBtkn() {
if (tokenstyle) return( get6tkn() );
else return( get2tkn() );
}
static char *getCtkn() {
if (tokenstyle) return( get7tkn() );
else return( get3tkn() );
}
static char *getDtkn() {
if (tokenstyle) return( get8tkn() );
else return( get4tkn() );
}
static wipeout() {
static int i;
player = 0;
barcube();
for (i = 0; i < 28; i++) {
point[i].stones = point[i].owner = 0;
}
update();
} /* end: wipeout */
setup() {
static int i, j, k; char *copyright;
myscore = yrscore = player = dice[0] = dice[1] = 0;
tokenstyle = swapped = tswap =
expert = helpdisabled = yrdice = FALSE;
show = moremsgline = tone = TRUE;
/* please be sure that main has called vid_init()...!!! */
off_cursor();
title();
token1 = getAtkn();
token2 = getBtkn();
copyright = backtalk[ MYLEVEL + 1 ];
draw_board( copyright );
for (i = 0; i < 28; i++) {
point[i].stones = point[i].owner = 0;
point[i].x = point[i].y = point[i].lastx = point[i].lasty = 0;
point[i].cx = point[i].cy = 0;
}
k = 68;
for (i = 1; i < 13; i++ ) { /* establish xy coords for the points */
j = 25 - i;
point[i].cx = point[j].cx = point[i].x = point[j].x = k;
k -= 5;
point[i].y = 4;
point[j].y = 18;
point[i].cy = 2;
point[j].cy = 20;
if (k == 38) k -= 5; /* skip over bar */
}
point[MYBAR].x = point[YRBAR].x = 38;
point[MYHOME].x = point[YRHOME].x = 75;
point[MYBAR].y = point[MYHOME].y = 5;
point[YRBAR].y = point[YRHOME].y = 17;
} /* end: setup */
newboard() {
static int i;
startcubevalue = 1;
wipedice(); wipeout();
putstone( MYHOME, 15, ME );
putstone( YRHOME, 15, YU );
putstone( YRHOME, 13, YU );
putstone( 1, 2, YU );
putstone( YRHOME, 8, YU );
putstone( 12, 5, YU );
putstone( YRHOME, 5, YU );
putstone( 17, 3, YU );
putstone( YRHOME, 0, 0 );
putstone( 19, 5, YU );
putstone( MYHOME, 10, ME );
putstone( 6, 5, ME );
putstone( MYHOME, 7, ME );
putstone( 8, 3, ME );
putstone( MYHOME, 2, ME );
putstone( 13, 5, ME );
putstone( MYHOME, 0, 0 );
putstone( 24, 2, ME );
} /* end: newboard */
void draw_board( c ) char *c; {
static int line,k;
static char *m = " ", *picture[] = {
"The Peelgrunt Game of GAMMON IV%s",
/* nice ain't it? */
"╔╤═══════════════════════════════╕o╒═══════════════════════════════╤╗",
"║│ ░░ ▓▓ ░░ ▓▓ ░░ ▓▓ │║│ ░░ ▓▓ ░░ ▓▓ ░░ ▓▓ │║",
"║│ │║│ │║",
"║│ ▓▓ ░░ ▓▓ ░░ ▓▓ ░░ │║│ ▓▓ ░░ ▓▓ ░░ ▓▓ ░░ │║",
"╚╧═══════════════════════════════╛o╘═══════════════════════════════╧╝"
};
clr_screen();
off_cursor();
msg(5,23, c );
off_cursor();
line = 0;
gotoxy(0,line++); wprintf(m); wprintf(picture[0],bgversion);
line = 3;
gotoxy(0,line++); wprintf(m); wprintf(picture[1]);
for (k = 0; k < 6; k++) {
gotoxy( 0,line++ ); wprintf(m); wprintf(picture[2]);
}
gotoxy(0,line++); wprintf(m); wprintf(picture[3]);
gotoxy(0,line++); wprintf(m); wprintf(picture[3]);
gotoxy(0,line++); wprintf(m); wprintf(picture[3]);
for (k = 0; k < 6; k++) {
gotoxy( 0,line++ ); wprintf(m); wprintf(picture[4]);
}
gotoxy(0,line); wprintf(m); wprintf(picture[5]);
} /* end: draw_board */
/*=========================================================================
DICE Commands: How to roll the dice
===========================================================================*/
haltgame() {
player = -1; /* if play resumes, ask whose roll it is */
msg(5,22,"Ok.");
jumpjack();
} /* end: haltgame */
static dpeek() {
if (yrdice) return; /* you know your own dice, probably...? */
if (expert) msg(5,22,"");
else msg(5,22,"The Dice will Rattle until you Roll. Now on ");
getdice();
wprintf("[%d] [%d] ...",dice[0],dice[1]);
} /* end: dpeek */
static getonedie() {
return ( (abs(acg()) % 6) + 1 );
} /* end: getonedie */
static fixup() { /* ensure that the low die is in dice[0] */
int d,e;
if (player == 0) return; /* whofirst? don't mess with the odds */
d = min(dice[0],dice[1]);
e = max(dice[0],dice[1]);
dice[0] = d;
dice[1] = e;
} /* end: fixup */
static getdice() {
int ch;
/* if it's MY dice we're using, generate random dice... */
if (!yrdice) {
dice[0] = getonedie();
acg(); /* bounce a little for luck */
dice[1] = getonedie();
}
/* but if it's YOUR dice, then get roll from user's real dice... */
else do
{
msg(5,23,"<> ");
wprintf( "%s roll: ", ((player == ME)? "My": "Your"));
if (!expert) wprintf("\b\b, using your dice: ");
wprintf(" First? ");
ch = keyin( acg );
if (ch == 27) haltgame();
ch -= '0';
if (ch < 1 || ch > 6) continue;
wink( ch + '0');
dice[0] = ch;
wprintf(" Second? ");
ch = keyin( acg );
if (ch == 27) haltgame();
ch -= '0';
if (ch < 1 || ch > 6) continue;
wink( ch + '0');
dice[1] = ch;
wprintf(" All Ok? ");
ch = keyin( acg );
ch = toupper( ch );
if (ch == 27) haltgame();
} while ( ch != 'Y' && ch != '\015' );
fixup();
} /* end: getdice */
static rolldice( who ) int who; {
int waiting,ch;
setchat("You Roll: ");
if (!expert) {
if (!yrdice) strcat(chatter," ^φP^eek,");
strcat(chatter," ^φD^ouble, ^φQ^uit, or <^φAnyKey^> to Roll ");
}
if (player == YU) { /* not executed if player == 0, i.e., whofirst */
waiting = TRUE;
while (waiting) {
msg(5,23,chatter);
ch = keyin(acg);
ch = toupper(ch);
switch ( ch ) {
case 27 : { haltgame(); break; }
case -69: /* F1 */
case 'P': { dpeek(); break; }
case -68: /* F2 */
case 'D': { udouble(); break; }
case -60: /* F10 */
case 'Q': { winner(ME,topstone(YU)); break; }
default : waiting = FALSE;
} }
off_cursor(); msg(5,22,""); msg(5,23,"");
}
highroller(who);
} /* end: rolldice */
static highroller( who ) int who; { /* parameter is not redundant */
static int y = 11;
static int xme, xyu;
/* get the values for two dice, either yours or mine */
getdice();
/* display the values of the dice in the board area */
off_cursor();
xme = 47; xyu = 12; /* decide which half to show the values in */
if (point[1].x > 40) {
xme = 12;
xyu = 47;
}
if (player) {
gotoxy(xyu,y); blanks(18); /* erase, if not whofirst */
gotoxy(xme,y); blanks(18);
}
if (who == ME) {
gotoxy(xme,y); wprintf("My");
}
else {
gotoxy(xyu,y); wprintf("Your");
}
wprintf(" Roll> [%d] ",dice[0]);
if (player) wprintf("[%d