资源简介

VC6.0做的五子棋程序源码(含禁手规则判断和倒计时功能),对战模式主要有人机对战、机人对战、人人对战等三种智能对战模式,还有黑棋的3-3、4-4禁手判定,以及6、7、8、9长连判断规则,另外还设置了黑、白双方倒计时功能,本程序为原创,特地与大家分享

资源截图

代码片段和文件信息

// Chess.cpp: implementation of the CChess class.
//
//////////////////////////////////////////////////////////////////////

#include “stdafx.h“
#include “MyChess.h“
#include “Chess.h“
#include “MyChessDlg.h“


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

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

// 构造函数,初始化参数
CChess::CChess()
{
flagForbidHand=false;

memset(m_board0sizeof(m_board)); //初始化全局棋盘
m_turn=1;  //落子次序,1表示黑,2表示白
m_win=0;   //胜负标志,0表示初始值,1表示白胜,2表示黑胜
posflagNum=0;

tmpPos[0].x=-1;   //初始化最近落子位置
tmpPos[0].y=-1;
tmpPos[0].flag=0;
tmpPos[1].x=-1;   //初始化最近落子位置
tmpPos[1].y=-1;
tmpPos[1].flag=0;

isfirstnew1=true;
isfirstnew2=true;
isBackstep=false;
}

CChess::~CChess()
{

}

// 设置对战模式,重置新棋局
void CChess::NewGame(int type)
{
isBackstep=false;
flagForbidHand=false;

memset(m_board0sizeof(m_board));

m_win=0;
m_turn=1;
posflagNum=1;

if(type==0)
m_board[7][7]=1;

ReDrawGame();
if(type==0)
m_turn=(m_turn==1?2:1);
else
m_turn=1;
}

// 重画设置后的对战模式
void CChess::ReDrawGame()
{
isfirstnew1=true;
isfirstnew2=true;

DrawChessBoard();
DrawChessManAgain();
}

// 画棋盘
void CChess::DrawChessBoard()
{
dc->BitBlt(00470470qp00SRCCOPY);
}

// 重画棋盘上已有的落子
void CChess::DrawChessManAgain()
{
for(int i=0;i<15;i++)
for(int j=0;j<15;j++)
{
if(m_board[i][j]==1){DrawNewChessMan(ji1);}
if(m_board[i][j]==2){DrawNewChessMan(ji2);}
}
}


// 按下鼠标,开始落子
bool CChess::DownMan(int nx int nyint typeHWND hwnd)
{
isBackstep=false;

int x y;
// 判断落子超界
if(nx<0||nx>14||ny<0||ny>14) 
{
AfxMessageBox(“超出棋盘位置! 请重新下子...“);
return false;
}
// 判断胜负
if(CChess::m_win!=0) //0表示初始值,1表示白胜,2表示黑胜
{
if(m_win==1) //黑胜
{
AfxMessageBox(“黑棋获胜! 恭喜您!^_^“);
return true;
}
else //白胜
{
AfxMessageBox(“白棋获胜! 恭喜您!^_^“);
return true;
}
}
if(m_board[ny][nx]==0)
{
if(type==2) //人人对战
{
m_board[ny][nx]=m_turn;
DrawNewChessMan(nxnym_turn);
m_win=IsWinner(nxny);
m_turn=(m_turn==1?2:1);
if(m_win==1){AfxMessageBox(“黑棋获胜! 恭喜您!^_^“);return true;}
if(m_win==2){AfxMessageBox(“白棋获胜! 恭喜您!^_^“);return true;}
return true;
}
else  //人机对战
{
m_board[ny][nx]=m_turn;
DrawNewChessMan(nxnym_turn);
m_win=IsWinner(nxny);
m_turn=(m_turn==1?2:1);
if(m_win==1){AfxMessageBox(“黑棋获胜! 恭喜您!^_^“);return true;}
if(m_win==2){AfxMessageBox(“白棋获胜! 恭喜您!^_^“);return true;}

if(flagForbidHand)
{
m_turn=1;
return false;
}

CChess::ComAlgo(xy);
m_board[y][x]=m_turn;
DrawNewChessMan(xym_turn);
m_win=IsWinner(xy);
m_turn=(m_turn==1?2:1);
if(m_win==1){AfxMessageBox(“黑棋获胜! 恭喜您!^_^“);return true;}
if(m_win==2){AfxMessageBox(

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

     文件      25392  2009-12-16 22:33  源代码\Chess.cpp

     文件       1756  2009-12-15 15:45  源代码\Chess.h

     文件         40  2009-02-28 19:17  源代码\info.h

     文件     260800  2009-12-16 22:11  源代码\MyChess.aps

     文件       1945  2009-12-16 23:25  源代码\MyChess.clw

     文件       2026  2009-12-15 17:19  源代码\MyChess.cpp

     文件       4509  2009-12-13 19:28  源代码\MyChess.dsp

     文件        522  2009-12-12 22:08  源代码\MyChess.dsw

     文件     405581  2009-12-16 23:16  源代码\MyChess.exe

     文件       1286  2009-02-27 13:43  源代码\MyChess.h

     文件     640000  2009-12-16 23:25  源代码\MyChess.ncb

     文件      53760  2009-12-16 23:25  源代码\MyChess.opt

     文件       1405  2009-12-16 23:16  源代码\MyChess.plg

     文件       6809  2009-12-16 22:11  源代码\MyChess.rc

     文件       7094  2009-12-16 23:20  源代码\MyChessDlg.cpp

     文件       1742  2009-12-16 23:07  源代码\MyChessDlg.h

     文件       3567  2009-02-27 13:43  源代码\ReadMe.txt

     文件       1078  2009-02-27 13:43  源代码\res\MyChess.ico

     文件        398  2009-02-27 13:43  源代码\res\MyChess.rc2

     文件     222920  2009-12-14 21:20  源代码\res\qp.bmp

    ..A.SH.      9216  2009-12-14 21:20  源代码\res\Thumbs.db

     文件       1693  2009-12-15 17:23  源代码\resource.h

     文件        796  2009-12-12 21:30  源代码\SettingDlg.cpp

     文件       1199  2009-12-12 21:29  源代码\SettingDlg.h

     文件        947  2009-12-12 23:35  源代码\SetupDlg.cpp

     文件       1208  2009-12-12 23:35  源代码\SetupDlg.h

     文件        208  2009-02-27 13:43  源代码\StdAfx.cpp

     文件       1054  2009-02-27 13:43  源代码\StdAfx.h

     目录          0  2009-12-15 23:18  源代码\res

     目录          0  2009-12-16 23:25  源代码

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

评论

共有 条评论