views:

225

answers:

4

All,

I have been asked to build a solitaire game in C++ for my project.

Here's what I have come up with: Card class Properties/members: Suit,Rank,Color(All of these can be enums) Actions/Functions: Flip card, compare card, print card Rules Class: Would contain the rules of the game and also validate each user action/command to check if it is allowed. Commands Class: I am thinking this need not necessarily be a class. Could be an enum as well. A base class CardPile. Have more classes derived from CardPile such as DealPile, Temporary Pile, DestinationPile, TablePile. What I am not clear about is the relationships between classes.

PS: This is not a homework. This is a project.

Thanks in advance!

+2  A: 

You need a representation of a card which will hold the card's value and suit.

You will also need a data structure to represent a "stack" of cards.

From there, building the GUI shouldn't be that challenging. This is a very easy project, and you seem to have the right idea.

dhorn
Yes, I hadnt thought about having a data stucture to represent the stack of cards. I was thinking in terms of different kinds of decks/piles. But may be I could have a separte datastructure and use it in the decks/piles. Thank you
AgentHunt
A: 

Use google: http://www.koders.com/cpp/fidF5707F3628C8FBF461AECF64B1F58E53119FCB8D.aspx?s=windows.h

Just google Solitaire in C++

JonH
A: 

Consider, instead of doing a bunch of up-front design, focusing on creating things that work. What will your program need to do?

It'll need to shuffle, so design a way to represent 52 cards and shuffle them. It's pretty easy to implement, but it's a good starting point.

Then you'll need to lay out the cards. So come up with a way to lay out the cards and put the rest in the draw pile.

And so forth. Instead of analyzing objects, focus on behaviors. Create objects only as needed in order to support the behaviors of your program. That will help you avoid getting lost in the analysis and excess code and ensure that you have a program that actually does some useful things.

(What if you need to turn in your design before doing anything? Not a problem; do your thinking the way I've described above. The implementation will be left for later, but even just thinking out how routines like the above will work will be more valuable than designing a bunch of objects without knowing what you'll do with them.)

Kyralessa
+1  A: 

Not an answer to your question but an attempt to help you out in the future. Software developers don't like it when people aren't willing to do the 'due dilligence' before asking questions. It is all well and good to be lazy if it leads you to design something that saves you or others time in the future. But one of the greatest mistakes a new developer can make is asking others for help (because it is quicker and easier) and never learning how to do it themselves. I have seen a few developers in my time get fired for not having the confidence to try to solve problems on their own first, before asking for help.

Good Luck with your project!

Jeremy E
I realize that. May be its just the way I framed my question.I should have given more details of what I was thinking.
AgentHunt