'===========================================================================
' Subject: Golf Card Game - A Remake          Date: 18-18-02 (  :  )       
'  Author: Richard D. Clark                   Code: IBASIC                 
'  Origin: rickclark58@yahoo.com            Packet: GAMES.ABC
'===========================================================================
'    Copyright (C) 2003  Richard D. Clark
'	 rickclark58@yahoo.com

'    This program is free software; you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation; either version 2 of the License, or
'    (at your option) any later version.

'    This program is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with this program; if not, write to the Free Software
'    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

' Required in Form Load to use dll
DECLARE "qcard32.dll",InitializeDeck(hwnd:INT),INT
' Reset all card values to defaults
DECLARE "qcard32.dll",SetDefaultValues()
' Set the currently used card back design for cards 105 to 109
DECLARE "qcard32.dll",SetCurrentBack(nIndex:INT)
' Card drawing "qcard32.dll",s
DECLARE "qcard32.dll",DrawSymbol(hwnd:INT, nValue:INT, x:INT, y:INT)
DECLARE "qcard32.dll",DealCard(hwnd:INT, nCard:INT, x:INT, y:INT)
DECLARE "qcard32.dll",DrawCard(hwnd:INT, nCard:INT, x:INT, y:INT)
DECLARE "qcard32.dll",RemoveCard(hwnd:INT, nCard:INT)
DECLARE "qcard32.dll",DrawBack(hwnd:INT, nValue:INT, x:INT, y:INT)
' Get card information "qcard32.dll",s
DECLARE "qcard32.dll",GetCardValue(nCard:INT),INT
DECLARE "qcard32.dll",GetCardBlocked(nCard:INT),INT
DECLARE "qcard32.dll",IsCardDisabled(nCard:INT),INT
DECLARE "qcard32.dll",GetCardX(nCard:INT),INT
DECLARE "qcard32.dll",GetCardY(nCard:INT),INT
' Set card information "qcard32.dll",s
DECLARE "qcard32.dll",SetCardStatus(nCard:INT, bValue:INT)
DECLARE "qcard32.dll",AdjustCardBlocked(nCard:INT, bValue:INT)
DECLARE "qcard32.dll",SetCardDisabled(nCard:INT, bValue:INT)
' Dragging "qcard32.dll",s and "qcard32.dll",s
DECLARE "qcard32.dll", InitDrag(hwnd:INT, x:INT, y:INT),INT
DECLARE "qcard32.dll", AbortDrag()

'Golf declarations.
DECLARE LoadCards()
DECLARE DrawCards()
DECLARE CardClick(x:INT, y:INT)
DECLARE StartUp()
DECLARE ShowHelp()
DECLARE DrawCardBacks()
DECLARE SelectCardBack(x:INT, y:INT)
DECLARE LoadCardSettings(pname:STRING)
DECLARE SaveCardSettings()
DECLARE ShowHighScores()
DECLARE ShowWin()

TYPE playpref
	DEF playname:STRING
	DEF design:INT
	DEF highscore:INT
ENDTYPE
DEF playerpref:playpref

CONST FACEDOWN = 0
CONST FACEUP = 1
CONST CARDWIDTH = 71
CONST CARDHEIGHT = 96
CONST OFFSET = 16
CONST TRUE = 1
CONST FALSE = 0
CONST PLACEX = 1
CONST PLACE0 = 2
CONST PLACEC = 3
CONST WINWIDTH = 700
CONST WINHEIGHT = 400

DEF run:INT
DEF w:WINDOW 
DEF d1:DIALOG
DEF draw[16]:INT
DEF stack[7,5]:INT
DEF played[52]:INT
DEF cardsleft:INT
DEF playptr:INT
DEF backcolor:INT
DEF ingame:INT
DEF playy:INT
DEF ret:INT
DEF score:INT
DEF bonus:INT
DEF selectback:INT
DEF showhs:INT
DEF gamewon:INT

DIALOG d1,0,0,234,108,0x80C80080,0,"Enter Name",dHandler
CONTROL d1,"T,Name:,7,16,42,20,0x5000010B,1"
CONTROL d1,"E,Player,47,15,144,20,0x50800000,2"
CONTROL d1,"B,&OK,82,63,70,20,0x50000001,3"

'Get the player's name.
DOMODAL d1

