Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to develop Chess Program based on C++ and MFC

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to develop chess programs based on C++ and MFC. It is very detailed and has a certain reference value. Interested friends must finish reading it.

First, chessboard analysis

This is the chessboard I drew. The chessboard consists of 9 vertical lines and 10 horizontal lines. Here we set the interval between each line to be 50.

Second, the drawing process

1. Create a new MFC program in vs to remove the buttons and text automatically generated by the environment.

2. Open the * Dlg.cpp file, define a chessboard interval value in void CChessDlg::OnPaint () and the drawing device CDC * cd = CWnd::GetDC ()

Int nWid = 50 China CDC * cd = CWnd::GetDC ()

3. Draw the horizontal line of the chessboard

/ / draw a dash for (int I = 1; I

< 11; ++i){ cd->

MoveTo (nWid, I * nWid); cd- > LineTo (9 * nWid, I * nWid);}

4. Draw the vertical line of the chessboard

/ / draw a vertical bar for (int I = 1; I

< 10; ++i){  //绘制棋盘两侧线段 if(1 == i || 9 == i) { cd->

MoveTo (I * nWid, nWid); cd- > LineTo (I * nWid,10 * nWid);} else// draws vertical lines in the middle of the chessboard {cd- > MoveTo (I * nWid, nWid); cd- > LineTo (I * nWid,5 * nWid); cd- > MoveTo (I * nWid,6 * nWid); cd- > LineTo (I * nWid,10 * nWid);}}

5. Draw Nine Palace grids

/ / painting Nine Miyagi CD-> MoveTo (4 * nWid, nWid); cd- > LineTo (6 * nWid,3 * nWid); cd- > MoveTo (6 * nWid, nWid); cd- > LineTo (4 * nWid,3 * nWid); cd- > MoveTo (4 * nWid, 8 * nWid); cd- > LineTo (6 * nWid,10 * nWid); cd- > MoveTo (6 * nWid, 8 * nWid); cd- > LineTo (4 * nWid,10 * nWid)

At this point, our chessboard is drawn. Here is the complete code.

CDialogEx::OnPaint (); int nWid = 50; CDC * cd = CWnd::GetDC (); / / dash for (int I = 1; I

< 11; ++i) { cd->

MoveTo (nWid, I * nWid); cd- > LineTo (9 * nWid, I * nWid);} / / draw vertical bar for (int I = 1; I

< 10; ++i) { if(1 == i || 9 == i) { cd->

MoveTo (I * nWid, nWid); cd- > LineTo (I * nWid,10 * nWid);} else {cd- > MoveTo (I * nWid, nWid); cd- > LineTo (I * nWid,5 * nWid); cd- > MoveTo (I * nWid,6 * nWid); cd- > LineTo (I * nWid,10 * nWid);}} / / draw Jiugong cd- > MoveTo (4 * nWid, nWid); cd- > LineTo (6 * nWid,3 * nWid) Cd- > MoveTo (6 * nWid, nWid); cd- > LineTo (4 * nWid,3 * nWid); cd- > MoveTo (4 * nWid, 8 * nWid); cd- > LineTo (6 * nWid,10 * nWid); cd- > MoveTo (6 * nWid, 8 * nWid); cd- > LineTo (4 * nWid,10 * nWid); these are all the contents of the article "how to develop Chess programs based on C++ and MFC". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 248

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report