home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
100 Great Games for Palm OS 1
/
100PalmV1.iso
/
Cards
/
pocketjack
/
deckofcards_fo.cpk
< prev
next >
Wrap
Text File
|
1999-03-06
|
4KB
|
184 lines
# deckofcards_fo.cpk
# deck of cards module for any card game
# 6mar99, ver 0.1, frank o'brien, dianfrank@worldnet.att.net,
# http://home.att.net/~dianfrank/casl_page.htm
# freeware, no warranty, copyright
# user guide
# see comments in sections marked "public"
# CARD VARIABLES - private
variables;
# deck constants
numeric dc_nShufs=10;
numeric dc_nShufCards=10;
numeric dc_nShufDelay=1000; # 1 s delay
numeric dc_nLastCard=52;
# deck variables
numeric dc_nDeck[dc_nLastCard];
numeric dc_nNextCard; # index for deck array
# temp string for holder main program name
string dc_sMainTitle;
end;
# card variables - public
variables;
# user can append to about text, if desired
dc_sCredits="Card functions provided by "+
"deckofcards_fo.cpk, ver 0.1, 6Mar99, Frank O'Brien, "+
"http://home.att.net/~dianfrank/casl_page.htm"+char(10)+char(10)+
"Single deck of 52 shuffled cards. After all cards dealt, "+
"deck is reshuffled by exchanging 2 random cards "+
string(dc_nShufs*dc_nShufCards,"")+" times.";
end;
# CARD FUNCTIONS - private
# given cards to arrange, shufs times, randomly rearranges global deck array
# by exchanging card elements of array.
# displays "shuffling..." on frMain for 2 s delay, as signal that shuffling,
# after delay, actually does shuffle
#
function dc_Shuffle;
variables;
numeric temp;
numeric i;
numeric j;
numeric n;
numeric m;
numeric t;
string s;
end;
# display that shuffling
get frMain, s;
put frMain, "Shuffling...";
# delay so can read display
t=timevalue();
while timevalue()-t<dc_nShufDelay;
end_while;
# do shuffle
i=0;
while i<dc_nShufs;
j=0;
while j<dc_nShufCards;
n=randomn(52);
m=randomn(52);
temp=dc_nDeck[n];
dc_nDeck[n]=dc_nDeck[m];
dc_nDeck[m]=temp;
j=j+1;
end_while;
i=i+1;
end_while;
# return to original display
put frMain, "PocketJack"; # s as parameter doesn't work, bug?
end;
# CARD FUNCTIONS - public
# basic dealing functions
# initializes deck, must call once in startup function
#
function dc_InitDeck;
variables;
numeric i;
end;
# fill deck
i=0;
while i<52;
dc_nDeck[i]=i;
i=i+1;
end_while;
dc_nNextCard=52; # force shuffle
end;
# returns next card in deck 0-51, if last card, performs reshuffle first
#
function dc_nfNextCard as numeric;
if dc_nNextCard=dc_nLastCard;
call dc_Shuffle;
dc_nNextCard=0;
end_if;
dc_nfNextCard=dc_nDeck[dc_nNextCard];
dc_nNextCard=dc_nNextCard+1;
end;
# card information accessors
#given 0-51, returns 2-14
#
function dc_nfFace(numeric n) as numeric;
dc_nfFace=n%13+2;
end;
#given 0-51, returns 0-3
#
function dc_nfSuit(numeric n) as numeric;
dc_nfSuit=int(n/13);
end;
# display function - private
#given 0-51, returns display string for face 2-14
#
function dc_sfFace(numeric n) as string;
n=dc_nfFace(n);
if n > 1 and n < 10; # number 2-9
dc_sfFace=Char(48+n);
end_if;
if n = 10; # 10
dc_sfFace=Char(49)+Char(48);
end_if;
if n = 11; # jack
dc_sfFace=Char(74);
end_if;
if n = 12; # queen
dc_sfFace=Char(81);
end_if;
if n = 13; # king
dc_sfFace=Char(75);
end_if;
if n = 14; # high ace
dc_sfFace=Char(65);
end_if;
end;
#given 0-51, returns display string for 0-3 suit
#
function dc_sfSuit(numeric n) as string;
n=dc_nfSuit(n);
# do suit string for each platform, windows font doesn't have
# suit char
if platform = "windows";
if n=0;
dc_sfSuit="d";
end_if;
if n=1;
dc_sfSuit="c";
end_if;
if n=2;
dc_sfSuit="h";
end_if;
if n=3;
dc_sfSuit="s";
end_if;
else;
# pilot platform
dc_sfSuit=Char(141+n);
end_if;
end;
# Display functions - public
#given 0-51, returns display string for face and suit
#
function dc_sfCardName(numeric n) as string;
dc_sfCardName=dc_sfFace(n)+dc_sfSuit(n);
end;