The Design and Implementation of the QT class in wuziqi game in Huaqing vision learning Manual (3)

Source: Internet
Author: User

Design and Implementation of Network wuziqi game QT class (3)

 

The second version of the Five-play game is indeed much better than the first version. However, the more I see it, the less decent it is, especially the pawns! 'W' indicates white games, and 'B' indicates black games. If you have learned English, you can easily tell them. But what if I don't even know ABC? You must find a way to make the pawns more beautiful.

I thought of graphical characters. Can I see the round characters on 'T' and 'y? It is very suitable for wuziqi.

The key is how to find and display this graphic character, directly enter it, in Ubuntu is supported UTF-8 encoding, and in Windows ultraedit/notepad although can enter '● ', but when saving it as a UTF-8, the inner code is "FF Fe CF 25"

, Save Unicode
The Code obtained is the same, which indicates that the UTF-8 code is not implemented in my current window. Find a conversion tool to use, looking for a long time but no return, then the first UFT-8 code understand, manually to switch it! UTF-8 is one of Unicode implementations, it specifies how characters are stored and transmitted in a computer, it is a variable length encoding method. UTF-8 Rules 1: for a single byte, the first byte is set to 0, the last 7 is Unicode code, so in English letters, the UTF-8 code and ASCII code is the same. UTF-8 Rule 2: For n Bytes (n> 1), the first n Bytes are set to 1, the n + 1 is set to 0, all subsequent bytes start with 10, and the remaining bits belong to the Unicode code. For '● Unicode codes "FF Fe CF 25 ",

"Ff fe"
Yes
Size
End mode, which indicates the small end. All actual codes are 0x25cf. Converted to binary: 0010
0101 11
001111
According to UTF-8 rules, the conversion is 1110
0010
10
010111
10
001111,
That is, the hexadecimal 0xe2978f, similarly, the '○' UTF-8 code is




0xe2978b.


Add the UTF-8 encoding of the pawns to the display function:



Void chessboard: dispchessboard ()
{

Const char white [] = {0xe2, 0x97, 0x8b, 0}; // ○
UTF-8 code for displaying white games

Const char black [] = {0xe2, 0x97, 0x8f, 0}; // ●








Used
Show the UTF-8 code of the black game








Cout <"";





For (Int J = 0; j <19; j ++)
{
Printf ("% 02d", J );
}
Cout <Endl;

For (INT I = 0; I <19; I ++)
{
Printf ("% 02d", I );
For (Int J = 0; j <19; j ++)
{
If (j = 0)
{
If (Board [I] [J] = 'W ')
Printf ("% 2 s", white );
Else if (Board [I] [J] = 'B ')
Printf ("% 2 s", black );
Else
Printf ("% 2C", Board [I] [J]);
}

// Printf ("% 2C", Board [I] [J]);

Else {
If (Board [I] [J] = 'W ')
Printf ("-% 2 s", white );
Else if (Board [I] [J] = 'B ')
Printf ("-% 2 s", black );
Else
Printf ("-% 2C", Board [I] [J]);
}
// Printf ("-% 2C", Board [I] [J]);
}
Printf ("% 02d", I );
Cout <Endl;
Cout <"";
For (Int J = 0; j <19; j ++)
{
If (I! = 18)
Printf ("| ");
}
Cout <Endl;
}
Cout <"";
For (Int J = 0; j <19; j ++)
{
Printf ("% 02d", J );
}
Cout <Endl;
}





Let's take a look at my third version of the Five-play game after UTF-8 improvement:



 




 




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.