WINDOW w,0,0,WINWIDTH,WINHEIGHT,@SIZE|@MINBOX|@NOAUTODRAW|@MAXBOX,0,"IBasic Golf",main 
CENTERWINDOW w 
MENU w,"T,&Game,0,0","I,New,0,1","I,-,0,0","I,Quit,0,2"
INSERTMENU w,1,"T,&Options,0,0","I,Card Design,0,3","I,High Scores,0,4"
INSERTMENU w,2,"T,&Help,0,0","I,Contents,0,5"

'The window color - standard green.
backcolor = RGB(0, 130, 0)
'Set the default for the select cards.
selectcard = FALSE
'Can only cal this once.
ret = InitializeDeck(w)
IF ret = FALSE
	'If we can't load the dll then exit.
	MESSAGEBOX w,"Cannot initialize Qcards32.dll.","IBasic Golf"
	run = 0
ELSE
	'Ket's go.
	StartUp
	run = 1 
ENDIF
'Strat main event loop.
WAITUNTIL run=0 
CLOSEWINDOW w:END 


SUB main 
	SELECT @CLASS 
	CASE @IDCLOSEWINDOW 
		'Save the current settings.
		SaveCardSettings
		'Exit flag
		run = 0
	CASE @IDPAINT
		'Show the design selection screen.
		IF selectback = TRUE
			DrawCardBacks
		ELSE
			'Show the high scores
			IF showhs = TRUE
				ShowHighScores
			ELSE
				'Did the player win the game?
				IF gamewon = TRUE
					ShowWin
				ELSE
					'Draw the cards
					DrawCards
				ENDIF
			ENDIF
		ENDIF
	CASE @IDLBUTTONUP
		'Get the selected card design
		IF selectback = TRUE
			SelectCardBack @MOUSEX, @MOUSEY
		ELSE
			'Clear the high scores
			IF showhs = TRUE
				showhs = FALSE
				SETWINDOWCOLOR w, backcolor
			ELSE
				'Process the move
				IF ingame = TRUE
					CardClick @MOUSEX, @MOUSEY
				ENDIF
			ENDIF
		ENDIF
	CASE @IDMENUPICK
		SELECT @MENUNUM
			CASE 1
				'New
				Startup
				DrawCards
			CASE 2
				'Quit
				run = 0
			CASE 3
				'Card design
				selectback = TRUE
				SETWINDOWCOLOR w, backcolor
			CASE 4
				'High scores
				showhs = TRUE
				SETWINDOWCOLOR w, backcolor
			CASE 5
				'Display the help file.
				ShowHelp
		ENDSELECT
	ENDSELECT 
RETURN 

SUB dHandler
	DEF answer:STRING

	SELECT @CLASS
   	CASE @IDCONTROL
		SELECT @CONTROLID
        CASE 3
			'Player clicked the OK button.
			answer = GETCONTROLTEXT(d1, 2)
   		    CLOSEDIALOG d1,@IDOK
			LoadCardSettings answer
        ENDSELECT
	CASE @IDINITDIALOG
 	   CENTERWINDOW d1
	ENDSELECT
RETURN

SUB LoadCards
	DEF i,j:INT
	DEF temp:INT
	DEF k:INT
	DEF deck[52]:INT
	DEF cnt:INT
	DEF carddisabled:INT

	'Load all the cards
	FOR i = 0 TO 51
		deck[i] = i + 1
	NEXT i	
	'Shuffle the cards.	
	FOR i = 0 TO 51
		'Get a random slot.
		k = RND(52) - 1
		'Get the value for the slot.
		temp = deck[k]
		'Swap the values with the current slot.
		deck[k] = deck[i]
		deck[i] = temp
	NEXT i
	'Load the stacks.
	FOR i = 0 to 6
		FOR j = 0 to 4
			stack[i,j] = deck[cnt]
			'Block the card
			AdjustCardBlocked(stack[i,j], TRUE)
			carddisabled = GetCardBlocked(stack[i,j])
			cnt = cnt + 1
		NEXT j
	NEXT i
	'Unblock the cards in the last rows of the stacks.
	FOR i = 0 to 6
		AdjustCardBlocked stack[i,4], FALSE
	NEXT i
	'Load the rest of the cards, except the last into the draw stack.
	FOR i = 0 TO 15
		draw[i] = deck[cnt]
		cnt = cnt + 1
		'Increment the cards left counter.
		cardsleft = cardsleft + 1
	NEXT i
	'Put the last card in play.
	played[0] = deck[51]
	'Set the current play spot.
	playptr = 0
