The QBasic / QB64 Discussion Forum      Other Subforums, Links and Downloads
 
  << Previous Topic | Next Topic >>Return to Index  

Yet another deal-52-cards program

February 2 2008 at 7:22 AM
  (Premier Login iorr5t)
Forum Owner

DECLARE FUNCTION crdDelt% (cmd AS INTEGER)
DIM SHARED crdU AS INTEGER ' Undelt cards
CLS
GOSUB ShuffleDeck
DO
  PRINT : PRINT "Undealt cards:"; crdU
  PRINT "Press ESC to quit, 'S' to shuffle, anything else deal 13 cards: ";
  LOCATE , , 1: k$ = INPUT$(1): PRINT k$
  IF k$ = CHR$(27) THEN EXIT DO
  GOSUB NotESC
LOOP
CLS
SYSTEM

NotESC:
IF UCASE$(k$) = "S" THEN GOSUB ShuffleDeck: RETURN
IF crdU = 0 THEN PRINT "No cards left! You need to shuffle": RETURN
FOR i = 1 TO 13: PRINT crdDelt(1); : NEXT i: PRINT
RETURN

ShuffleDeck:
crdU = 52
IF crdDelt(0) > 0 THEN RETURN
RETURN

FUNCTION crdDelt% (cmd AS INTEGER)
STATIC dd AS STRING * 52
IF cmd = 0 THEN dd = STRING$(52, "-"): crdU = 52: EXIT FUNCTION
crdU = crdU - 1: IF crdU < 0 THEN STOP' User forgot to shuffle
r = 1 + INT(RND * 52)
DO
  IF MID$(dd, r, 1) = "-" THEN EXIT DO
  r = r + 1: IF r > 52 THEN r = 1
LOOP
MID$(dd, r, 1) = " "
crdDelt% = r
END FUNCTION

 


 
 Respond to this message   
Current Topic - Yet another deal-52-cards program
  << Previous Topic | Next Topic >>Return to Index  

Newbies usually go to www.qbasic.com and click on The QBasic Forum
Forum regulars have their own ways, which include The QBasic Community Forums