C#实现人机对战五子棋


源代码,C#实现五子棋,人机对战,人人对战
资源截图
代码片段和文件信息
// Chess.cpp: implementation of the CChess class.
// Download by http://www.codefans.net
//////////////////////////////////////////////////////////////////////

#include “stdafx.h“
#include “五子棋.h“
#include “Chess.h“


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CChess::CChess()
{
memset(m_board0sizeof(m_board));
m_turn=1;
m_flag=0;
posflag=0;
}

CChess::~CChess()
{

}

int CChess::PanYing(int nx int ny)
{
int count=0;
for(int i=-4;i<5;i++)
{
if(m_board[ny][nx+i]==m_turn) {count++;if(count==5) return m_turn;}
else count=0;
}
count=0;
for(i=-4;i<5;i++)
{
if(m_board[ny+i][nx]==m_turn) {count++;if(count==5) return m_turn;}
else count=0;
}
count=0;
for(i=-4;i<5;i++)
{
if(m_board[ny+i][nx+i]==m_turn) {count++;if(count==5) return m_turn;}
else count=0;

}
count=0;
for(i=-4;i<5;i++)
{
if(m_board[ny+i][nx-i]==m_turn) {count++;if(count==5) return m_turn;}
else count=0;
}
count=0;
return 0;
}

void CChess::DrawQp()
{
dc->BitBlt(00446446qp00SRCCOPY);
}

void CChess::DrawQz(int nxint nyint type)
{
if(type==0)
{
if(m_turn==1){dc->Ellipse(nx*29+7ny*29+7nx*29+34ny*29+34);
posinfo[posflag].x=nx;
posinfo[posflag].y=ny;
posinfo[posflag].flag=m_turn;
posflag++;}
else
{
CBrush *brush;
CBrush brush1(RGB(000));
brush=dc->Selectobject(&brush1);
dc->Ellipse(nx*29+7ny*29+7nx*29+34ny*29+34);
posinfo[posflag].x=nx;
posinfo[posflag].y=ny;
posinfo[posflag].flag=m_turn;
posflag++;
dc->Selectobject(brush);
}
}
else if(type==1)
{
dc->Ellipse(nx*29+7ny*29+7nx*29+34ny*29+34);
posinfo[posflag].x=nx;
posinfo[posflag].y=ny;
posinfo[posflag].flag=m_turn;
posflag++;
}
else
{
CBrush *brush;
CBrush brush1(RGB(000));
brush=dc->Selectobject(&brush1);
dc->Ellipse(nx*29+7ny*29+7nx*29+34ny*29+34);
posinfo[posflag].x=nx;
posinfo[posflag].y=ny;
posinfo[posflag].flag=m_turn;
posflag++;
dc->Selectobject(brush);
}
}

bool CChess::DownZi(int nx int nyint typeHWND hwnd)
{
int xy;
if(nx<0||nx>14||ny<0||ny>14) 
{
MessageBox(hwnd“不正确的下子位置!“ NULLMB_OK);
return false;
}
if(CChess::m_flag!=0)//已分出胜负
{
if(m_flag==1){MessageBox(hwnd“白棋获胜!“ NULLMB_OK);return true;}
else{MessageBox(hwnd“黑棋获胜!“ NULLMB_OK);return true;}
}
if(m_board[ny][nx]==0)
{
if(type==2)//人人对战
{
m_board[ny][nx]=m_turn;
DrawQz(nxny);
m_flag=PanYing(nxny);
m_turn=(m_turn==1?2:1);
if(m_flag==1){MessageBox(hwnd“白棋获胜!“ NULLMB_OK);return true;}
if(m_flag==2){MessageBox(hwnd“黑棋获胜!“ NULLMB_OK);return true;}
return true;
}
else //人机对战
{
m_board[ny][nx]=m_turn;
DrawQz(n

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      10670  2011-09-07 10:07  五子棋Chess.cpp

     文件       1199  2011-09-06 11:17  五子棋Chess.h

     文件      24864  2011-09-07 10:07  五子棋DebugChess.obj

     文件       8467  2011-09-07 10:07  五子棋DebugChess.sbr

     文件      10401  2011-09-06 08:30  五子棋DebugSettingDlg.obj

     文件       2131  2011-09-06 08:30  五子棋DebugSettingDlg.sbr

     文件     106032  2011-09-06 08:30  五子棋DebugStdAfx.obj

     文件    1377953  2011-09-06 08:30  五子棋DebugStdAfx.sbr

     文件     222208  2011-09-07 10:08  五子棋Debugvc60.idb

     文件     364544  2011-09-07 10:07  五子棋Debugvc60.pdb

     文件     364618  2011-09-07 10:07  五子棋Debug五子棋.exe

     文件     241928  2011-09-07 10:07  五子棋Debug五子棋.ilk

     文件      14021  2011-09-06 11:17  五子棋Debug五子棋.obj

     文件    6868432  2011-09-06 08:30  五子棋Debug五子棋.pch

     文件     386048  2011-09-07 10:07  五子棋Debug五子棋.pdb

     文件     203956  2011-09-07 09:54  五子棋Debug五子棋.res

     文件       3362  2011-09-06 11:17  五子棋Debug五子棋.sbr

     文件      30703  2011-09-06 11:17  五子棋Debug五子棋Dlg.obj

     文件       6648  2011-09-06 11:17  五子棋Debug五子棋Dlg.sbr

     文件         40  2009-02-28 19:17  五子棋info.h

     文件       3567  2009-02-27 13:43  五子棋ReadMe.txt

     文件     200886  2011-09-07 09:54  五子棋
esqp.bmp

     文件       1078  2009-02-27 13:43  五子棋
es五子棋.ico

     文件        398  2009-02-27 13:43  五子棋
es五子棋.rc2

     文件       1096  2009-02-28 19:44  五子棋Resource.h

     文件        998  2010-01-13 17:42  五子棋SettingDlg.cpp

     文件       1219  2009-02-28 19:47  五子棋SettingDlg.h

     文件        208  2009-02-27 13:43  五子棋StdAfx.cpp

     文件       1054  2009-02-27 13:43  五子棋StdAfx.h

     文件     237900  2011-09-07 09:54  五子棋五子棋.aps

............此处省略17个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)