|
You can use a scheme to identify rank and suit by using div() on an range of integers from 0 to 51 (this is how the cards dll works - google for Cards.dll for tips on how a card can be represented) In this case you could wrap this up with a class with little more than an integer member and an overloaded member that would output the rank and suit.
Now then - what does a deck do? Well, it needs a number of cards, a way of shuffling them, and a way of doling one out - so, you might have a int GimmeACard() method, e.g.
A hand will need to RecieveACard(int) likewise.
The dealer (main.cpp) will need to:
have a deck to work with (for int GimmeACard() )
have hands to be dealt to (with ReceiveACard(int) )
Does this help? Note that the nice thing is that the details involved in the operations are hidden below the interfaces, leaving you with a nice little black box to work with. Take the case of the Deck class. It is free to worry about what type of randomization to use when the Shuffle() method is called. It takes care of knowing what cards are left in the deck after each one is doled out.
Your dealer can then just say:
// declare the object instances
Deck myDeck;
Hand myHand; // or make and array of pointers to hands and new 'em
// Shuffle the deck
myDeck.Shuffle(); // could take a seed parameter
// deal a card to a hand
myHand.RecieveACard(myDeck.GimmieACard());
Each .cpp file #includes its corresponding .h file.
Your main.cpp will #include the headers it needs, and when you instantate the objects they'll be ready for use. The linker will take care of tieing the files together - just make sure they're in the project.
Hope this helps - I'm just killing a little time here, having have had a bit of fun with this kind of thing in the past...
|
|
|
|
|
Hey Man thanks a million!!!!!!!!!!!!!!!!!!!!!!!
zackyD
|
|
|
|
|
Hey, I have a problem. A have a project in a computer science class and I am lost on how to organize all of these OOP files (header files, specification files) Anyways, if someone out there could somehow explain the main concepts behind OOP, that would be very helpful. If there is anyone out there that has a sample program to look at that would be great as well. I am really lost on this subject. Thanx.
ZackyD
|
|
|
|
|
Check out CodeProject code section for examples of object-oriented designs.
Kuphryn
|
|
|
|
|
where do i find the codeproject code section?
ZackyD
|
|
|
|
|
Think of an object as a person, place, or thing that represents what a system needs to know and do about an actual person, place, or thing. Think of an object in first-person form. Instead of saying "How can it do ____ to that object?", say "I am a ____. I know hot to ____ myself." instead. When you can look at an object in this fashion, the laying out of objects and the relationship(s) between objects becomes clearer. Something that I learned in undergraduate school was that of "strong cohesion, weak coupling." While it was not discussed in the context of OOP, it still applies.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi all, im sure this will be an easy question for some of you but i have failed to find an answer after searching through previous posts.
When i open a CFileDialog in my app the directory it starts in is different to the return value of GetCurrentDirectory() (and _getcwd). How do i get the directory that a CFileDialog would point to if i were to open it?
Cheers for any help,
Andy.
|
|
|
|
|
Does this help?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Cheers for the reply but no. I dont want to set the initial directory of the CFileDialog. I want to get the directory that a filedialog will point to if i were to use it. This directory may be different to the current working directory. MFC must be storing this somewhere in the registry based on the app name but i'll be buggered if i know where.
Cheers anyway.
Andy.
|
|
|
|
|
Have you looked at the documentation for the lpstrInitialDir member of the OPENFILENAME structure? I'm pretty sure that it details what Windows will use as the directory when one is (not) specified.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
One solution is CFileDialog's GetPathName() member function.
Kuphryn
|
|
|
|
|
Cheers for the reply.
I tried that but i dont want to have to store this value anywhere and i cant guarantee a file open dialog being used before displaying my folder open dialog (which is the thing i want to point to the same location).
Any other ideas?
|
|
|
|
|
Okay.
Your original question was not very clear. Do you want to get the full path of the file that a user had selected via CFileDialog? Do you want to set the directory where CFileDialog first starts out?
Kuphryn
|
|
|
|
|
I want to get the directory that a CFileDialog choses as its initial directory if the lpstrInitialDir of the OPENFILENAME structure is left empty.
There is an algorithm it uses to choose this directory (as explained in the OPENFILENAME documentation) but i want to be able to call a function (on something) to get me this directory without having to replicate this algorithm myself.
So i dont want to do either of what you suggested.
Cheers for your help.
Andy.
|
|
|
|
|
It is random. I have seen it initialize to the document directory. Other times it initializes to the system drive, C.
Kuphryn
|
|
|
|
|
I'm program a music program. How i can use winamp's visualization with my program. Where i can find some information? Thank you very much
Nothing
|
|
|
|
|
|
Can you tell me more exactly. thanks
Nothing
|
|
|
|
|
Are there products that contain gauge and dial widgets for use with Visual C++? I have use xDesigner (Linux) and the gauge, needle, scale, range widgets are handy to use.
|
|
|
|
|
There are a number of these libraries around for Windows. I think National Instruments is one company that does this. You will also find code here and on Codeguru for individual controls like guage etc. A Google search should help you find the main players in this space.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
I have this situation:
I have a CDialog and in it some ctrl's. I Enumerate all the ctrl's in it to let another window take over (a CTabCtrl derived class) the ctrl's for itself - working as a delegate for the "real" other window (called Wr here) - the dialog. This I do in order to let pages of the tab-ctrl work with the ctrl-sets to mimic that the dialog is embedded into the tab. So on tab shown I go SetWindowPos(...) on all the child's etc.
I use ::SetParent(hWndNewParent, hWndChild) for taking over the ownership - all works just fine!
Now my problem: How do I STILL let the messages from all kinds of ctrls go to the Wr (dialogs in this case and later on CView's)? Say I press a btn. on tab 0 - now the BN_CLICKED generated as a result of this press go to hWndNewParent (the CTabCtrl derived) and I want to route it to the Wr. This wish is because we already have all msg-handlers installed in lots of Wr's and would like to have'm stay their - otherwise it's mixed into a CTabCtrl derived and - well; no good!
My sugestion is still to catch "all interesting" messages on the new object and then go in the direction of (pseudo): pTabDlg->PostMessage(msg)...
So in other words my CTabCtrl derived class is a delegate only. Can I do that? I can use any help I can possible get – thanks in advance!
Regards,
Michael Mogensen, mm it-consult dk.
><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
|
|
|
|
|
Hi, I have a custom CTreeCtrl, the problem is that the HScrollbar is not more working correctly, because the rect of the item insert in the tree is different than the rect that i use paint. So i tried to implement my own HScrollfunction, i know the item length, and can set the Scrollbar with SetScrollInfo, that works perfectly i can also calculate the offset to scroll. I use the customdraw function to scroll the screen with setWindowOrg(xOffset,yOffset). As next i can catch nearly all mouse events and also set an offset, i have only one problem with the TVS_HASBUTTONS that is not working correctly (The offset i calculate has no influence), any idea why? Or is there another way to scroll, a custom treectrl? Is it not possible just to change the item length somehow? So the windows standard behavier of the treectrl would do the scrolling for me?
I would be happy for any help or ideas...
|
|
|
|
|
In VC,why I cannot open the project of CDex downloaded from "http://sourceforge.net/" ? Thank you first.
Rap off for you,for me,for our human.
|
|
|
|
|
maybe u have the wrong version of vc?
i can't open it either with .net 2002.
Don't try it, just do it!
|
|
|
|
|
I am using the VC6.0.
Is the reason the version???
If so,which version of VC can open it???
Rap off for you,for me,for our human.
|
|
|
|