資源簡介
源代碼,C#實現五子棋,人機對戰(zhàn),人人對戰(zhàn)

代碼片段和文件信息
//?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)//人人對戰(zhàn)
{
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?//人機對戰(zhàn)
{
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??五子棋\Debug\Chess.obj
?????文件???????8467??2011-09-07?10:07??五子棋\Debug\Chess.sbr
?????文件??????10401??2011-09-06?08:30??五子棋\Debug\SettingDlg.obj
?????文件???????2131??2011-09-06?08:30??五子棋\Debug\SettingDlg.sbr
?????文件?????106032??2011-09-06?08:30??五子棋\Debug\StdAfx.obj
?????文件????1377953??2011-09-06?08:30??五子棋\Debug\StdAfx.sbr
?????文件?????222208??2011-09-07?10:08??五子棋\Debug\vc60.idb
?????文件?????364544??2011-09-07?10:07??五子棋\Debug\vc60.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??五子棋\res\qp.bmp
?????文件???????1078??2009-02-27?13:43??五子棋\res\五子棋.ico
?????文件????????398??2009-02-27?13:43??五子棋\res\五子棋.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個文件信息
- 上一篇:駕校信息管理系統論文+源碼
- 下一篇:超市管理系統C#
評論
共有 條評論