五子棋程序设计报告.docx
- 文档编号:10896196
- 上传时间:2023-05-28
- 格式:DOCX
- 页数:22
- 大小:291.39KB
五子棋程序设计报告.docx
《五子棋程序设计报告.docx》由会员分享,可在线阅读,更多相关《五子棋程序设计报告.docx(22页珍藏版)》请在冰点文库上搜索。
五子棋程序设计报告
五子棋程序设计报告
班级:
姓名:
学号:
指导老师:
2012/1/07
一、课程设计题目与要求
题目:
网络五子棋游戏。
功能要求:
该软件应包括服务器端程序和客户端程序两个部分,要求
实现的功能如下。
客户端功能要求:
(1)友好的用户登录界面设计;
(2)登录服务器后,请求用户列表;
(3)相其他用户发出邀请,做游戏;
(4)当用户加入或离开时,客户端接受服务器发送的成员列表,更
新用户列表;
(5)当用户开始游戏或游戏结束时,服务器通知客户端用户更新该
用户状态,客户端接受该消息后,更新该用户状态;
(6)根据五子棋的游戏规则实现五子棋的游戏功能,包括游戏判断、
画图等。
服务器端功能要求:
(1)服务器接受用户注册信息,服务器最多容纳64个成员,成员信
息包括:
用户名、IP地址、端口和状态,当服务器退出时,保
存用户信息;
(2)当用户加入或退出,服务器向所有用户发送成员列表,通知客
户端更新成员列表;
(3)当用户开始游戏或者结束游戏时,服务器通知其他用户更新该
用户状态,通知客户端更新成员状态;
(4)和客户端一起维护游戏的进行,发送游戏信息。
二、需求分析以及模型框架
1.五子棋游戏是一历史悠久,对抗性强,技巧性高的棋类游戏。
而且我对五子棋有着独特的爱好,希望自己也可以编写出一款可以实现人机对战的五子棋游戏。
把自己的思想付给电脑,让自己有些成就感,给自己继续努力的动力。
借此次课程设计的机会,把想法变成现实。
而且五子棋不仅能增强思维能力,提高智力,而且富含哲理,有助于修身养性。
五子棋既有现代休闲的明显特征“短、平、快”,又有古典哲学的高深学问“阴阳易理”;它既有简单易学的特性,为人民群众所喜闻乐见,又有深奥的技巧和高水平的国际性比赛;它的棋文化源渊流长,具有东方的神秘和西方的直观;既有“场”的概念,亦有“点”的连接。
它是中西文化的交流点,是古今哲理的结晶。
所以此次c++课程设计选择五子棋这个题目。
2.程序所实现的功能
通过给电脑赋予人工智能,利用电脑运算速度快的特点,结合五子棋的游戏规则,给电脑设定固定的扫描方式,设定权值,使电脑能够选择最合适的落子点,然后调用加载已做好的棋盘棋子图像,最终实现简单的人机对弈。
3.该游戏为普通玩家使用,只要连成五子即获胜.
三、设计内容
1.根据所选题目,给出模块图
2.画出主程序及其主要模块的流程图
四、相关截图:
1、开始游戏的时候,会根据提示来选择游模式。
2、如果选的对手是电脑。
则会提示是哪个级别的。
初级、中级和高级。
3、系统会根据你下棋子来判断来怎么下。
4、在任何一方下到五个子的时候,系统会提示输赢,以及下棋过程中有无悔棋,和总共下了几手。
五、相关代码:
1.Pente.h
#if!
defined(AFX_PENTE_H__9A01CC66_D589_11D1_92B0_000021003EA5__INCLUDED_)
#defineAFX_PENTE_H__9A01CC66_D589_11D1_92B0_000021003EA5__INCLUDED_
#if_MSC_VER>=1000
#pragmaonce
#endif//_MSC_VER>=1000
#ifndef__AFXWIN_H__
#errorinclude'stdafx.h'beforeincludingthisfileforPCH
#endif
#include"resource.h"//mainsymbols
#defineMODE_WITH_COMPUTER0
#defineMODE_2PLAYER1
#defineMODE_2PLAYER_NET2
#defineMODE_2PLAYER_MODEM3
#defineID_TIMER_NET100
#defineMESSAGE_SIZE512
/////////////////////////////////////////////////////////////////////////////
//CPenteApp:
//SeePente.cppfortheimplementationofthisclass
//
classCPenteApp:
publicCWinApp
{
public:
CPenteApp();
//Overrides
//ClassWizardgeneratedvirtualfunctionoverrides
//{{AFX_VIRTUAL(CPenteApp)
public:
virtualBOOLInitInstance();
//}}AFX_VIRTUAL
//Implementation
//{{AFX_MSG(CPenteApp)
//NOTE-theClassWizardwilladdandremovememberfunctionshere.
//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
//MicrosoftDeveloperStudiowillinsertadditionaldeclarationsimmediatelybeforethepreviousline.
#endif//!
defined
2.Pente.cpp:
#include"stdafx.h"
#include"Pente.h"
#include"PenteDlg.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//CPenteApp
BEGIN_MESSAGE_MAP(CPenteApp,CWinApp)
//{{AFX_MSG_MAP(CPenteApp)
//NOTE-theClassWizardwilladdandremovemappingmacroshere.
//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!
//}}AFX_MSG
ON_COMMAND(ID_HELP,CWinApp:
:
OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CPenteAppconstruction
CPenteApp:
:
CPenteApp()
{
//TODO:
addconstructioncodehere,
//PlaceallsignificantinitializationinInitInstance
}
/////////////////////////////////////////////////////////////////////////////
//TheoneandonlyCPenteAppobject
CPenteApptheApp;
/////////////////////////////////////////////////////////////////////////////
//CPenteAppinitialization
BOOLCPenteApp:
:
InitInstance()
{
//stardardinitializationbegin...
AfxEnableControlContainer();
//Standardinitialization
//Ifyouarenotusingthesefeaturesandwishtoreducethesize
//ofyourfinalexecutable,youshouldremovefromthefollowing
//thespecificinitializationroutinesyoudonotneed.
#ifdef_AFXDLL
Enable3dControls();//CallthiswhenusingMFCinasharedDLL
#else
Enable3dControlsStatic();//CallthiswhenlinkingtoMFCstatically
#endif
SetRegistryKey(_T("MultiMediaGuid"));
CPenteDlgdlg;
m_pMainWnd=&dlg;
intnResponse=dlg.DoModal();
if(nResponse==IDOK)
{
//TODO:
Placecodeheretohandlewhenthedialogis
//dismissedwithOK
}
elseif(nResponse==IDCANCEL)
{
//TODO:
Placecodeheretohandlewhenthedialogis
//dismissedwithCancel
}
//Sincethedialoghasbeenclosed,returnFALSEsothatweexitthe
//application,ratherthanstarttheapplication'smessagepump.
returnFALSE;
}
3.AboutDlg.h
#if!
defined(AFX_ABOUTDLG_H__701A5C62_DBBE_11D1_92B0_000021003EA5__INCLUDED_)
#defineAFX_ABOUTDLG_H__701A5C62_DBBE_11D1_92B0_000021003EA5__INCLUDED_
#if_MSC_VER>=1000
#pragmaonce
#endif//_MSC_VER>=1000
//AboutDlg.h:
headerfile
//
/////////////////////////////////////////////////////////////////////////////
//CAboutDlgdialog
classCAboutDlg:
publicCDialog
{
//Construction
public:
CAboutDlg(CWnd*pParent=NULL);//standardconstructor
//DialogData
//{{AFX_DATA(CAboutDlg)
enum{IDD=IDD_ABOUTDLG};
//NOTE:
theClassWizardwilladddatamembershere
//}}AFX_DATA
//Overrides
//ClassWizardgeneratedvirtualfunctionoverrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport
//}}AFX_VIRTUAL
//Implementation
protected:
//Generatedmessagemapfunctions
//{{AFX_MSG(CAboutDlg)
virtualBOOLOnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
//MicrosoftDeveloperStudiowillinsertadditionaldeclarationsimmediatelybeforethepreviousline.
#endif//!
defined
4.AboutDlg.cpp:
#include"stdafx.h"
#include
#include
#include
#include"resource.h"
#include"HelperAPI.h"
#include"Globalvar.h"
#include"AboutDlg.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//CAboutDlgdialog
CAboutDlg:
:
CAboutDlg(CWnd*pParent/*=NULL*/)
:
CDialog(:
:
g_bChinese?
IDD_ABOUTDLG1:
IDD_ABOUTDLG,pParent)
{
//{{AFX_DATA_INIT(CAboutDlg)
//NOTE:
theClassWizardwilladdmemberinitializationhere
//}}AFX_DATA_INIT
}
voidCAboutDlg:
:
DoDataExchange(CDataExchange*pDX)
{
CDialog:
:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//NOTE:
theClassWizardwilladdDDXandDDVcallshere
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CAboutDlgmessagehandlers
BOOLCAboutDlg:
:
OnInitDialog()
{
CDialog:
:
OnInitDialog();
HICONhIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
SetIcon(hIcon,TRUE);//Setbigicon
SetIcon(hIcon,FALSE);//Setsmallicon
CStringstr;
//fillmemoryinfo
MEMORYSTATUSMemStat;
MemStat.dwLength=sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&MemStat);
//TotalPhysicalmem
str.Format("%luKB",MemStat.dwTotalPhys/1024L);
SetDlgItemText(IDC_PHYSICAL_MEM,str);
//FreePhysicalmem
str.Format("%luKB",MemStat.dwAvailPhys/1024L);
SetDlgItemText(IDC_AVAIL_MEM,str);
//FreeVirtualmem
str.Format("%luKB",MemStat.dwAvailVirtual/1024L);
SetDlgItemText(IDC_AVAIL_VIRTUAL_MEM,str);
//fillCPUinfo
SYSTEM_INFOSysInfo;
GetSystemInfo(&SysInfo);
switch(SysInfo.dwProcessorType)
{
casePROCESSOR_INTEL_486:
str="Intel80486";
break;
casePROCESSOR_INTEL_PENTIUM:
str="IntelPentium";
break;
default:
str="";
break;
}
SetDlgItemText(IDC_CPU,str);
//fillOSinfo
OSVERSIONINFOOsInfo;
OsInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
if(GetVersionEx(&OsInfo))
{
//platform
switch(OsInfo.dwPlatformId)
{
caseVER_PLATFORM_WIN32_WINDOWS:
str="Windows95";
break;
caseVER_PLATFORM_WIN32_NT:
str="WindowsNT";
break;
default:
str="";
break;
}
SetDlgItemText(IDC_OS,str);
//versionandlanguage
charszVer[512];
GetWindowsVersion((LPSTR)szVer);
str.Format("%ld.%ld,%s",OsInfo.dwMajorVersion,
OsInfo.dwMinorVersion,szVer);
SetDlgItemText(IDC_VERSION,str);
}
//filldiskinformation
charszWindowsPath[_MAX_PATH];
GetWindowsDirectory(szWindowsPath,_MAX_PATH);
ULARGE_INTEGERTotalNumberOfBytes,TotalNumberOfFreeBytes;
GetDiskFreeSpaceEx((LPSTR)szWindowsPath,
NULL,
&TotalNumberOfBytes,
&TotalNumberOfFreeBytes);
//totalspace
str.Format("%luKB",TotalNumberOfBytes.QuadPart/1024L);
SetDlgItemText(IDC_TOTAL_SPACE,str);
//freespace
str.Format("%luKB",TotalNumberOfFreeBytes.QuadPart/1024L);
SetDlgItemText(IDC_FREE_SPACE,str);
PlaySound(IDSOUND_WELCOME);
returnTRUE;//returnTRUEunlessyousetthefocustoacontrol
//EXCEPTION:
OCXPropertyPagesshouldreturnFALSE
}
5.BestDlg.cpp:
implementationfile
//
#include"stdafx.h"
#include"Pente.h"
#include"Globalvar.h"
#include"BestDlg.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//CBestDlgdialog
CBestDlg:
:
CBestDlg(CWnd*pParent/*=NULL*/)
:
CDialog(:
:
g_bChinese?
IDD_BEST1:
IDD_BEST)
{
//{{AFX_DATA_INIT(CBestDlg)
//NOTE:
theClassWizardwilladdmemberinitializationhere
//}}AFX_DATA_INIT
}
voidCBestDlg:
:
DoDataExchange(CDataExchange*pDX)
{
CDialog:
:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBestDlg)
//NOTE:
theClassWizardwilladdDDXandDDVcallshere
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBestDlg,CDialog)
//{{AFX_MSG_MAP(CBestDlg)
ON_BN_CLICKED(IDC_RESTARTCOUNT,OnRestartcount)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 五子棋 程序设计 报告