资源描述:
《精!!!C语言实现国际棋盘》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C语言实现国际象棋盘的输出,不用画图头文件,不用Tutor2.0,不用输出扩展的ASCI码,总之,一般的编译器都可以#include #include void ConPrint(char *CharBuffer, int len);void ConPrintAt(int x, int y, char *CharBuffer, int len);void gotoXY(int x, int y);void ClearConsole(void);void ClearConsoleToColors(int F
2、orgC, int BackC);void SetColorAndBackground(int ForgC, int BackC);void SetColor(int ForgC);void HideTheCursor(void);void ShowTheCursor(void);int main(int argc, char* argv[]){ int i=0,j=0; HideTheCursor(); ClearConsoleToColors(15, 2); for(i=0;i<8;i++) for(j=0;j<8;j++){
3、if(i%2==0) {if(j%2==0) {SetColorAndBackground(15, 15); ConPrintAt(i,j," ", 1);} else {SetColorAndBackground(1, 16); ConPrintAt(i,j, " ", 1);}//红色为重点 } else {if(j%2!=0) {SetColorAndBackground(15, 15); ConPrintAt(i,j," ", 1);} else {SetColorAnd
4、Background(1, 16); ConPrintAt(i,j, " ", 1);}}} SetColorAndBackground(7, 1); return 0;}void ClearConsoleToColors(int ForgC, int BackC){ WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F); HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); COORD coord = {0, 0};
5、 DWORD count; CONSOLE_SCREEN_BUFFER_INFO csbi; SetConsoleTextAttribute(hStdOut, wColor); if(GetConsoleScreenBufferInfo(hStdOut, &csbi)) { FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count); FillConsoleOutputAtt
6、ribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count); SetConsoleCursorPosition(hStdOut, coord); }} void ClearConsole(){ HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); COORD coord = {0, 0}; DWORD count; CONSOLE_SCREEN_BUFFER_INFO c
7、sbi; if(GetConsoleScreenBufferInfo(hStdOut, &csbi)) { FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count); FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count); SetCon
8、soleCursorPosition(hStdOut, coord); }}void gotoXY(int x, int y){ COORD