DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T b

⟦9aa596070⟧ TextFile

    Length: 3312 (0xcf0)
    Types: TextFile
    Names: »bj.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/General/Bj/bj.c« 

TextFile

#include <curses.h>
#include "defs.h"

/*
 * This implements the player (client) portion of blackjack.  It's
 * pretty stupid, basically a big case statement.  It listens to
 * the dealer (server), and updates the screen, getting input from
 * the player when necessary.  Here are the commands it sends and
 * receives:
 *
 * commands to client:
 *
 * Pnplayername		add player playername as player n
 * Mstring		display string as a message
 * Rstring		display string and get single char response
 * rstring		display string and get string response
 * Cnhstring		display string as cards for player n hand h
 *
 * commands to server:
 *
 * H			hit with another card
 * S			stand
 * T			split
 * D			double down
 * Q			quit
 * (plus plain old string)
 */
main (argc, argv)
int argc;
char *argv[];
{
	char buf[SLEN], host[20];
	int s, make_con();		/* socket I talk and listen on */
	void send_name();
	char *gets();

	(void) signal(SIGINT, SIG_IGN);
	(void) signal(SIGQUIT, SIG_IGN);
	if (argc == 2)
		s = make_con(*++argv);	/* host is a different machine */
	else  {
		(void) gethostname(host, SLEN);	/* host is this machine */
		s = make_con(host);
	}
	send_name(s);			/* send name, get player info */
	initscr();			/* curses stuff */
	noecho();
	crmode();
	refresh();
	for (;;)  {
		standend();
		sockread(s, buf);	/* get command from dealer */
		switch(buf[0])  {
		case 'P':		/* display player names */
			standout();
			switch(buf[1])  {
			case '0':
				mvaddstr(5, 55, buf + 2);
				break;
			case '1':
				mvaddstr(11, 50, buf + 2);
				break;
			case '2':
				mvaddstr(17, 45, buf + 2);
				break;
			case '3':
				mvaddstr(17, 10, buf + 2);
				break;
			case '4':
				mvaddstr(11, 5, buf + 2);
				break;
			case '5':
				mvaddstr(5, 0, buf + 2);
				mvaddstr(2, 30, "Dealer");
				break;
			}
			refresh();
			break;
		case 'M':		/* display a message */
			move(0, 0);
			clrtoeol();
			mvaddstr(0, 0, buf + 1);
			refresh();
			sleep(1);	/* delete or increase for different delay reading messages */
			break;
		case 'r':		/* display a message, then read a string */
			move(0, 0);
			clrtoeol();
			mvaddstr(0, 0, buf + 1);
			refresh();
			echo();
			nocrmode();
			(void) gets(buf);	/* getstr() screws up tty bits */
			sockwrite(s, buf);
			noecho();
			crmode();
			break;
		case 'R':		/* display a message, then read a char */
			move(0,0);
			clrtoeol();
			mvaddstr(0, 0, buf + 1);
			refresh();
			*buf = getch();
			buf[1] = '\0';
			sockwrite(s, buf);
			break;
		case 'C':		/* display a players hand */
			switch(buf[1])  {
			case '0':	/* the different players */
				move(6, 55);
				break;
			case '1':
				move(12, 50);
				break;
			case '2':
				move(18, 45);
				break;
			case '3':
				move(18, 10);
				break;
			case '4':
				move(12, 5);
				break;
			case '5':
				move(6, 0);
				break;
			case '6':
				move(3, 30);
			}
			/* this places the hands under the player name in the proper row */
			move(stdscr->_cury + buf[2] - '0', stdscr->_curx);
			if (buf[1] == '6')
				addstr(buf + 3);
			else  {
				printw("#%c: ", buf[2] + 1);
				addstr(buf + 3);
			}
			refresh();
			break;
		case 'c':		/* clear screen */
			clear();
			refresh();
			break;
		case 'Q':		/* quit */
			endwin();
			exit(0);
		default:
			puts("Error");
			puts(buf);
		}
		(void) fflush(stdout);
	}
}