In the previous demo we allowed the user to right-click on a card and drag it around. When the user released the button the card was dropped in a new position. We paid no attention to the card's status or to the location it was dropped. In a real game we'd need to monitor all such activity.
Blocked Cards
QCard has two functions to set and query the blocked status of a card. A card can be marked as blocked if it is covered or partially covered by another card. QCard lets us set the "blocked" status with AdjustCardBlocked. We can query the "blocked" status of a card with GetCardBlocked. The API calls look like this:
calldll#qc,"AdjustCardBlocked",_
nC aslong,_ 'index of card to block/unblock
bValue aslong,_ '1=blocked, 0=unblocked
re asvoid'no returncalldll#qc,"GetCardBlocked",_
nC aslong,_ 'index of card to query
isBlocked aslong'1=blocked, 0=unblocked
Blocking Some Cards
In our demo, we'll change the display so that the rows of cards overlap. Each row is 20 pixels below the previous row. When we deal the first three rows we'll also set the "blocked" status of each card in that row to "blocked". We will leave the cards in the fourth row with the default "unblocked" status. We've introduced a variable called "row" to keep track of the row being dealt.
x=10:y=2:row=1for i =1to24Call DealCard hBox,card(i),x,y
'When creating a row or pile of cards,'only the topmost card should have an'IsBlocked value of FALSE.if row<4thencall AdjustCardBlocked card(i),1
x=x+100if x>510then'move to next row
x=10
y=y+offset
row=row+1endifplaywave"card.wav",sync
'pause 100 milliseconds between cardscall Pause 100scannext
Aborting the Dragging Operation
QCard DLL captures mouse events from the time InitDrag is called until EndDrag is called. If for any reason we need to abort the dragging procedure, we must call AbortDrag so that the DLL releases the capture of mouse events.
calldll#qc,"AbortDrag", re asvoid
Preventing the Drag of Blocked Cards
When the user right-clicks the mouse we'll use InitDrag to discover which card in our card array was clicked. InitDrag returns the index of the card at the given x,y location. We then query its blocked status.
If the card is blocked we document that at the bottom of the display and halt the routine with AbortDrag. If it is not blocked, we begin the dragging procedure, as we did in the last lesson.
[initDrag]
cardIndex=InitDrag(hBox,MouseX,MouseY)
isBlocked=GetCardBlocked(cardIndex)'see if card is blockedif isBlocked<>0then'if card is blocked, inform user and abort drag operationcall AbortDrag
#1.g "place 10 420;\BLOCKED Card Index is ";cardIndex;space$(100)waitendif#1.g "place 10 420;\Drag Card Index is ";cardIndex;space$(100)#1.g "when rightButtonMove [doDrag]"wait
In a real game you'd want to set the blocked status of the newly uncovered card to 0. You'd also need to set the card that was just covered by the dragged card to "blocked". We did not complicate the code with these routines in order to keep the demo program short and understandable.
Offset Value
QCard has a default offset value of 16 pixels. The cards are 70x95 pixels and if one card is displayed 16 pixels lower thena the card beneath both card values will be visible. This offset is important to the DLL when it discovers which card is at MouseX and MouseY.
We can change the offset with SetOffSet. We change the offset to 20 pixels for this demo.
calldll#qc,"SetOffSet",_ 'change pixel offset for vertical colums of cards
offset aslong,_ 'number of pixels to offset
re asvoid
DEMO
See Lesson 1 for QCard DLL and WAV files needed for the demo code.
The demo deals the cards in four overlapped rows. It sets the blocked status of cards in the first three rows. It checks the blocked status of the card clicked by the user. It allows the user to drag the card if the designated card status is "unblocked". We've eliminated the shuffling routine to keep things simple for this demo.
'An open project card game, begun by Alyce Watson, May 27, 2003.'Uses Qcard32.dll, a freeware library of playing card images.'DLL by Stephen Murphy. Qcard32.DLL website:'http://www.telusplanet.net/public/stevem/dim card(24)'array to hold cardsgosub[fillCardArray]'fill array with card values[varSetup]
i=0'i will be our counter var in for/next loops
offset=20'offset for card vertical spacing for dragging purposesnomainwinWindowWidth=640:WindowHeight=480UpperLeftX=1:UpperLeftY=1menu#1,"&File","&New",[new],"E&xit",[quit]graphicbox#1.g,0,0,640,440open"Dragging Cards"for window_nf as#1#1"trapclose [quit]"'get graphicbox handle
hBox=hwnd(#1.g)'open the dllopen"qcard32.dll"fordllas#qc
'initialize the deckCall InitializeDeck hBox
[new]Call SetDefaultValues
'draw a nice background#1.g "down; fill 10 190 225"#1.g "backcolor 10 190 225"'temp message for this demo only#1.g "place 10 420"#1.g "\Right-click on a card, then move mouse to drag and drop it."
offset=20call SetOffSet offset 'set offset to 20 pixels - default is 16'set xy location to start deal
x=10:y=2:row=1for i =1to24Call DealCard hBox,card(i),x,y
'When creating a row or pile of cards,'only the topmost card should have an'IsBlocked value of FALSE.if row<4thencall AdjustCardBlocked card(i),1
x=x+100if x>510then'move to next row
x=10
y=y+offset
row=row+1endifplaywave"card.wav",sync
'pause 100 milliseconds between cardscall Pause 100scannext#1.g "when rightButtonDown [initDrag]"wait[initDrag]
cardIndex=InitDrag(hBox,MouseX,MouseY)
isBlocked=GetCardBlocked(cardIndex)'see if card is blockedif isBlocked<>0then'if card is blocked, inform user and abort drag operationcall AbortDrag
#1.g "place 10 420;\BLOCKED Card Index is ";cardIndex;space$(100)waitendif#1.g "place 10 420;\Drag Card Index is ";cardIndex;space$(100)#1.g "when rightButtonMove [doDrag]"wait[doDrag]call DoDrag hBox,MouseX,MouseY#1.g "when rightButtonUp [endDrag]"wait[endDrag]#1.g "when rightButtonUp"
cardIndex=EndDrag(hBox,MouseX,MouseY)#1.g "place 10 420;\Destination Card Index is ";cardIndex;space$(100)wait[fillCardArray]'fill card array'cards 1 to 52 are in the first deck'cards 53 to 104 are in the second deck'use cards Jack through King in each suit, first deck
card(1)=11'jack of clubs
card(2)=12'queen
card(3)=13'king
card(4)=24'jack of diamonds
card(5)=25'queen
card(6)=26'king
card(7)=37'jack of hearts
card(8)=38'queen
card(9)=39'king
card(10)=50'jack of spades
card(11)=51'queen
card(12)=52'king'now use second deck, to fill second half of arrayfor i =1to12
card(i+12)=card(i)+52nextRETURN[quit]close#qc:close#1:end'''''''''''''''''''''subs and functions:Sub Pause ms
'pause ms number of millisecondscalldll#kernel32,"Sleep",_
ms aslong, re asvoidEndSubSub SetOffSet offset
calldll#qc,"SetOffSet",offset aslong,_
re asvoidendsubSub AdjustCardBlocked nC, bValue
calldll#qc,"AdjustCardBlocked",_
nC aslong, bValue aslong, re asvoidendsubFunction GetCardBlocked(nC)calldll#qc,"GetCardBlocked",nC aslong,_
GetCardBlocked aslongendfunctionFunction InitDrag(hndle, x, y)calldll#qc,"InitDrag",_
hndle asulong, x aslong, y aslong,_
InitDrag aslongendfunctionSub AbortDrag
calldll#qc,"AbortDrag",re asvoidendsubSub DoDrag hndle,x,y
calldll#qc,"DoDrag",hndle asulong,_
x aslong, y aslong, r asvoidendsubFunction EndDrag(hndle,x,y)calldll#qc,"EndDrag",hndle asulong,_
x aslong, y aslong, EndDrag aslongendfunctionSub InitializeDeck hndle
calldll#qc,"InitializeDeck",_
hndle asulong,r aslongEndSubSub DealCard hndle,nC,x,y
'places card on window whose handle is hndle at x,y'nC is number of card - 1-52 in first deck and'53-104 in second deck, if usedcalldll#qc,"DealCard",hndle asulong,nC aslong,_
x aslong,y aslong,r asvoidEndSubSub SetDefaultValues
'reset all card properties back to their default values.calldll#qc,"SetDefaultValues",r asvoidEndSub
QCard DLL Lesson 10
Lesson 9 Lesson 11-
QCard DLL Lesson 10 | More on Card Dragging | Blocked Cards | Blocking Some Cards | Aborting the Dragging Operation | Preventing the Drag of Blocked Cards | Offset Value | DEMO
See Lesson 1 for QCard DLL and WAV files needed for the demo code.
More on Card Dragging
In the previous demo we allowed the user to right-click on a card and drag it around. When the user released the button the card was dropped in a new position. We paid no attention to the card's status or to the location it was dropped. In a real game we'd need to monitor all such activity.
Blocked Cards
QCard has two functions to set and query the blocked status of a card. A card can be marked as blocked if it is covered or partially covered by another card. QCard lets us set the "blocked" status with AdjustCardBlocked. We can query the "blocked" status of a card with GetCardBlocked. The API calls look like this:
Blocking Some Cards
In our demo, we'll change the display so that the rows of cards overlap. Each row is 20 pixels below the previous row. When we deal the first three rows we'll also set the "blocked" status of each card in that row to "blocked". We will leave the cards in the fourth row with the default "unblocked" status. We've introduced a variable called "row" to keep track of the row being dealt.
Aborting the Dragging Operation
QCard DLL captures mouse events from the time InitDrag is called until EndDrag is called. If for any reason we need to abort the dragging procedure, we must call AbortDrag so that the DLL releases the capture of mouse events.
Preventing the Drag of Blocked Cards
When the user right-clicks the mouse we'll use InitDrag to discover which card in our card array was clicked. InitDrag returns the index of the card at the given x,y location. We then query its blocked status.
If the card is blocked we document that at the bottom of the display and halt the routine with AbortDrag. If it is not blocked, we begin the dragging procedure, as we did in the last lesson.
In a real game you'd want to set the blocked status of the newly uncovered card to 0. You'd also need to set the card that was just covered by the dragged card to "blocked". We did not complicate the code with these routines in order to keep the demo program short and understandable.
Offset Value
QCard has a default offset value of 16 pixels. The cards are 70x95 pixels and if one card is displayed 16 pixels lower thena the card beneath both card values will be visible. This offset is important to the DLL when it discovers which card is at MouseX and MouseY.
We can change the offset with SetOffSet. We change the offset to 20 pixels for this demo.
DEMO
See Lesson 1 for QCard DLL and WAV files needed for the demo code.The demo deals the cards in four overlapped rows. It sets the blocked status of cards in the first three rows. It checks the blocked status of the card clicked by the user. It allows the user to drag the card if the designated card status is "unblocked". We've eliminated the shuffling routine to keep things simple for this demo.
QCard DLL Lesson 10 | More on Card Dragging | Blocked Cards | Blocking Some Cards | Aborting the Dragging Operation | Preventing the Drag of Blocked Cards | Offset Value | DEMO
Lesson 9 Lesson 11