' Card DLL Contest' Anandis' http://www.pagat.com/invented/anandis.html' August, 2011' Uses Qcard32.dll, a freeware library of playing card images.' DLL by Stephen Murphy. Qcard32.DLL website:' http://www.telusplanet.net/public/stevem/' Rules' 2 Players' 17 card deck (4 Aces, 12 face cards, one Joker)' 8 cards alternately dealt to each player' Last card is placed face down in middle of table' Object of the game is to guess the card in the middle' Player opposite the dealer starts first' Play options are' Guess the card in the middle' Correct guess = WIN game' Incorrect guess = LOSE game' Either way, game ends' Play a card' Opponent lays down all cards of the' same suit and same rank' Play then passes to the opposing player' Pass the Joker' If held, the player may pass the Joker' to the opposing player, forcing that' player to play' A player with less than 2 cards MUST' guess the middle card' Winner is the best of 7 handsWindowWidth=800WindowHeight=500UpperLeftX=Int((DisplayWidth-WindowWidth)/2)UpperLeftY=Int((DisplayHeight-WindowHeight)/2)graphicbox#main.g,0,0,800,500open"Simple Anandis"forwindowas#main
#main "trapclose [quit]"
hGbox =hWnd(#main.g)#main.g "down; color 0 192 0; backcolor 0 192 0"#main.g "font verdana 12 bold"#main.g "place 0 0; boxfilled 800 500; flush bg"#main.g "place 355 305; boxfilled 425 385"#main.g "flush clearGuess"#main.g "color black"#main.g "place 365 325"#main.g "\ ???"#main.g "\Guess"#main.g "\ Card"#main.g "\ ???"#main.g "flush playerGuess"#main.g "color 0 192 0"' Initialize the deckcall InitializeDeck hGbox
call SetCurrentBack 3' Select (by number) only the cards to be used' 11 = Jack Clubs, 24 = Jack Diamonds' 37 = Jack Hearts, 50 = Jack Spadesdim dCards(17)
dCards(1)=11
dCards(2)=24
dCards(3)=37
dCards(4)=50' 12 = Queen Clubs, 25 = Queen Diamonds' 38 = Queen Hearts, 51 = Queen Spades
dCards(5)=12
dCards(6)=25
dCards(7)=38
dCards(8)=51' 13 = King Clubs, 26 = King Diamonds' 39 = King Hearts, 52 = King Spades
dCards(9)=13
dCards(10)=26
dCards(11)=39
dCards(12)=52' 1 = Ace Clubs, 14 = Ace Diamonds' 27 = Ace Hearts, 40 = Ace Spades
dCards(13)=1
dCards(14)=14
dCards(15)=27
dCards(16)=40' 110 = Joker
dCards(17)=110' Set up array to hold nCards to shuffledim nCards(17)' Set up an array to hold visibility of cardsdim iCards(17)' Set up array to hold xCards to determine best guessdim xCards(17)' Fill arrayscall InitCards
' Set up array to hold cardsdim hand1(2,8)dim hand2(2,8)' (1, = computer's hand' (2, = player's hand' , 1-8) = nCard' , 9: 1-8 = nCard' Set GameInProgressFlag
GameInProgressFlag =0' Select dealer
dealer =int(rnd(1)*2)+1if dealer =1then
human =2
computer =1else
human =1
computer =2endif' Define coordinates
x1 =50' x of dealt cards
x2 =50' x of revealed cards
y1 =300' y of human cards
y2 =30' y of computer cards[AnnounceDealer]call AnnounceDealer dealer
[ShuffleCards]' Remove cards from handredim hand1(2,8)redim hand2(2,8)' Shuffle the cardscall ShuffleCards dealer
' Deal the cardscall NewDeal dealer, hGbox
[AnnouncePlayer]if dealer = human then
playerTurn = computer
else
playerTurn = human
endifcall AnnouncePlayer playerTurn
if playerTurn = human then' Human's Turn#main.g "when leftButtonDown [PlayerClick]"waitendif' Computer's Turnwait[quit]close#qc
close#main
end[PlayerClick]
xPos =MouseX
yPos =MouseY
clickCard =-1selectcasecase yPos <300
clickCard =0case yPos >395
clickCard =0case xPos >400
clickCard =0case xPos >352
clickCard =9case xPos >260if xPos <330then
clickCard =8else
clickCard =0endifif clickCard =8thenif hand1(1,8)=0then
clickCard =0if hand1(1,7)>0thenif xPos <300then
clickCard =7endifendifendifendifcase xPos >230if xPos <300then
clickCard =7else
clickCard =0endifif clickCard =7thenif hand1(1,7)=0then
clickCard =0if hand1(1,6)>0thenif xPos <270then
clickCard =6endifendifendifendifcase xPos >200if xPos <270then
clickCard =6else
clickCard =0endifif clickCard =6thenif hand1(1,6)=0then
clickCard =0if hand1(1,5)>0thenif xPos <240then
clickCard =5endifendifendifendifcase xPos >170if xPos <240then
clickCard =5else
clickCard =0endifif clickCard =5thenif hand1(1,5)=0then
clickCard =0if hand1(1,4)>0thenif xPos <210then
clickCard =4endifendifendifendifcase xPos >140if xPos <210then
clickCard =4else
clickCard =0endifif clickCard =4thenif hand1(1,4)=0then
clickCard =0if hand1(1,3)>0thenif xPos <180then
clickCard =3endifendifendifendifcase xPos >110if xPos <180then
clickCard =3else
clickCard =0endifif clickCard =3thenif hand1(1,3)=0then
clickCard =0if hand1(1,2)>0thenif xPos <150then
clickCard =2endifendifendifendifcase xPos >80if xPos <150then
clickCard =2else
clickCard =0endifif clickCard =2thenif hand1(1,2)=0then
clickCard =0if hand1(1,1)>0thenif xPos <120then
clickCard =1endifendifendifendifcase xPos >50if xPos <120then
clickCard =1else
clickCard =0endifendselectif clickCard <1thencall RefreshCards hGbox,1call RefreshCards hGbox,2waitendif
nCard = hand1(1, clickCard)
hand2(1, clickCard)= hand1(1, clickCard)
hand1(1, clickCard)=0call RefreshCards hGbox,1[computerDiscardsLikes]' Find all invisible cardsfor i =1to17
iC = iCards(i)for j =1to8if hand2(1, j)= iC then
iCards(i)=0endifif hand1(2, j)= iC then
iCards(i)=0endifif hand2(2, j)= iC then
iCards(i)=0endifnext j
next i
sort iCards(),17,1
nChoices =0for i =1to17if iCards(i)>0then
nChoices = nChoices +1endifnext i
cValue = GetCardValue(hand2(1, clickCard))if cValue =99then
cValue =-1endif
cSuit = GetCardSuit(hand2(1, clickCard))for i =1to8if GetCardValue(hand1(2, i))= cValue thencall SetCardStatus hand1(2, i),1
hand2(2, i)= hand1(2, i)
hand1(2, i)=0endifif GetCardSuit(hand1(2, i))= cSuit thencall SetCardStatus hand1(2, i),1
hand2(2, i)= hand1(2, i)
hand1(2, i)=0endifnext i
call RefreshCards hGbox,2waitsub Pause ms
calldll#kernel32,"Sleep", _
ms aslong, _
result asvoidendsubsub InitializeDeck hGbox
open"qcard32.dll"fordllas#qc
calldll#qc,"InitializeDeck", _
hGbox asulong, _
result aslongendsubsub SetCardStatus nCard, face
'nC is number of card - 1-52 in first deck and'53-104 in second deck, if used'face: 0=facedown,1=faceupcalldll#qc,"SetCardStatus", _
nCard aslong,_
face aslong,_
result asvoidendsubsub DealCard hGbox, nCard, xPos, yPos
'places card on window whose handle is hGbox at xPos, yPos'nC is number of card - 1-52 in first deck and'53-104 in second deck, if usedcalldll#qc,"DealCard", _
hGbox asulong, _
nCard aslong,_
xPos aslong, _
yPos aslong, _
result asvoidendsubsub RemoveCard hGbox,nCard
'removes a card from screen that was'drawn with DealCard, replacing screen backgroundcalldll#qc,"RemoveCard", _
hGbox asulong, _
nCard aslong, _
result asvoidendsubsub SetCurrentBack nDesign
'nDesign can be 1,2,3,4,5,6 for 6 possible designscalldll#qc,"SetCurrentBack", _
nDesign aslong, _
result asvoidendsubsub RefreshCards hGbox, player
for i =1to8call RemoveCard hGbox, hand1(player, i)call RemoveCard hGbox, hand2(player, i)next i
if player =1then#main.g "place 40 295; boxfilled 340 400"
yPos =300else#main.g "place 40 45; boxfilled 340 150"
yPos =50endif
x1Pos =50
x2Pos =450for i =1to8
n1Card = hand1(player, i)if n1Card >0thencall DealCard hGbox, n1Card, x1Pos, yPos
endif
n2Card = hand2(player, i)if n2Card >0thencall DealCard hGbox, n2Card, x2Pos, yPos
endif
x1Pos = x1Pos +30
x2Pos = x2Pos +30next i
endsubsub InitCards
for i =1to17
nCards(i)= dCards(i)
iCards(i)= dCards(i)
xCards(i)= dCards(i)next i
endsubsub ShuffleCards dealer
for i =17to2 step -1
n =int(rnd(1)* i)+1
temp = nCards(i)
nCards(i)= nCards(n)
nCards(n)= temp
next i
if dealer =1then
hand1 =2
hand2 =1else
hand1 =1
hand2 =2endif
ct =0for i =1to15 step 2
ct = ct +1
hand1(hand1, ct)= nCards(i)
hand1(hand2, ct)= nCards(i +1)
hand2(hand1, ct)=0
hand2(hand2, ct)=0next i
questCard = nCards(17)endsubsub NewDeal dealer, hGbox
xPos =50if dealer=1then
hand1 =2
hand2 =1
vis1 =0
vis1 =1' Preserve computer CardStatus 0 for actual play
vis2 =1
y1Pos =50
y2Pos =300else
hand1 =1
hand2 =2
vis1 =1
vis2 =0
vis2 =1' Preserve computer CardStatus to 0 for actual play
y1Pos =300
y2Pos =50endiffor i =1to8call Pause 250
nCard = hand1(hand1, i)call SetCardStatus nCard, vis1
call DealCard hGbox, nCard, xPos, y1Pos
call Pause 250
nCard = hand1(hand2, i)call SetCardStatus nCard, vis2
call DealCard hGbox, nCard, xPos, y2Pos
xPos = xPos +30next i
call Pause 500
nCard = nCards(17)' Reset Middle (Guess) CardStatus to 1 for actual play' call SetCardStatus nCard, 0Call DealCard hGbox, nCard,162,175endsubsub AnnounceDealer dealer
if dealer =1then
msg$ ="Your Deal"else
msg$ ="Computer Deals"endifconfirm msg$;yn$ ' Validates proper deal of cardsendsubsub AnnouncePlayer playerTurn
if playerTurn =1then
msg$ ="Your Turn"
y =420else
msg$ ="Computer's Turn"
y =40endif#main.g "stringwidth? msg$ width"#main.g "place ";int(200- width/2);" ";y
#main.g "\";msg$
endsubfunction GetCardSuit(nCard)calldll#qc,"GetCardSuit", _
nCard aslong, _
GetCardSuit aslong'returns 1=Clubs, 2=Diamonds, 3=Hearts, 4=Spadesendfunctionfunction GetCardValue(nCard)calldll#qc,"GetCardValue", _
nCard aslong, _
GetCardValue aslong'ace=1,deuce=2....jack=11,queen=12,king=13,joker=99endfunction
At this point, the only action is for the human to click a card, and the computer then reveals cards of the same value and same suit. Turn is never passed to the computer, so human can keep clicking away. All cards are face up. Eventually the computer's hand will be face down (with discards face up) and the middle (guess) card will be face down as well.
At this point, the only action is for the human to click a card, and the computer then reveals cards of the same value and same suit. Turn is never passed to the computer, so human can keep clicking away. All cards are face up. Eventually the computer's hand will be face down (with discards face up) and the middle (guess) card will be face down as well.