Jump to content
  • Advertisement
Sign in to follow this  
vinb

Displaying hearts, clubs, spades, diamonds

This topic is 4847 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm building a console version of blackjack and I would like to display the suite as a symbol rather than a letter. I did some research and found that \u2660 is supposed to display the hearts symbol. But when I compile the code, I get a warning "unrecognized character escape sequence". I'm using C++. Any help would be greatly appreciated. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
ASCII code 3 is heart, 4 is diamond, 5 is clubs and 6 is spades.

To output them just use something like:

cout << char(4); //outputs diamond

or for strings:

cout << "\4"; //same

Share this post


Link to post
Share on other sites
The DOS console happens to map those characters to those symbols as well, but they're really not supposed to be printable characters.

As for \u2660, first of all, sequences starting with \u are Java-speak for Unicode characters (for C++ you'll need to specify the data in some other way, probably manually, byte-by-byte - which depends on which Unicode encoding you will be using), and there's extra work that has to be done to use Unicode anyway. Plus, the console won't display it anyway.

Trust me, it's not worth the effort. You will learn far, far more by getting the rest of your program to work, than trying to polish off one graphical detail. Later in your career you can look into doing things with various graphics APIs, which is about that point at which you can also sanely start to think about Unicode and other sorts of i18n issues.

Share this post


Link to post
Share on other sites
Quote:
Original post by vinb
I did some research and found that \u2660 is supposed to display the hearts symbol. But when I compile the code, I get a warning "unrecognized character escape sequence".

"\u" is not a valid escape sequence in C++, just like the error says. Where ever you got that code was not talking about C++. I'm guessing that it is Unicode and that it is represented in C++ as a wide character with the value 0x2660. I don't use Unicode, but my guess is that in string form it looks like "\x60\x26" or maybe "\x2660"L.
Quote:
Original post by Scet
ASCII code 3 is heart, 4 is diamond, 5 is clubs and 6 is spades

This is not standard and it depends on the font.
Quote:
Original post by Zahlman
Trust me, it's not worth the effort...

I agree. Just use H, S, C, D for now. In my chess program, rather than spending time making it look pretty, I use K, Q, B, K, R, and P for the pieces.

Share this post


Link to post
Share on other sites
By the way, I will definitely spend more time on the design, as it is greatly lacking. The graphics (if you can call it that) was just something that was bugging me and seemed like it should be a lot easier that it was.

Thanks again.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!