您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > c++做的象棋源代码
//¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«£ü//àË£¡ÎÒÊÇÍõÏþîÚ¡£//ÎÒµÄE-mailÊÇ£ºXiaoYu.wang@263.netÓÐÎÊÌâ¿ÉÒÔ·¢Óʼþ»òÔÚÍøÕ¾ÉÏÁôÑÔ//»¶ÓÄã·ÃÎÊÎҵĸöÈËÖ÷Ò³£º¡°Ð¦ÓïС԰¡±¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«£ü//¶þ¡ð¡ð¡ðÄêÆßÔÂ//ÈÃÎÒÃǼÌÐø¿´ÎҵijÌÐò¡£//ÕâÊǿα¾ÉϵÄÀý×Ó¡£//¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«¡«£ü//¿É¹©Á½È˶ÔÞĵÄÖйúÏóÆå³ÌÐò#includeafxwin.h//ÆåÅÌÀàclassCPlate{intm_ndx;//ÆåÅ̸ñ¿íintm_ndy;//ÆåÅ̸ñ¸ßintm_nLeft;//ÆåÅÌλÖÃintm_nTop;intm_nRight;intm_nBottom;public:CPlate();voidShowPlate(CDC*pDC);voidDrawConer(CDC*pDC,introw,intcol,inttype);CPointGetPosition(intcol,introw);};//ÆåÅÌÀàµÄ³ÉÔ±º¯Êý//¹¹Ô캯Êý:³õʼ»¯CPlate::CPlate(){m_ndx=50;m_ndy=45;m_nLeft=198;m_nTop=30;m_nRight=m_nLeft+m_ndx*8;m_nBottom=m_nTop+m_ndy*9;}//ÏÔʾÆåÅÌvoidCPlate::ShowPlate(CDC*pDC){//»ÆåÅÌ·½¸ñCPenpenRed2(PS_SOLID,2,RGB(255,0,0));CPen*pOldPen=pDC-SelectObject(&penRed2);for(inti=0;i10;i++){pDC-MoveTo(m_nLeft,m_nTop+i*m_ndy);pDC-LineTo(m_nRight,m_nTop+i*m_ndy);}for(i=0;i9;i++){if(i==0||i==8){pDC-MoveTo(m_nLeft+i*m_ndx,m_nTop);pDC-LineTo(m_nLeft+i*m_ndx,m_nBottom);}else{pDC-MoveTo(m_nLeft+i*m_ndx,m_nTop);pDC-LineTo(m_nLeft+i*m_ndx,m_nTop+4*m_ndy);pDC-MoveTo(m_nLeft+i*m_ndx,m_nTop+5*m_ndy);pDC-LineTo(m_nLeft+i*m_ndx,m_nBottom);}}//»ÆåÅÌбÏßpDC-SelectObject(pOldPen);CPenpenRed1(PS_SOLID,1,RGB(255,0,0));pOldPen=pDC-SelectObject(&penRed1);pDC-MoveTo(m_nLeft+3*m_ndx,m_nTop);pDC-LineTo(m_nLeft+5*m_ndx,m_nTop+2*m_ndy);pDC-MoveTo(m_nLeft+3*m_ndx,m_nTop+2*m_ndy);pDC-LineTo(m_nLeft+5*m_ndx,m_nTop);pDC-MoveTo(m_nLeft+3*m_ndx,m_nBottom);pDC-LineTo(m_nLeft+5*m_ndx,m_nBottom-2*m_ndy);pDC-MoveTo(m_nLeft+3*m_ndx,m_nBottom-2*m_ndy);pDC-LineTo(m_nLeft+5*m_ndx,m_nBottom);pDC-SelectObject(pOldPen);//»±ø,ÅÚλ±ê¼ÇDrawConer(pDC,2,1,0);DrawConer(pDC,2,7,0);DrawConer(pDC,3,0,1);DrawConer(pDC,3,2,0);DrawConer(pDC,3,4,0);DrawConer(pDC,3,6,0);DrawConer(pDC,3,8,2);DrawConer(pDC,7,1,0);DrawConer(pDC,7,7,0);DrawConer(pDC,6,0,1);DrawConer(pDC,6,2,0);DrawConer(pDC,6,4,0);DrawConer(pDC,6,6,0);DrawConer(pDC,6,8,2);}//»æÖƱø,ÅÚλ±êÖ¾voidCPlate::DrawConer(CDC*pDC,introw,intcol,inttype){CPenpenRed1(PS_SOLID,1,RGB(255,0,0));CPen*pOldPen=pDC-SelectObject(&penRed1);if(type==0||type==1){pDC-MoveTo(m_nLeft+col*m_ndx+3,m_nTop+row*m_ndy-10);pDC-LineTo(m_nLeft+col*m_ndx+3,m_nTop+row*m_ndy-3);pDC-LineTo(m_nLeft+col*m_ndx+10,m_nTop+row*m_ndy-3);pDC-MoveTo(m_nLeft+col*m_ndx+3,m_nTop+row*m_ndy+10);pDC-LineTo(m_nLeft+col*m_ndx+3,m_nTop+row*m_ndy+3);pDC-LineTo(m_nLeft+col*m_ndx+10,m_nTop+row*m_ndy+3);}if(type==0||type==2){pDC-MoveTo(m_nLeft+col*m_ndx-3,m_nTop+row*m_ndy-10);pDC-LineTo(m_nLeft+col*m_ndx-3,m_nTop+row*m_ndy-3);pDC-LineTo(m_nLeft+col*m_ndx-10,m_nTop+row*m_ndy-3);pDC-MoveTo(m_nLeft+col*m_ndx-3,m_nTop+row*m_ndy+10);pDC-LineTo(m_nLeft+col*m_ndx-3,m_nTop+row*m_ndy+3);pDC-LineTo(m_nLeft+col*m_ndx-10,m_nTop+row*m_ndy+3);}pDC-SelectObject(pOldPen);}//È¡ÆåÅÌÉϸ÷½»²æµãµÄ×ø±êCPointCPlate::GetPosition(intcol,introw){CPointpoint;point.x=m_nLeft+col*m_ndx;point.y=m_nTop+row*m_ndy;returnpoint;}//Æå×ÓÀà//¶¨ÒåÆå×ÓÃû³Æ#defineBING1#definePAO2#defineJU3#defineMA4#defineXIANG5#defineSHI6#defineJIANG7classCStone{BOOLm_bRed;//ÊÇ·ñºì·½BOOLm_bSelected;//ÊÇ·ñ±»Ñ¡Ôñintm_nCol;//·intm_nRow;//ÐÐCRectm_rectStone;//Æå×Ó°üº¬¾ØÐÎBOOLm_bShow;//ÊÇ·ñÏÔʾCStringm_sName;//Æå×ÓÃû³Æintm_nR;//Æå×Ӱ뾶intm_nType;//Æå×ÓÀàÐÍpublic:CStone(){}CStone(BOOLred,intcol,introw,LPCSTRname,inttype,CPlate&plate);voidShowStone(CDC*pDC);voidMoveTo(intcol,introw,CPlate&plate);CRectGetRect(){returnm_rectStone;}intGetType(){returnm_nType;}BOOLBeKilled(intcol,introw){returnm_bShow&&m_nCol==col&&m_nRow==row;}BOOLMouseOnStone(CPointpoint){returnm_rectStone.PtInRect(point)&&m_bShow;}voidKillIt(){m_bShow=FALSE;}voidSelectStone(){m_bSelected=!m_bSelected;}};//Æå×ÓÀàµÄ³ÉÔ±º¯Êý//Æå×ÓÀàµÄ¹¹Ô캯Êý£º³õʼ»¯Æå×ÓCStone::CStone(BOOLred,intcol,introw,LPCSTRname,inttype,CPlate&plate){m_bShow=TRUE;m_bSelected=FALSE;m_bRed=red;m_nCol=col;m_nRow=row;m_sName=name;m_nType=type;m_nR=23;CPointpos=plate.GetPosition(col,row);m_rectStone=CRect(pos.x-m_nR,pos.y-m_nR,pos.x+m_nR,pos.y+m_nR);}//ÏÔʾÆå×ÓvoidCStone::ShowStone(CDC*pDC){if(m_bShow)//Ö»ÓÐδ±»³ÔµôµÄÆå×Ó²ÅÏÔʾ{//×¼±¸»Æå×ӵĻ±ÊºÍ»Ë¢CPen*pOldPen,penNormal(PS_SOLID,3,RGB(120,120,120));CBrush*pOldBrush,brushNormal,brushSelected;brushNormal.CreateSolidBrush(RGB(255,255,0));brushSelected.CreateSolidBrush(RGB(127,127,0));pOldPen=pDC-SelectObject(&penNormal);//±»Ñ¡ÖеÄÆå×ÓÑÕÉ«²»Í¬if(m_bSelected)pOldBrush=pDC-SelectObject(&brushSelected);elsepOldBrush=pDC-SelectObject(&brushNormal);//ÏÔʾÆå×ÓCRectr(m_rectStone);r.left++;r.top++;r.right--;r.bottom--;pDC-Ellipse(r);pDC-SelectObject(pOldPen);pDC-SelectObject(pOldBrush);//×¼±¸ÏÔʾÆå×ÓÃû³ÆµÄ×ÖÌåCFont*pOldFont,fontStone;fontStone.CreateFont(40,0,0,0,400,FALSE,FALSE,0,OEM_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,¿¬Ìå);pOldFont=pDC-SelectObject(&fontStone);inttx=m_rectStone.left+
本文标题:c++做的象棋源代码
链接地址:https://www.777doc.com/doc-4948273 .html