RETURN

SUB DrawCards
	DEF x,y:INT
	DEF i,j:INT

	'Draw the table cards.
	x = -CARDWIDTH + OFFSET:y = 0
	FOR i = 0 TO 6
		x = x + CARDWIDTH + 2
		y = OFFSET
		FOR j = 0 TO 4
			'Deal the table cards
			IF stack[i, j]<>0
				DealCard w, stack[i, j], x, y
				y = y + OFFSET
			ENDIF
		NEXT j
	NEXT i
	y = 200
	'Save this for the message.
	playy = y
	x = OFFSET
	'If we are out of draw cards, sraw the placeholder
	IF cardsleft = 0
		DrawSymbol w, PLACEX, x, y
	ENDIF
	'Set the card back
	SetCurrentBack(playerpref.design)
	'The draw pile.
	FOR i = 0 TO 15
		IF draw[i]<>0
			'Deal it face down.
			SetCardStatus draw[i], FACEDOWN
			Dealcard w, draw[i], x, playy
		ENDIF
	NEXT i
	'Draw the played cards.
	x = CARDWIDTH + (OFFSET * 2)
	FOR i = 0 to playptr
		IF played[i]<>0
			'Deal the played card.
			Dealcard w, played[i], x, y
			'Diasble it so it is out of play.
			SetCardDisabled played[i], TRUE
			x = x + 8
		ENDIF
	NEXT i
	WriteMessage
RETURN

SUB CardClick(x:INT, y:INT)
	DEF source:INT
	DEF sourcevalue:INT
	DEF destvalue:INT
	DEF i,j,k:INT
	DEF found:INT
	DEF carddisabled:INT
	DEF cardx:INT
	DEF cardy:INT

	'Get the source card.
	source = InitDrag(w, x, y)
	'Abort the drag. We are only trying to get the selected card.
	AbortDrag
	'Get the old location
	cardx = GetCardX(source)
	cardy = GetCardY(source)
	'Is the card blocked?
	carddisabled = GetCardBlocked(source)
	'Is a valid card selected.
	IF (source > 0) & (carddisabled = FALSE)
		'Check to see if the card is in the draw pile.
		found = FALSE
		FOR i = 0 to 15
			IF draw[i] = source
				'We found the card
				found = TRUE
				'Remove it from the pile.
				RemoveCard w, source
				'Set the card to face up
				SetCardStatus draw[i], FACEUP
				'Add the card to the play pile.
				playptr = playptr + 1
				played[playptr] = draw[i]
				draw[i] = 0
				cardsleft = cardsleft - 1
				'Reset the bonus.
				bonus = 0
				'Redraw the window
				Drawcards
				'*** Test win sub
				'playptr = 51
				'Did the player win?
				IF playptr = 51
					'Thousand point bonus
					score = score + 1000
					IF score > playerpref.highscore
						playerpref.highscore = score
					ENDIF
					ingame = FALSE
					'Do the win routine.
					gamewon = TRUE
					SETWINDOWCOLOR w, backcolor
				ENDIF
				GOTO GetOut
			ENDIF
		NEXT i

		'Look for the card in the card stack.
		IF found = FALSE
'stop
			FOR i = 0 to 6
				FOR j = 0 to 4
					IF (stack[i,j] = source) 
						'Get the source value.
						sourcevalue = GetCardValue(source)
						'Get the top dest card value.
						destvalue = GetCardValue(played[playptr])
						'Is the card playable?
						IF ABS(sourcevalue - destvalue) = 1
							'Remove the card from the screen.
							RemoveCard w, source
							'Clear the stack array
							stack[i,j] = 0
							'Set the previous card, if any, to unblocked.
							IF (j - 1) >= 0
								AdjustCardBlocked stack[i,j-1], FALSE
							ENDIF
							'Add the card to the play pile.
							playptr = playptr + 1
							played[playptr] = source
							'Increment the score
							score = score + (10 * sourcevalue)
							score = score + bonus
							'Add in the bonus
							bonus = bonus + 10
							'New high score?
							IF score > playerpref.highscore
								playerpref.highscore = score
							ENDIF
							'Repaint the window
							RECT w, cardx, cardy, CARDWIDTH, CARDHEIGHT , RGB(0,130,0), RGB(0,130,0)
							DrawCards
							'Did the player win?
							IF playptr = 51
								'Thousand point bonus
								score = score + 1000
								IF score > playerpref.highscore
									playerpref.highscore = score
								ENDIF
								ingame = FALSE
								'Do the win routine.
								gamewon = TRUE
								SETWINDOWCOLOR w, backcolor
							ENDIF
							'Get out of the loop.
							GOTO GetOut
						ENDIF
					ENDIF
				NEXT j
			NEXT i
		ENDIF
	ENDIF
