Jump to content

Simple C++ Card Game


Recommended Posts

Hello! I don't spend a lot of time on these forums, but I think I might in the future. :)

 

I'm currently a second year university student. In my first year we learned C++, but we only touched on Object Oriented Programming. So I'm trying to teach it to myself while I have some downtime between summer classes! I've managed to make a simple program that builds cards, then spits the cards out to stdout. What I'd like from you guys is a suggestion of a simple one-player card game I might be able to make!

 

Right now I'm running everything through Command Prompt (Windows system :P) and that's where all my output goes, so all my output is of course text based. I've been curious if there's another place I can direct output that isn't strictly text? Even if there is, it's likely too complicated for me to try yet, but I would still like to know about it. :)

 

EDIT: Another question that's not entirely important right now, but may be in the future: I don't seem to have the stdint.h or cstdint libraries on my laptop. Is there a way I can check? And if they aren't there, is there a way I can get them? If it helps I'm running Windows 7 Home Premium!

Blakdragon39.png
Link to comment
Share on other sites

Any solitaire game should be pretty easy to reproduce, just google it up.

 

I'd download visual C++ from microsoft, if you have msdn student access it's free.

 

I assume you only had one C++ class, an introductory one? Otherwise they should have taught you gui :?

polvCwJ.gif
"It's not a rest for me, it's a rest for the weights." - Dom Mazzetti

Link to comment
Share on other sites

^ I don't know what kind of programming education or experience you have, (i.e. you might know more than me) but I am guessing that GUI programming is taught more with Java than with C++.

What's kind of strange to me is that they would teach C++ without teaching OOP. IMO if you're just going to teach procedural programming with a lower-level language you should just learn C, and learn OOP later with C++/Java.

 

About the actual question, you could make a go fish program against the computer. :P Really simple game, there's not much AI to write.

C2b6gs7.png

Link to comment
Share on other sites

I'm the the same focus isn't there, but they should at least be teaching it. It's far past the days where command line is all you're going to be using in an application.

polvCwJ.gif
"It's not a rest for me, it's a rest for the weights." - Dom Mazzetti

Link to comment
Share on other sites

I don't know, I just finished a programming course at college and we did most of that time with C++ being one of the classes. The introductory one was just procedural C++, and that's what we did for the first year, then OOP for the second year. They never told us C++ with GUI but we did it with Java though.

Link to comment
Share on other sites

Well it makes sense to do procedural first, then OOP - which is what I did as well (with Java though).

 

I've never taken any C++ courses but it seems to me they should at least touch on gui.

polvCwJ.gif
"It's not a rest for me, it's a rest for the weights." - Dom Mazzetti

Link to comment
Share on other sites

A "procedural fragment" of C++ is what we've been using. I had two classes, one was a very introductory class (loops, if-else, the absolute basics), and then the next semester was more about structures (trees, linked lists, hash tables). I've heard we're going to do Java in one of my second year classes in September.

 

A Go Fish game doesn't sound too bad. :D Right now I'm trying to figure out how to make a deck.. I'm trying to make it it's own object, but I'm having issues just using it right now. :P

Blakdragon39.png
Link to comment
Share on other sites

That sounds a lot simpler than the go fish game, I certainly might try doing that first! I quit working at this for a few days because my classes have started up again. When I have free time I'll keep working on it though. I'm having trouble using the functions, and making them work sometimes. You can't just call the function, you have to call it FROM an object... like

 

deck.Shuffle();

 

right? And if you want to shuffle THAT deck, depending on how you deal with the function, you would have to go:

 

deck = deck.Shuffle();

OR

deck.Shuffle(deck);

 

Is that right?

Blakdragon39.png
Link to comment
Share on other sites

To me using a specific object to modify another specific object seems like bad design, it throws away the polymorphism you have available. Do one of these two things:

  1. Create an object for initializing decks (Creating them, shuffling them) and keep decks as a separate object, or
  2. Integrate the functions needed into your class, so that it can process itself in the style of deck.shuffle(), deck.deal() or whatever.

Option two is better for you as it's pretty unnecessary to use a factory method pattern for such a small program.

C2b6gs7.png

Link to comment
Share on other sites

In the second option, do you mean have just one object/structure? Or do are you talking about the way I'm calling the function? I haven't found a terribly decent tutorial anywhere that goes through basics such as.. how to CALL the functions. xD

Blakdragon39.png
Link to comment
Share on other sites

Yeah just one object per deck, that contains a property with all the cards in it, and has methods like shuffle() and anything else you might need (Possibly a function that deals) that processes itself.

C2b6gs7.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.