Card Game Routines

Basic and Machine Language

Moderator: Moderators

Post Reply
CurtisP
Vic 20 Dabbler
Posts: 99
Joined: Tue Mar 08, 2005 8:24 pm

Card Game Routines

Post by CurtisP »

I've written some routines for use in writing card games.

The deck of cards is stored in a string. Each character represents one card. The value of the character is 48 + suit * 16 + card value.

Here are the routines:

Build the card deck: The deck his held in D$. Uses I and J.

Code: Select all

110 D$="":FORI=1TO4:FORJ=1TO13:D$=D$+CHR$(I*16+48+J):NEXT:NEXT:RETURN
Draw a random card: Card is removed from D$ and returned in C$. Uses Z. Drops into the Decode card routine.

Code: Select all

120 Z=RND(0)*LEN(D$):C$=MID$(D$,Z+1,1):D$=LEFT$(D$,Z)+MID$(D$,Z+2)
Decode card: Suit# is returned in S and suit Character in S$. Card value is returned in C and card character if returned in C$. Uses Z$.

Code: Select all

130 Z=ASC(C$):S=Z/16-3:S$=MID$("{shift-s}{shift-z}{shift-a}{shift-x}",S,1):C=ZAND15:C$=MID$("A234567890JQK",C,1):RETURN
Print Card: Prints the currently decoded card at the current cursor position. Uses Z$.

Code: Select all

140 Z$=MID$("{black}{red}",S/2+1):PRINT"{black}{shift-u}{shift-asterisk}{shift-i}{down}{left}{left}{left}{shift-minus}"Z$C$"{black}{shift-minus}{down}{left}{left}{left}{shift-minus}"Z$S$"{black}{shift-minus}{down}{left}{left}{left}{shift-j}{shift-asterisk}{shift-k}";:RETURN 
Finally, here is some code that excises the above routines.

Code: Select all

10 GOSUB 110
15 FOR J=1 TO 7
20 FOR I=1 TO 7
30 GOSUB 120
40 GOSUB 140
45 PRINT "{up}{up}{up}";
50 NEXT I
55 PRINT "{down}"
65 NEXT J
80 PRINT
90 END
The code is available at http://www.neoventures.org/jscripts/CARDS.PRG
[/i]
Post Reply