GetOut: 
RETURN

SUB WriteMessage()
	'Set the defaults
	MOVE w, OFFSET, playy + CARDHEIGHT + 2
	FRONTPEN w, RGB(255, 255, 255)
	BACKPEN w, backcolor
	'How many cards left in draw pile
	PRINT w, "Cards: " + STR$(cardsleft) + "  "
	RECT w, 545, OFFSET, 130, 90 , RGB(255,255,0), RGB(0,130,0)
	MOVE w, 545 + OFFSET + 10, OFFSET + 10
	'write the title
	PRINT w, "IBasic Golf"
	MOVE w, 545 + OFFSET - 5, OFFSET + 35
	PRINT w, "By Richard Clark"
	MOVE w, 545 + OFFSET + 10, OFFSET + 60
	PRINT w, "Version 1.0"
	'write the score.
	MOVE w, 545, OFFSET + 100
	PRINT w, "Score: " + STR$(score)
	'Write the current bonus.
	MOVE w, 545, OFFSET + 125
	PRINT w, "Bonus: " + STR$(bonus) + "    "
	'Write the highscore.
	MOVE w, 545, OFFSET + 150
	PRINT w, "High Score: " + STR$(playerpref.highscore) + "    "
	
RETURN

SUB StartUp
	DEF i:INT
	DEF j:INT

	'Save the current settings.
	SaveCardSettings
	'Clear the window.
	SETWINDOWCOLOR w, backcolor
	'Reset the card dll
	SetDefaultValues
	'Clear the deck.
	FOR i = 0 to 51
		RemoveCard w, i + 1
	NEXT i
	'Clear the work arrays.
	FOR i = 0 TO 15
		draw[i] = 0
	NEXT i
	FOR i = 0 to 6
		FOR j = 0 to 4
			stack[i,j] = 0
		NEXT j
	NEXT i
	FOR i = 0 to 51
		played[i] = 0
	NEXT i
	'Reset the values.
	ingame = TRUE
	cardsleft = 0
	score = 0
	bonus = 0
	selectback = FALSE
	showhs = FALSE
	gamewon = FALSE
	'Load all the cards into the deck array.
	LoadCards
RETURN

SUB DrawCardBacks
	DEF i:INT
	DEF x,y:INT

	'Draw the card backs.
	x = 50:y = 100
	DrawBack w, 1, x, y
	x = 150:y = 100
	DrawBack w, 2, x, y
	x = 250:y = 100
	DrawBack w, 3, x, y
	x = 350:y = 100
	DrawBack w, 4, x, y
	x = 450:y = 100
	DrawBack w, 5, x, y
	x = 550:y = 100
	DrawBack w, 6, x, y

	FRONTPEN w, RGB(255, 255, 255)
	BACKPEN w, backcolor
	MOVE w, 280, 50
	PRINT w, "Select Card Design"
	MOVE w, 160, 250
	PRINT w, "Click on card to select design or green area to cancel."
	
RETURN

