home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
BEEHIVE
/
GAMES
/
BLACKJAC.ARC
/
BJ1.C
< prev
next >
Wrap
Text File
|
1988-08-07
|
8KB
|
262 lines
/*------------------------------------------------------------------------*/
/* Subroutines for Blackjack.
function prototypes. */
/*------------------------------------------------------------------------*/
extern void copy_bytes (char *, int, int); /* (from, to, count) */
extern void draw_border (int, int, int, int); /* (x, y, width, height) */
extern void show_card (int, int, int); /* (card, x, y) */
extern void erase_card (int, int); /* (x, y) */
extern void put_string (int, int, char *); /* (x, y, string) */
extern char one_deal (void); /* one deal and bet. */
extern int draw_card (void); /* select a card from pack */
extern int random (int, int); /* (nin, max) */
void delay (int); /* time delay */
int get_score (int); /* compute score of hand. */
char get_reply (char *); /* get reply from user. */
void dollars (long, int, char *); /* decode dollar values. */
void play_game (char, char); /* play one game. */
/*------------------------------------------------------------------------*/
/* includes */
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <cpm.h>
#include <ctype.h>
/* defines */
#define DRAWN 7
#define AVAIL 0
#define BACK 54
/* Global Variables */
/*--------------------------------------------------------------------------*/
extern char deck [53]; /* deck of 52 cards 1 - 52 */
extern char hands [2] [11]; /* two hands with a maximum of 11 cards each. */
extern int scores [2]; /* total scores for player and banker. */
extern int cards [2]; /* number of cards in hands. */
extern int dealt; /* number of cards taken from pack. */
extern long max_bet; /* maximum bet. */
extern long min_bet; /* minimum bet. */
extern long bank; /* Bank funds. */
extern long funds; /* players funds. */
extern char message [80]; /* message to user. */
extern char bankt [12]; /* decoded number. */
extern char fundt [12]; /* decoded number. */
extern char bett [12]; /* decoded number. */
extern char mint [12]; /* decoded number. */
extern char maxt [12]; /* decoded number. */
/*--------------------------------------------------------------------------*/
char get_reply (list) /* get reply from user. */
char *list;
{
char j;
int k;
for (;;)
{
k = rand ();
j = bdos (CPMDCIO, 255);
if (j != '\n')
{
if ((j >= 'a') && (j <= 'z')) j = toupper (j);
for (k = 0; k < strlen(list); k++)
{
if (j == list [k]) return j;
}
}
}
}
/*--------------------------------------------------------------------------*/
void dollars (number, size, line)
long number;
int size;
char *line;
{
int j, k, n;
char text [20];
sprintf (text, "%ld", number);
k = size;
n = 0;
j = strlen (text);
line [k--] = text [j];
for (j--; j >= 0; j--)
{
line [k--] = text [j];
n++;
if (((n % 3) == 0) && (j > 0))
{
line [k--] = ',';
}
}
line [k--] = ' ';
line [k--] = '$';
while (k >= 0)
{
line [k--] = ' ';
}
return;
}
/*--------------------------------------------------------------------------*/
int get_score (no) /* compute score of hand. */
int no;
{
int j, k, aces;
int score; /* total card value */
int values [11]; /* card value */
score = 0;
aces = 0;
for (j = 0; j < cards [no]; j++)
{
k = hands [no] [j];
k %= 13;
if (k == 0) k = 13;
values [j] = k;
if (k == 1)
{
values [j] = 11;
aces++;
}
if (k > 10) values [j] = 10;
score += values [j];
}
while ((score > 21) && (aces > 0))
{
score -= 10;
aces--;
}
k = cards [no];
if (score > 21) score = 26; /* Bust */
if ((k == 2) && (score == 21)) score = 22; /* Blackjack */
if ((k == 5) && (score < 22)) score = 23; /* Five Under */
if ((k == 6) && (score < 22)) score = 24; /* Six Under */
if ((k == 3) && (values [0] == 7) && (values [1] == 7) &&
(values [2] == 7)) score = 25;
return score;
}
/*--------------------------------------------------------------------------*/
void delay (delay_time)
int delay_time;
{
int j, k;
for (j = 0; j <= delay_time; j++)
{
for (k = 0; k < 500; k++);
}
}
/*--------------------------------------------------------------------------*/
void play_game (location, wealth)
char location, wealth;
{
char command; /* command from player. */
int j;
switch (location)
{
case '1': bank = 1000000;
min_bet = 10;
max_bet = 10000;
switch (wealth)
{
case '1': funds = 10000;
break;
case '2': funds = 1000;
break;
case '3': funds = 10;
break;
}
break;
case '2': bank = 100000;
min_bet = 5;
max_bet = 1000;
switch (wealth)
{
case '1': funds = 1000;
break;
case '2': funds = 100;
break;
case '3': funds = 10;
break;
}
break;
case '3': bank = 1000;
min_bet = 1;
max_bet = 50;
switch (wealth)
{
case '1': funds = 200;
break;
case '2': funds = 100;
break;
case '3': funds = 10;
break;
}
break;
}
for (j = 0; j <= 52; j++) deck [j] = AVAIL; /* all cards available. */
cards [0] = 0;
cards [1] = 0;
dealt = 0;
goto_xy (3, 13);
draw_border (0, 0, 80, 24); /* draw a border on the screen. */
draw_border (2, 8, 76, 8); /* draw a border on the screen. */
/* Start of game */
command = '0';
while (command != 'A')
{
command = one_deal ();
if (funds <= 0)
{
put_string (3, 14, "Sorry, but you have run out of funds.");
funds = 0;
delay (100);
}
if (bank <= 0)
{
put_string (3, 14, "Congratulations you have broken the bank.");
bank = 0;
delay (100);
}
cards [0] = 0;
cards [1] = 0;
}
return;
}