473,320 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Writing Hears card game in C#

Hi,

I am trying to write a version of the Hears card game. I can't figue
out what is the best way to detect clicks on the cards. Using the
cards.dll interface as described in tutorials like
http://www.publicjoe.f9.co.uk/csharp/card00.html . Can anyone give me
suggestions how to detect which card is clicked and how to redraw it
at the center of the sceen. For now all i know is that I have to
detect the X and Y coordinates of the mouse. But then what, I have to
go through the location of each card to get which one is actually
clicked. That seems kinda tedious since in the beginning of the game a
card in the middle is only slighly exposed, then when a card nex to it
is played, the area of the card gets bigger. How should I keep track
of that. Is it better to make some object like a button that actually
displays cards ( I still want to keep the same look as the WIndows
Hearts). Please help me since I am a total newbie at C#. Any
suggestions ( and sample code ) would be deeply appreciated

Thank you in advance

Apr 9 '07 #1
1 4557
On Sun, 08 Apr 2007 19:02:10 -0700, Olmar <ol*******@gmail.comwrote:
[...] Can anyone give me
suggestions how to detect which card is clicked and how to redraw it
at the center of the sceen. For now all i know is that I have to
detect the X and Y coordinates of the mouse. But then what, I have to
go through the location of each card to get which one is actually
clicked. That seems kinda tedious since in the beginning of the game a
card in the middle is only slighly exposed, then when a card nex to it
is played, the area of the card gets bigger. How should I keep track
of that.
Short of making each card its own control and letting .NET (Windows) do
the hit-testing for you, then you pretty much do have to go through the
location of each card until you get one that matches.

As far as overlap goes, you're talking about a basic z-order issue. All
you have to do to address that is make sure that you hit-test from top to
bottom. You won't have to worry about exactly what portion of the card is
exposed that way...if you're clicking within an area of a card that is
obscured by a card on top, that obscuring card will test positive for the
hit before you get to the one being covered up. You stop testing on the
first card that tests positive for a hit.

For example, let's assume you've got an array of stacks of cards and each
stack of card is an array of cards. Let's also assume that you maintain
each stack array in top to bottom order (that is, the first card in the
array is the card at the top of the stack). Let's also assume that the
card data structure has a rectangle property that exposes the boundary
within which the card is considered to be clicked on. Finally, let's
assume that each stack is entirely independent of every other stack (that
is, the only overlap is within a card). Then you get something like this:

public Card CardHitTest(Card[][] stacks, Point ptClick)
{
foreach (Card cardCur in stacks)
{
if (cardCur.rectangleBounds.Contains(ptClick))
{
return cardCur;
}
}

return null;
}

I'm not familiar with the game you mention, but you should be able to
adapt the above idea to suit your needs. The key is to maintain some kind
of ordered collection of cards, and have the order be according to how the
cards lay on top of each other, with the top-most card being the first
card in the collection.

As far as redrawing goes, if you can implement the code to draw the cards
in the first place, then all you have to do is maintain your card data so
that you know where each card should be drawn, update that information
when the position of a card changes, and then invalidate the areas that
need to be redrawn so that they do get redrawn (that is, for each card
that moves, invalidate the rectangles describing the old boundary of the
card and the new boundary of the card). The redrawing part is pretty
simple.

Pete
Apr 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sam | last post by:
Hey all, I want to create a computerised version of this game, though I'm not really sure how to go about it. For those who don't know how the game works, here's my attempt at a brief...
1
by: Gary Camblin | last post by:
Has anyone got a script to run a higher or lower card game on a web page. Like the game show play you cards right.
7
by: Ken Smith | last post by:
I have a little video poker game I created in Javascript. It uses Tables and inner html stuff - for example: (psudo-code) imagePicked=random card image (2h.gif);...
4
by: Bern | last post by:
This is the first time I'm writing a network multiplayer card game. And the model I have thought of : The host creates a new thread and this thread listens for clients. When a client is...
0
by: Limpor | last post by:
Hello, I am new to learning java, and i am trying to build the class for a calculation card game, unfortunately i can't get the public Card top() and Card takeTop() method in the Stock class. Can...
0
by: Paul | last post by:
Greetings: I have been trying to find source code for a Baccarat card game (C++ or Basic, but preferably the former). My reason for this is wanting to experiment with possible Baccarat card...
6
by: hicksmcb | last post by:
Hi i'm having some trouble with a card memory game. Typical type. You turn over one card then another, if they dont match you turn them both back over and start again. I've got this 'if else'...
1
by: Geoff | last post by:
Hi all, I've been making a card game in VB and am trying to get it work over a network. I think I've got all the card game pretty much planned out ready to make it, but need to find a way to get 2...
3
by: Fiona1200 | last post by:
Please help me..i have to write a code in java for a card game as follows. there are 4 players each with 4 decks of cards. each deck has four zeros - four seven as follows...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.