SUB SelectCardBack(x:INT, y:INT)
	
	'Which card did player select.
	IF (x >= 50) & (x <= 50 + CARDWIDTH)
		IF (y >= 100) & (y <= 100 + CARDHEIGHT)
			playerpref.design = 1
			GOTO GetOutSelectCard
		ENDIF
	ENDIF
	IF (x >= 150) & (x <= 150 + CARDWIDTH)
		IF (y >= 100) & (y <= 100 + CARDHEIGHT)
			playerpref.design = 2
			GOTO GetOutSelectCard
		ENDIF
	ENDIF
	IF (x >= 250) & (x <= 250 + CARDWIDTH)
		IF (y >= 100) & (y <= 100 + CARDHEIGHT)
			playerpref.design = 3
			GOTO GetOutSelectCard
		ENDIF
	ENDIF
	IF (x >= 350) & (x <= 350 + CARDWIDTH)
		IF (y >= 100) & (y <= 100 + CARDHEIGHT)
			playerpref.design = 4
			GOTO GetOutSelectCard
		ENDIF
	ENDIF
	IF (x >= 450) & (x <= 450 + CARDWIDTH)
		IF (y >= 100) & (y <= 100 + CARDHEIGHT)
			playerpref.design = 5
			GOTO GetOutSelectCard
		ENDIF
	ENDIF
	IF (x >= 550) & (x <= 550 + CARDWIDTH)
		IF (y >= 100) & (y <= 100 + CARDHEIGHT)
			playerpref.design = 6
			GOTO GetOutSelectCard
		ENDIF
	ENDIF

GetOutSelectCard:
	selectback = FALSE
	SETWINDOWCOLOR w, backcolor
RETURN

SUB ShowHelp
	DEF helpfile:STRING
	DEF ret:INT

	'Get the program folder.
	helpfile = GETSTARTPATH
	IF RIGHT$(helpfile,1)<>"\"
		helpfile = helpfile + "\"
	ENDIF
	helpfile = helpfile + "ibgolf.chm"
	'Show the help file.
	SYSTEM helpfile
RETURN

SUB LoadCardSettings(pname:STRING)
	DEF cfgfile:STRING
	DEF f:FILE
	DEF fret:INT
	DEF item:STRING
	DEF fread:INT
	DEF rdata:STRING
	DEF isep:INT

	'Set the default balues.
	playerpref.playname = pname
	playerpref.design = 1
	playerpref.highscore = 0
	'Get the program folder.
	cfgfile = GETSTARTPATH
	IF RIGHT$(cfgfile,1)<>"\"
		cfgfile = cfgfile + "\"
	ENDIF
	cfgfile = cfgfile + "ibgolf.cfg"
	fret = OPENFILE(f, cfgfile,"R")
	IF fret = 0
		'Get the file data.
		WHILE EOF(f) = FALSE
			fread = READ(f, item)
			IF fread = 0
				'Parse the string.
				isep = INSTR(item, ";")
				IF isep > 0
					'Get the name
					rdata = LEFT$(item, isep - 1)
					'Do we have a match.
					IF rdata = pname
						'Clip off the name.
						item = MID$(item, isep + 1)
						'Get card design
						isep = INSTR(item, ";"
						IF isep > 0
							rdata = LEFT$(item, isep - 1)
							playerpref.design = VAL(rdata)
							'Clip off the design
							item = MID$(item, isep + 1)
							'Save the highscore
							playerpref.highscore = VAL(item)
							GOTO GetOutLoadCards
						ENDIF
					ENDIF
				ENDIF
			ENDIF
		ENDWHILE
	ENDIF
GetOutLoadCards:
	IF fret = 0
		CLOSEFILE f
	ENDIF
RETURN

SUB SaveCardSettings
	DEF cfgfile:STRING
	DEF tempfile:STRING
	DEF folder:STRING
	DEF f:FILE
	DEF f1:FILE
	DEF fret:INT
	DEF fret1:INT
	DEF item:STRING
	DEF rdata:STRING
	DEF pdata:STRING

'stop	
	'Get the program folder.
	folder = GETSTARTPATH
	'Build the ini filename
	IF RIGHT$(folder,1)<>"\"
		folder = folder + "\"
	ENDIF
	cfgfile = folder + "ibgolf.cfg"
	tempfile  = folder + "ibgolf.tmp"
	'Try and open the config file.
	fret = OPENFILE(f, cfgfile,"R")
	IF fret <> 0
		'Create a new file.
		fret = OPENFILE(f, cfgfile,"A")
		item = RTRIM$(playerpref.playname) 
		rdata = LTRIM$((STR$(playerpref.design)) 
		pdata = LTRIM$(STR$(playerpref.highscore))
		item = item + ";" + rdata + ";" + pdata
		WRITE f, item
		CLOSEFILE f
		GOTO GetOutSaveFile
	ENDIF
	'Copy the items to a temp file.
	fret1 = OPENFILE(f1, tempfile,"A")
	IF (fret = 0) & (fret1 = 0)
		'Write out the player info first.
		item = RTRIM$(playerpref.playname) 
		rdata = LTRIM$((STR$(playerpref.design)) 
		pdata = LTRIM$(STR$(playerpref.highscore))
		item = item + ";" + rdata + ";" + pdata
		WRITE f1, item
		'Get the file data.
		WHILE EOF(f) = FALSE
			fread = READ(f, item)
			IF fread = 0
				'Parse for the string.
				isep = INSTR(item, ";")
				IF isep > 0
					'Get the name
					rdata = LEFT$(item, isep - 1)
					'Do we have a match.
					IF rdata <> playerpref.playname
						'Write out the data
						WRITE f1, item
					ENDIF
				ENDIF
			ENDIF
		ENDWHILE
	ENDIF
	'Close the files.
	IF fret = 0
		CLOSEFILE f
	ENDIF
	IF fret1 = 0
		CLOSEFILE f1
	ENDIF
	'Copy over the new file.
	IF (fret = 0) & (fret1 = 0)
		COPYFILE tempfile, cfgfile, 0
		DELETEFILE tempfile
	ENDIF
GetOutSaveFile:
RETURN

SUB ShowHighScores
	DEF cfgfile:STRING
	DEF fret:INT
	DEF f:FILE
	DEF x,y:INT
	DEF isep:INT
	DEF rdata:STRING
	DEF outdata:STRING
	DEF item:STRING

	'Save the current settings.
	SaveCardSettings
	'Draw the border.	
	RECT w, 20, 20, WINWIDTH - 40, WINHEIGHT - 80 , RGB(255,255,0), BACKCOLOR
	'Set the pen markers.
	FRONTPEN w, RGB(255, 255, 0)
	BACKPEN w, backcolor
	'Print the header.
	x = 30:y = 10
	MOVE w, x, y
	PRINT w, " * High Scores * "
	FRONTPEN w, RGB(255, 255, 255)
	'Get the program folder.
	cfgfile = GETSTARTPATH
	IF RIGHT$(cfgfile,1)<>"\"
		cfgfile = cfgfile + "\"
	ENDIF
	cfgfile = cfgfile + "ibgolf.cfg"
	fret = OPENFILE(f, cfgfile, "R")
	IF fret = 0
		'Get the file data.
		WHILE EOF(f) = FALSE
			fread = READ(f, item)
			IF fread = 0
				'Parse the string.
				isep = INSTR(item, ";")
				IF isep > 0
					'Get the name
					rdata = LEFT$(item, isep - 1)
					'Save the name
					outdata = rdata + ": "
					'Clip off the name.
					item = MID$(item, isep + 1)
					'Clip off the card design
					isep = INSTR(item, ";"
					IF isep > 0
						'Get the high score
						item = MID$(item, isep + 1)
						outdata = outdata + item
						'Adjust the columns
						y = y + 20
						IF y > (WINHEIGHT - 100)
							x = x + 50
							y = 10
						ENDIF
						MOVE w, x, y
						PRINT w, outdata
					ENDIF
				ENDIF
			ENDIF
		ENDWHILE		
	ENDIF
	'Close the file.
	IF fret = 0
		CLOSEFILE f
	ENDIF
	'Print close instructions.
	MOVE w, 30, WINHEIGHT - 70
	PRINT w, " Click window to return to game. "
	
RETURN

SUB ShowWin
	DEF x,y:INT
	DEF i:INT
	DEF msg:STRING
	
	'The win message
	msg = " Wow! You won the game! "
	FOR i = 1 TO 113
		x = RND(WINWIDTH)
		Y = RND(WINHEIGHT)
		DrawCard w, i, x, y
	NEXT i
	FOR i = 1 TO 113
		x = RND(WINWIDTH)
		Y = RND(WINHEIGHT)
		DrawCard w, i, x, y
	NEXT i
	'Set the pen markers.
	FRONTPEN w, RGB(255, 255, 255)
	BACKPEN w, backcolor
	'Print close instructions.
	RECT w, 250, 30, 190, 30, RGB(255,255,0), backcolor
	MOVE w, 258, 35
	PRINT w, msg
RETURN
