下载 >  开发技术 >  C++ > MFC 中国象棋 viusal C++ 网络+制作文档
4

MFC 中国象棋 viusal C++ 网络+制作文档

里面的程序注释详细,是模仿qq用mfc做的一个网络版对战中国象棋的游戏,有制作文档,很详细,大家可以下载学学,觉得好的话顶一个!谢谢
2010-12-27 上传大小:3.73MB
分享
收藏 举报
MFC 中国象棋

MFC 象棋 vs2010以上编译通过 大连理工大学软件学院C++大作业

立即下载
基于MFC的中国象棋

这是一款基于MFC的中国象棋程序,有兴趣的可以自学下载

立即下载
中国象棋--C++ MFC

用于C++课程设计的中国象棋题目,基于C++ MFC制作

立即下载
C++编写中国象棋源代码

这是基于vc++6.0开发平台,丰富的数据算法融于一体的代码组合,利用MFC图形界面而开发的益智的棋盘游戏,代码希望爱好编程的学者学习

立即下载
C++版中国象棋(人机对战)

用C++实现的人机博弈中国象棋,对象棋算法有兴趣的可下载来学习

立即下载
MFC设计局域网对战五子棋游戏(源代码)

开发环境采用Visual Studio 2010旗舰版,因为不需要做什么项目,因为我还是学生呵呵,所以不需要考虑太多的兼容性方面的因素,还是喜欢用新的工具。 开发过程中使用到的技术大概有: DWM API:这是vista以来新增的API,具体内容见MSDN,游戏中只使用了部分窗口毛玻璃的效果; GDI混合GDI+:因为GDI+不支持双缓冲,所以画图时先使用GDI创建缓冲位图,然后使用GDI+的Graphics画在这个位图上,最后由GDI绘制到屏幕; CSocket:局域网对战肯定要用到socket通信,因为数据量很少,所以使用了封装好的比较简单的CSocket类,这样可以省不少代码; 多线程和互斥对象:因为CSokcet工作在阻塞模式,所以不能使用主线程接受和发送游戏数据,我把绘制图像的代码也放在一个独立线程中,所以需要使用互斥对象来确保主线程退出时所有子线程以释放主线程中的资源,否则会引起内存错误; 自绘控件:在游戏中使用默认的控件也太挫了吧,所以就要自己绘制控件,这样才像游戏,虽然市面上有很多,但是拿来的和自己写的用着感觉不一样;

立即下载
visual c++ and MFC programming

关于viusal c++和MFC编程的,希望对你有用

立即下载
中国象棋资料大全

C++ MFC中国象棋资料,有MFC实例,棋盘位图资源和算法讲解等,适用于课程设计制作

立即下载
实验2 Visual C++ MFC的图形绘制

1.了解Windows应用程序的特点。 2.掌握MFC类库中CDC类绘图函数的使用方法。 3.使用VisualC++开发简单Windows程序。

立即下载
网络对战/人机对战中国象棋

本软件可以网络对战,也可以人机对战,可以点对点对战,也可以连接服务器对战,还可以要机对战。是我的毕业设计成果,欢迎大家关注,等毕业了,我把源代码也传上来。

立即下载
viusal C++ MFC 编程实例

本书通过85个实例全面讲述了应用MFC进行Visual C++编程的思想。每个实例均以编写一个应用程序要走的步骤编写。全书共分四部分进行介绍,第一部分是基础知识,第二部分讲述用户界面的实例,第三部分讲述MFC内部处理方面的实例,第四部分讲述打包实例。全书基本上面向实例进行阐述,讲解透彻、易于掌握。本书既可作为初学者和大专院校师生的自学参考书,也可作为计算机软件开发人员的技术参考书。

立即下载
Viusal C++的实验设计

Viusal C++的实验设计,学习如何使用MFC进行界面 的开发,适合初学者,手把手教会你如何使用MFC架构

立即下载
MFC 网络编程之TCP网络调试助手

1,在网上找了许久,找到一些模板,但是都有些行行色色的问题; 2,本代码经过自己的调试,能在vs2008上执行,没问题; 3,值得一提的是radiobutton这个控件,有个Group选型,Sever和Client不是同一组的,大家注意一下,不然会出现一些问题的; 4,资源分为1分,毕竟编个程不容易,我是资源分很贫的啦!经常看到些文档,代码的都不能下,苦呀!谁叫资源描述少了,不让提交呢? 有点啰嗦, 有问题的可以给我留言,一起进步!

立即下载
C++最强版中国象棋

这是一款基于qt开发的中国象棋,功能强大,可以移植到Android和IOS,可以直接运行,代码清晰,可读性强。

立即下载
C/C++中国象棋程序入门与提高

简介《C/C++中国象棋程序入门与提高》由浅入深地介绍了中国象棋博弈程序的各个基本知识点,以实际案例来促进读者对算法的理解,提高实际编程能力。主要内容包括:中国象棋博弈,局面表示,走法表示及生成走法,局面.. 这是压缩后的第二分卷,请把两卷下载完之后再解压。

立即下载
中国象棋网络对战平台系统

中国象棋网络对战平台系统[1]中国象棋网络对战平台系统[1]中国象棋网络对战平台系统[1]中国象棋网络对战平台系统[1]中国象棋网络对战平台系统[1]中国象棋网络对战平台系统[1]中国象棋网络对战平台系统[1]中国象棋网络对战平台系统[1]

立即下载
利用MFC的CSOCKET类实现网络聊天程序

WinSock编程基础,MFC啊CSocket类,使用CSocket类的编程模型,网络聊天程序实例源代码

立即下载
VS2010下孙鑫MFC第15章网络聊天室程序的实现

前几天仿照孙鑫《VC++深入详解》书中第15章网络聊天室程序的实现重写了这个程序,VS2010下的程序与书中所写有所差别。

立即下载
中国象棋C++代码

中国象棋的C++代码 #include "chess_zn.h" QTcpSocket * Chess_ZN::client = new QTcpSocket; QUndoStack * Chess_ZN::undoStack = new QUndoStack(); int Chess_ZN::second = 120; bool Chess_ZN::isTurn = false; Chess_ZN::Chess_ZN(QWidget *parent) : QWidget(parent) { init(); initElse(); } void Chess_ZN::initElse(){ treeitem = 1; timer=new QTimer; portmap=0; isConn = true; start = false; isTimer = false; isSearch = false; connect(timer,SIGNAL(timeout()),this,SLOT(stopWatch())); connect(wigettree[1],SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(getInfo(QTreeWidgetItem*))); connect(wigettree[0],SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(connectToHost_PK(QTreeWidgetItem*))); connect(client,SIGNAL(connected()),this,SLOT(connected())); //连接一旦断开 connect(client,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(error(QAbstractSocket::SocketError ))); connect(client,SIGNAL(readyRead()),this,SLOT(readyRead())); peer = new PeerManager(this); peer->setServerPort(10001); items=wigettree[1]->currentItem(); item_pk=wigettree[0]->currentItem(); item_pk_info=wigettree[0]->currentItem(); connect(undoStack, SIGNAL(canUndoChanged(bool)),action2[8], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),action2[9], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),action2[10], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),action2[11], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),button[0], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),button[1], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),button[2], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),button[3], SLOT(setEnabled(bool))); timer->start(1000); createUndoView(); isChoose = true; tableeditor=new TableEditor("users"); } void Chess_ZN::createUndoView() { undoView = new QUndoView(undoStack); undoView->setWindowTitle(tr("Command List")); //undoView->show(); undoView->setAttribute(Qt::WA_QuitOnClose, false); } void Chess_ZN::init(){ createActions(); createMenus(); menubar = new QMenuBar; for (int i = 0; i < 4; i++) { action1[i]->setMenu(menu[i]); menubar->addAction(action1[i]); } for (int i = 0; i < 4; i++) { hblayout[i] = new QHBoxLayout; } for (int i = 0; i < 13; i++) { vblayout[i] = new QVBoxLayout; } for (int i = 0; i < 8; i++) { if(i<4){ vblayout[1]->addWidget(boxs[i]); }else if(i>=4 && i<6){ vblayout[2]->addWidget(boxs[i]); }else{ vblayout[3]->addWidget(boxs[i]); } } for (int i = 1; i < 4; i++) { hblayout[0]->addLayout(vblayout[i]); } initwidgets(); vblayout[0]->addWidget(menubar); vblayout[0]->addLayout(hblayout[0]); this->setLayout(vblayout[0]); } void Chess_ZN::createActions(){ action1[0]= new QAction(utf("游戏设置"),this); action1[1]= new QAction(utf("文件"),this); action1[2]= new QAction(utf("操作"),this); action1[3]= new QAction(utf("关于"),this); action2[0]= new QAction(utf("新建服务器"),this); action2[0]->setShortcut(tr("Ctrl+N")); action2[1]= new QAction(utf("搜索服务器"),this); action2[1]->setShortcut(tr("Ctrl+F")); action2[2]= new QAction(utf("游戏设置"),this); action2[2]->setShortcut(tr("Ctrl+G")); action2[3]= new QAction(utf("退出"),this); action2[3]->setShortcut(tr("Ctrl+Q")); action2[4]= new QAction(utf("打开"),this); action2[4]->setShortcut(tr("Ctrl+O")); action2[5]= new QAction(utf("保存"),this); action2[5]->setShortcut(tr("Ctrl+S")); action2[6]= new QAction(utf("另存为"),this); action2[6]->setShortcut(tr("Ctrl+E")); action2[7]= new QAction(utf("载入棋盘"),this); action2[7]->setShortcut(tr("Ctrl+L")); action2[8]= new QAction(utf("悔棋"),this); action2[8]->setShortcut(tr("Ctrl+D")); action2[8]->setEnabled(false); action2[9]= new QAction(utf("求和"),this); action2[9]->setShortcut(tr("Ctrl+P")); action2[9]->setEnabled(false); action2[10]= new QAction(utf("认输"),this); action2[10]->setShortcut(tr("Ctrl+T")); action2[10]->setEnabled(false); action2[11]= new QAction(utf("重来"),this); action2[11]->setShortcut(tr("Ctrl+B")); action2[11]->setEnabled(false); action2[12]= new QAction(utf("关于"),this); action2[12]->setShortcut(tr("Ctrl+A")); for (int i = 0; i < 12; i++) { connect(action2[i],SIGNAL(triggered()),this,SLOT(allAtions())); } connect(undoStack, SIGNAL(indexChanged (int )), this, SLOT(undonext(int ))); } void Chess_ZN::undonext(int dex){ QString ssup = undoStack->text(dex-1); QString ssdown = undoStack->text(dex); ssdown = ssdown.left(ssdown.indexOf(".")); ssup = ssup.left(ssup.indexOf(".")); if(ssup.compare(ssdown)==0){ undoStack->undo(); } } void Chess_ZN::createMenus(){ for (int i = 0; i < 4; i++) { menu[i] = new QMenu; } for (int i = 0; i < 4; i++) { menu[0]->addAction(action2[i]); } for (int i = 4; i < 8; i++) { menu[1]->addAction(action2[i]); } for (int i = 8; i < 12; i++) { menu[2]->addAction(action2[i]); } menu[3]->addAction(action2[12]); boxs[0] = new QGroupBox(utf("对手信息")); boxs[1] = new QGroupBox(utf("我的信息")); boxs[2] = new QGroupBox(utf("系统信息")); boxs[3] = new QGroupBox(utf("聊天对象")); boxs[4] = new QGroupBox(utf("棋逢对手")); boxs[5] = new QGroupBox(utf("你想干嘛")); boxs[6] = new QGroupBox(utf("玩家列表")); boxs[7] = new QGroupBox(utf("消息栏")); for (int i = 0; i < 6; i++) { formLayout[i] = new QFormLayout; } } void Chess_ZN::initwidgets(){ scene = new DiagramScene(client,this); QPixmap pmap(":/Resources/chessbg.png"); QBrush pixmapBrush(pmap.scaled(pmap.width(),pmap.height())); scene->setBackgroundBrush(pixmapBrush); scene->setSceneRect(QRect(0, 0, pmap.width(),pmap.height())); scene->initItem(0); graview =new QGraphicsView(scene); graview->setFixedSize(pmap.width()+5,pmap.height()+5); connect(scene, SIGNAL(itemMoved(DiagramItem *, const QPointF &)), this, SLOT(itemMoved(DiagramItem *, const QPointF &))); button[0]=new QPushButton(utf("悔棋")); button[1]=new QPushButton(utf("求和")); button[2]=new QPushButton(utf("认输")); button[3]=new QPushButton(utf("重来")); button[4]=new QPushButton(utf("邀请对战")); button[5]=new QPushButton(utf("排行榜")); button[6]=new QPushButton(utf("刷新信息")); button[7]=new QPushButton(utf("远程求助")); button[8]=new QPushButton(utf("请对方确认")); button[9]=new QPushButton(utf("清空消息")); button[10]=new QPushButton(utf("发送消息")); button[11]=new QPushButton(utf("请对方认可")); button[12]=new QPushButton(utf("加入服务器")); button[13]=new QPushButton(utf("退出服务器")); button[14]=new QPushButton(utf("开始")); button[0]->setEnabled(false); button[1]->setEnabled(false); button[2]->setEnabled(false); button[3]->setEnabled(false); button[4]->setEnabled(false); button[13]->setEnabled(false); for (int i= 0; i < 15; ++i) { connect(button[i],SIGNAL(clicked()),this,SLOT(allButtons())); } ////棋逢对手 vblayout[4]->addWidget(graview); boxs[4]->setLayout(vblayout[4]); ////你想干嘛 hblayout[1]->addWidget(button[14]); for (int i = 0; i < 4; i++) { hblayout[1]->addWidget(button[i]); } boxs[5]->setLayout(hblayout[1]); ////玩家列表 wigettree[0] = new QTreeWidget; wigettree[0]->setColumnCount(3); wigettree[1] = new QTreeWidget; wigettree[1]->setColumnCount(3); QStringList slist; slist << utf("状态") << utf("用户名") << utf("IP地址"); QStringList slistoo; slistoo << utf("服务器") << utf("信息") << utf("IP地址"); wigettree[0]->setHeaderLabels(slist); wigettree[1]->setHeaderLabels(slistoo); formLayout[1]->addRow(button[4],button[5]); formLayout[1]->addRow(button[6],button[7]); formLayout[4]->addRow(button[12],button[13]); vblayout[5]->addWidget(wigettree[1]); vblayout[5]->addLayout(formLayout[4]); vblayout[5]->addWidget(wigettree[0]); vblayout[5]->addLayout(formLayout[1]); boxs[6]->setLayout(vblayout[5]); ////消息栏 edit[1]=new QTextEdit; line[2]=new QLineEdit; edit[1]->setReadOnly(true); formLayout[3]->addRow(button[9],button[10]); vblayout[6]->addWidget(edit[1]); vblayout[6]->addWidget(line[2]); vblayout[6]->addLayout(formLayout[3]); boxs[7]->setLayout(vblayout[6]); ////对手信息 label[0] = new QLabel(utf("NONE")); label[1] = new QLabel(utf("NULL")); vblayout[7]->addWidget(label[0]); vblayout[7]->addWidget(label[1]); boxs[0]->setLayout(vblayout[7]); ////我的信息 label[2] = new QLabel(utf("NONE")); label[3] = new QLabel(utf("NULL")); vblayout[8]->addWidget(label[2]); vblayout[8]->addWidget(label[3]); boxs[1]->setLayout(vblayout[8]); ////系统信息 QLabel *laba = new QLabel(utf("系统提示:")); QLabel *labb = new QLabel(utf("请选择:")); radio[2]=new QRadioButton(utf("红方先走")); radio[3]=new QRadioButton(utf("黑方先走")); radio[4]=new QRadioButton(utf("红子")); radio[5]=new QRadioButton(utf("黑子")); vblayout[9]->addWidget(laba); vblayout[9]->addWidget(new QLabel(utf("1.黑方准备"))); vblayout[9]->addWidget(new QLabel(utf("2.红方开始"))); vblayout[9]->addWidget(new QLabel(utf("3.红方先走"))); vblayout[10]->addWidget(labb); vblayout[10]->addWidget(radio[4]); vblayout[10]->addWidget(radio[5]); vblayout[10]->addWidget(button[11]); hblayout[3]->addLayout(vblayout[9]); hblayout[3]->addLayout(vblayout[10]); label[4]=new QLabel(utf("120秒倒计时(您有120秒考虑时间)")); label[5]=new QLabel(utf("XX方剩余时间为: ")); lcd = new QLCDNumber; lcd->setNumDigits(4); formLayout[5]->addRow(label[5],lcd); vblayout[11]->addLayout(hblayout[3]); vblayout[11]->addWidget(label[4]); vblayout[11]->addLayout(formLayout[5]); boxs[2]->setLayout(vblayout[11]); boxs[2]->setEnabled(false); ////聊天对象 line[0] = new QLineEdit; line[1] = new QLineEdit; QLabel lab(utf("聊天对象")); radio[0]=new QRadioButton(utf("对手(发送信息时直接Enter)")); radio[0]->setEnabled(false); radio[1]=new QRadioButton(utf("指定IP:")); formLayout[2]->addRow(radio[1],line[0]); line[0]->setInputMask("000.000.000.000;"); edit[0]=new QTextEdit; edit[0]->setReadOnly(true); vblayout[12]->addWidget(&lab); vblayout[12]->addWidget(radio[0]); vblayout[12]->addLayout(formLayout[2]); vblayout[12]->addWidget(edit[0]); vblayout[12]->addWidget(line[1]); boxs[3]->setLayout(vblayout[12]); connect(line[1],SIGNAL(returnPressed()),this,SLOT(returnPressed())); } void Chess_ZN::allAtions(){ QAction *ac =qobject_cast<QAction *>(sender()); QString ss = ac->text(); if(ss.compare(utf("新建服务器"))==0){ server = new ChessServer(this); server->show(); }else if(ss.compare(utf("取消服务器"))==0){ server->closex(); wigettree[1]->clear(); wigettree[0]->clear(); treeitem = 1; action2[0]->setText(utf("新建服务器")); }else if(ss.compare(utf("搜索服务器"))==0){ bool ok; int i = QInputDialog::getInteger(this, utf("请输入"),utf("服务器端口"), 9999, 0, 65535, 1, &ok); if(ok){ portmap = i ; peer->sendBroadcastDatagram(1); } }else if(ss.compare(utf("悔棋"))==0){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 5; client->write(byte); }else if(ss.compare(utf("求和"))==0){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 9; client->write(byte); }else if(ss.compare(utf("认输"))==0){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 11; client->write(byte); }else if(ss.compare(utf("重来"))==0){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 13; client->write(byte); } } void Chess_ZN::allButtons(){ QPushButton *ac =qobject_cast<QPushButton *>(sender()); QString ss = ac->text(); if(ss.compare(utf("刷新信息"))==0){ portmap = 9999; peer->sendBroadcastDatagram(1); }else if(ss.compare(utf("加入服务器"))==0){ connectToHost(); }else if(ss.compare(utf("退出服务器"))==0){ client->close(); items=wigettree[1]->currentItem(); button[12]->setEnabled(true); button[13]->setEnabled(false); button[4]->setEnabled(false); peer->sendBroadcastDatagram(3); //peer->sendBroadcastDatagram(1); }else if(ss.compare(utf("邀请对战"))==0){ send_pk_vs(); }else if(ss.compare(utf("请对方认可"))==0){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 3; if(radio[4]->isChecked()){ in << 0; }else{ in << 1; } client->write(byte); }else if(ss.compare(utf("悔棋"))==0){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 5; client->write(byte); }else if(ss.compare(utf("准备"))==0){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 7; client->write(byte); button[14]->setEnabled(false); button[11]->setEnabled(false); isTurn = false; }else if(ss.compare(utf("开始"))==0){ if(start){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 8; client->write(byte); isTimer = true; scene->whoturn(1); button[14]->setEnabled(false); isTurn = true; }else{ QMessageBox::information(this,utf("对弈信息"),utf("您好,对手还没有准备好,请稍等..."),QMessageBox::Ok); } }else if(ss.compare(utf("求和"))==0){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 9; client->write(byte); }else if(ss.compare(utf("认输"))==0){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 11; client->write(byte); }else if(ss.compare(utf("重来"))==0){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 13; client->write(byte); }else if(ss.compare(utf("清空消息"))==0){ edit[1]->clear(); }else if(ss.compare(utf("发送消息"))==0){ QString s=line[2]->text(); if(s.trimmed().compare("")!=0){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 16; in << QHostInfo::localHostName(); in << s; peer->returnUdp()->writeDatagram(byte.data(),byte.size(),QHostAddress::Broadcast,10001); line[2]->clear(); } }else if(ss.compare(utf("远程求助"))==0){ send_pk_vs_info(); }else if(ss.compare(utf("排行榜"))==0){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 16; client->write(byte); } } void Chess_ZN::send_pk_vs_info(){ item_pk_info=wigettree[0]->currentItem(); if(!item_pk_info){ item_pk_info=wigettree[0]->currentItem(); if(!item_pk_info) return; } QString ip=item_pk_info->text(0); if(ip.compare("wait...")==0){ QMessageBox::information(this,utf("连接信息"),utf("您好,连接成功"),QMessageBox::Ok); } } void Chess_ZN::send_pk_vs(){/////////----------------邀请对战 item_pk=wigettree[0]->currentItem(); if(!item_pk){ item_pk=wigettree[0]->currentItem(); if(!item_pk) return; } QString ip=item_pk->text(2); QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 1 << ip ; client->write(byte); } void Chess_ZN::connectToHost_PK(QTreeWidgetItem*item){ if(isChoose){ item_pk=wigettree[0]->currentItem(); if(!item_pk){ item_pk=wigettree[0]->currentItem(); if(!item_pk) return; } bool bo = false; if(!client->isOpen()){ button[4]->setEnabled(false); return; } QString ip=item_pk->text(2); for (int i= 0; i < peer->ipAddresses.size(); ++i) { if(ip.compare(peer->ipAddresses.at(i).toString())==0){ bo = true; break; } } if(bo){ button[4]->setEnabled(false); }else{ button[4]->setEnabled(true); } } } void Chess_ZN::getInfo(QTreeWidgetItem*item){ if(!item){ item=wigettree[1]->currentItem(); if(!item) return; } QString ip=item->text(2); peer->sendBroadcastDatagram(ip); items=wigettree[1]->currentItem(); } void Chess_ZN::connectToHost(){ if(!items){ items=wigettree[1]->currentItem(); if(!items) return; } QString ip=items->text(2); conip = ip; client->connectToHost(ip,portmap); button[12]->setEnabled(false); button[13]->setEnabled(true); button[4]->setEnabled(false); } void Chess_ZN::connected(){ QString name=QHostInfo::localHostName(); QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); int flag=0; in << flag << name; client->write(byte); QMessageBox::information(this,utf("连接信息"),utf("您好,连接成功"),QMessageBox::Ok); } void Chess_ZN::error(QAbstractSocket::SocketError socketError){ QMessageBox::information(this,utf("连接信息"),utf(tr("对不起,连接失败: %1.").arg(client->errorString())),QMessageBox::Ok); wigettree[1]->clear(); wigettree[0]->clear(); treeitem = 1; } void Chess_ZN::readyRead(){ QByteArray data=client->readAll(); QDataStream out(data); int flag=0; out >> flag; if(flag == 0){ ///接受对战方 QString Aip; QString name; out >> Aip; out >> name; int i=QMessageBox::question(this,utf("连接"),utf(Aip+"----请您对弈!!!"),QMessageBox::Yes,QMessageBox::No); QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in<<100; if(i==QMessageBox::Yes){ label[0]->setText(name); label[1]->setText(Aip); label[2]->setText(QHostInfo::localHostName()); label[3]->setText(peer->ipAddresses.at(0).toString()); scene->addItems(); scene ->initItem(1); button[14]->setText(utf("准备")); button[4]->setEnabled(false); isChoose = false; radio[0]->setEnabled(true); radio[0]->setChecked(true); boxs[2]->setEnabled(true); radio[5]->setChecked(true); in<<1; client->write(byte); }else{ in<<-1; client->write(byte); } }else if(flag == 1){///发起对战方 int ok; out >> ok; if(ok == 1){ QString Aip; QString name; out >> Aip; out >> name; QMessageBox::information(this,utf("对战信息"),utf("您好,对方接受挑战"),QMessageBox::Ok); label[0]->setText(name); label[1]->setText(Aip); label[2]->setText(QHostInfo::localHostName()); label[3]->setText(peer->ipAddresses.at(0).toString()); scene->addItems(); scene ->initItem(0); button[14]->setText(utf("开始")); button[4]->setEnabled(false); isChoose = false; boxs[2]->setEnabled(true); radio[4]->setChecked(true); radio[0]->setEnabled(true); radio[0]->setChecked(true); }else if(ok == -1){ QMessageBox::information(this,utf("对战信息"),utf("您好,对方拒绝挑战"),QMessageBox::Ok); } }else if(flag ==2){///棋子交换信息 int mapValue; QPoint point; out >> mapValue >> point; doWithInfo(mapValue,point); scene->whoturn(1); isTurn = true; second=120; }else if(flag == 3){ int se; out >> se; QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in<<4; if(scene->r_or_b == 0){ if(se ==0 ){ int i=QMessageBox::question(this,utf("换棋"),utf("对方想换棋,您是否同意?"),QMessageBox::Yes,QMessageBox::No); if(i==QMessageBox::Yes){ scene ->initItem(1); button[14]->setText(utf("准备")); radio[5]->setChecked(true); in<<QString("ok"); client->write(byte); }else{ in<<QString("no"); client->write(byte); } } }else{ if(se ==1 ){ int i=QMessageBox::question(this,utf("换棋"),utf("对方想换棋,您是否同意?"),QMessageBox::Yes,QMessageBox::No); if(i==QMessageBox::Yes){ scene ->initItem(0); button[14]->setText(utf("开始")); radio[4]->setChecked(true); in<<QString("ok"); client->write(byte); }else{ in<<QString("no"); client->write(byte); } } } }else if(flag == 4){ QString se; out >> se; if(se.compare("ok")==0){ QMessageBox::information(this,utf("换棋信息"),utf("您好,对方同意换棋"),QMessageBox::Ok); if(scene->r_or_b == 0){ scene ->initItem(1); button[14]->setText(utf("准备")); }else{ scene ->initItem(0); button[14]->setText(utf("开始")); } }else{ QMessageBox::information(this,utf("换棋信息"),utf("您好,对方不同意换棋"),QMessageBox::Ok); } }else if(flag == 5){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 6; int i=QMessageBox::question(this,utf("悔棋"),utf("对方想悔棋,您是否同意?"),QMessageBox::Yes,QMessageBox::No); if(i==QMessageBox::Yes){ if(scene->r_or_b == 0){ if(undoStack->text(undoStack->index()-1).contains("RED")){ undoStack->undo(); undoStack->undo(); }else{ undoStack->undo(); } }else if(scene->r_or_b == 1){ if(undoStack->text(undoStack->index()-1).contains("BLACK")){ undoStack->undo(); undoStack->undo(); }else{ undoStack->undo(); } } in<<QString("ok"); client->write(byte); scene->whoturn(0); second=120; }else{ in<<QString("no"); client->write(byte); } }else if(flag == 6){ QString se; out >> se; if(se.compare("ok")==0){ scene->whoturn(1); second=120; QMessageBox::information(this,utf("悔棋信息"),utf("您好,对方同意悔棋"),QMessageBox::Ok); if(scene->r_or_b == 0){ //QMessageBox::information(this,QString::number(undoStack->index()-1),undoStack->text(undoStack->index()-1),QMessageBox::Ok); if(undoStack->text(undoStack->index()-1).contains("RED")){ undoStack->undo(); }else{ undoStack->undo(); undoStack->undo(); } }else if(scene->r_or_b == 1){ if(undoStack->text(undoStack->index()-1).contains("BLACK")){ undoStack->undo(); }else{ undoStack->undo(); undoStack->undo(); } } }else{ QMessageBox::information(this,utf("悔棋信息"),utf("您好,对方不同意悔棋"),QMessageBox::Ok); } }else if(flag == 7){ button[11]->setEnabled(false); QMessageBox::information(this,utf("对手信息"),utf("您好,对手已准备好,开始吧!!!"),QMessageBox::Ok); start = true; }else if(flag == 8){ isTimer = true; }else if(flag == 9){ int i=QMessageBox::question(this,utf("求和"),utf("对方想求和,您是否同意?"),QMessageBox::Yes,QMessageBox::No); QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 10; if(i==QMessageBox::Yes){ initAgain(); in << 1; }else{ in << 0; } client->write(byte); }else if(flag == 10){ int ff; out >>ff; if( ff ==1 ){ QMessageBox::information(this,utf("求和信息"),utf("对方同意求和!!!"),QMessageBox::Ok); initAgain(); }else{ QMessageBox::information(this,utf("求和信息"),utf("对方不同意求和!!!"),QMessageBox::Ok); } }else if(flag == 11){ int i=QMessageBox::question(this,utf("认输"),utf("对方想认输,您是否同意?"),QMessageBox::Yes,QMessageBox::No); QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 12; if(i==QMessageBox::Yes){ initAgain(); in << 1; }else{ in << 0; } client->write(byte); }else if(flag == 12){ int ff; out >>ff; if( ff ==1 ){ QMessageBox::information(this,utf("认输信息"),utf("对方同意您认输!!!"),QMessageBox::Ok); initAgain(); }else{ QMessageBox::information(this,utf("认输信息"),utf("对方不同意您认输!!!"),QMessageBox::Ok); } }else if(flag == 13){ int i=QMessageBox::question(this,utf("重来"),utf("对方想重来,您是否同意?"),QMessageBox::Yes,QMessageBox::No); QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 14; if(i==QMessageBox::Yes){ initAgain(); in << 1; }else{ in << 0; } client->write(byte); }else if(flag == 14){ int ff; out >>ff; if( ff ==1 ){ QMessageBox::information(this,utf("重来信息"),utf("对方同意重来!!!").append(QString::number(scene ->selectedItems().isEmpty())),QMessageBox::Ok); initAgain(); }else{ QMessageBox::information(this,utf("重来信息"),utf("对方不同意重来!!!"),QMessageBox::Ok); } }else if(flag == 15){ QString name; QString ss; out >> name; out >> ss; edit[0]->append(name+":\n "+ss); }else if(flag == 16){ int size; out >> size; if(size>0){ QStringList list; list << "name" << "time" << "wins" <<"ip"; tableeditor->widget->setRowCount(size); tableeditor->widget->setHorizontalHeaderLabels(list); QVariant name; QVariant time; QVariant wins; QVariant ip; for(int i=0;i<size;i++){ out >> name; QTableWidgetItem * item1 = new QTableWidgetItem; item1->setText(name.toString()); out >> time; QTableWidgetItem * item2 = new QTableWidgetItem; item2->setText(time.toString()); out >> wins; QTableWidgetItem * item3 = new QTableWidgetItem; item3->setText(wins.toString()); out >> ip; QTableWidgetItem * item4 = new QTableWidgetItem; item4->setText(ip.toString()); tableeditor->widget->setItem(i,0,item1); tableeditor->widget->setItem(i,1,item2); tableeditor->widget->setItem(i,2,item3); tableeditor->widget->setItem(i,3,item4); } tableeditor->show(); }else{ QMessageBox::information(this,utf("排行榜"),utf("不好意思,没有记录!!!"),QMessageBox::Ok); } }else if(flag == 17){ initAgain(); } } void Chess_ZN::doWithInfo(int mapValue,QPoint point){ scene->index++; int x = 8- point.x(); int y = 9- point.y(); int xl = DiagramScene::xl; int yl = DiagramScene::yl; int xw = DiagramScene::xw; int yh = DiagramScene::yh; if(scene->r_or_b == 0){ if(scene->map[y][x]!=0){ //scene->removeItem(scene->diaitemR[(scene->map[y][x])-20-1]); QUndoCommand *deleteCommand = new DeleteCommand(scene->index,scene->map, scene->diaitemR[(scene->map[y][x])-20-1]); undoStack->push(deleteCommand); } DiagramItem *diagramItem = scene->diaitemB[mapValue-20-1]; int oldx = diagramItem->localX(); int oldy = diagramItem->localY(); scene->diaitemB[mapValue-20-1]->setPos(xl+xw*x,yl+yh*y); undoStack->push(new MoveCommand(scene->index,scene->map,diagramItem,QPointF(xl+xw*oldx,yl+yh*oldy))); /*int oldx = scene->diaitemB[mapValue-20-1]->localX(); int oldy = scene->diaitemB[mapValue-20-1]->localY(); scene->diaitemB[mapValue-20-1]->setPos(xl+xw*x,yl+yh*y); scene->diaitemB[mapValue-20-1]->setLocalX(x); scene->diaitemB[mapValue-20-1]->setLocalY(y); scene->map[y][x]=(mapValue-20); scene->map[oldy][oldx]=0;*/ }else{ if(scene->map[y][x]!=0){ //scene->removeItem(scene->diaitemB[(scene->map[y][x])-20-1]); QUndoCommand *deleteCommand = new DeleteCommand(scene->index,scene->map,scene->diaitemB[(scene->map[y][x])-20-1]); undoStack->push(deleteCommand); } DiagramItem *diagramItem = scene->diaitemR[mapValue-20-1]; int oldx = diagramItem->localX(); int oldy = diagramItem->localY(); scene->diaitemR[mapValue-20-1]->setPos(xl+xw*x,yl+yh*y); undoStack->push(new MoveCommand(scene->index,scene->map,diagramItem,QPointF(xl+xw*oldx,yl+yh*oldy))); /* int oldx = scene->diaitemR[mapValue-20-1]->localX(); int oldy = scene->diaitemR[mapValue-20-1]->localY(); scene->diaitemR[mapValue-20-1]->setPos(xl+xw*x,yl+yh*y); scene->diaitemR[mapValue-20-1]->setLocalX(x); scene->diaitemR[mapValue-20-1]->setLocalY(y); scene->map[y][x]=(mapValue-20); scene->map[oldy][oldx]=0;*/ } } QString Chess_ZN::utf(QString s){ QByteArray ba = s.toLatin1(); const char * schar = ba.data(); QString ss=s.fromLocal8Bit(schar); return ss; } void Chess_ZN::stopWatch(){ if(isTimer){ if(scene->r_or_b == 0){ if(scene->diaitemR[0]->flags() == QGraphicsItem::ItemIsMovable){ label[5]->setText(utf("红方剩余时间为: ")); }else{ label[5]->setText(utf("黑方剩余时间为: ")); } }else{ if(scene->diaitemB[0]->flags() == QGraphicsItem::ItemIsMovable){ label[5]->setText(utf("黑方剩余时间为: ")); }else{ label[5]->setText(utf("红方剩余时间为: ")); } } lcd->display(--second); if(second == 0){ scene->whoturn(0); //QMessageBox::information(this,utf("通知..."),QString::number(isTurn),QMessageBox::Ok); if(isTurn){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 17; client->write(byte); initAgain(); QMessageBox::information(this,utf("通知..."),utf("不好意思,按规定您已经弃权认输了!!!"),QMessageBox::Ok); } } } //peer->sendBroadcastDatagram(1); } void Chess_ZN::initAgain(){ for (int i= 0; i < 16; ++i) { scene->removeItem(scene->diaitemB[i]); scene->removeItem(scene->diaitemR[i]); } start = false; second = 120; isTimer = false; isChoose = true; scene ->initItem(scene->r_or_b); scene ->whoturn(0); undoStack->clear(); label[5]->setText(utf("XX剩余时间为: ")); lcd->display(0); button[14]->setEnabled(true); button[11]->setEnabled(true); scene->addItems(); scene->initItem(scene->r_or_b); } void Chess_ZN::returnPressed(){ QString ss = line[1]->text(); if(ss.trimmed().compare("")!=0){ QByteArray byte; QDataStream in (&byte,QIODevice::ReadWrite); in << 15; in << QHostInfo::localHostName(); in << ss; if(radio[0]->isChecked()){ client->write(byte); }else if(radio[1]->isChecked()){ peer->returnUdp()->writeDatagram(byte.data(),byte.size(),QHostAddress(line[0]->text()),10001); } edit[0]->append(QHostInfo::localHostName()+":\n "+ss); line[1]->clear(); } } void Chess_ZN::itemMoved(DiagramItem *movedItem,const QPointF &oldPosition) { //undoStack->push(new MoveCommand(movedItem, oldPosition)); } Chess_ZN::~Chess_ZN() { }

立即下载
一个MFC多文档的小例子vc2015

最近在学习多文档编程,做了一个小例子放这边备查。 里面有做了多模板,创建子窗口,及在窗口上增加控件,不过没有做注释,希望下次还能看得懂。

立即下载
关闭
img

spring mvc+mybatis+mysql+maven+bootstrap 整合实现增删查改简单实例.zip

资源所需积分/C币 当前拥有积分 当前拥有C币
5 0 0
点击完成任务获取下载码
输入下载码
为了良好体验,不建议使用迅雷下载
img

MFC 中国象棋 viusal C++ 网络+制作文档

会员到期时间: 剩余下载个数: 剩余C币: 剩余积分:0
为了良好体验,不建议使用迅雷下载
VIP下载
您今日下载次数已达上限(为了良好下载体验及使用,每位用户24小时之内最多可下载20个资源)

积分不足!

资源所需积分/C币 当前拥有积分
您可以选择
开通VIP
4000万
程序员的必选
600万
绿色安全资源
现在开通
立省522元
或者
购买C币兑换积分 C币抽奖
img

资源所需积分/C币 当前拥有积分 当前拥有C币
5 4 45
为了良好体验,不建议使用迅雷下载
确认下载
img

资源所需积分/C币 当前拥有积分 当前拥有C币
5 0 0
为了良好体验,不建议使用迅雷下载
VIP和C币套餐优惠
img

资源所需积分/C币 当前拥有积分 当前拥有C币
5 4 45
您的积分不足,将扣除 10 C币
为了良好体验,不建议使用迅雷下载
确认下载
下载
您还未下载过该资源
无法举报自己的资源

兑换成功

你当前的下载分为234开始下载资源
你还不是VIP会员
开通VIP会员权限,免积分下载
立即开通

你下载资源过于频繁,请输入验证码

您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:webmaster@csdn.net!

举报

若举报审核通过,可返还被扣除的积分

  • 举报人:
  • 被举报人:
  • *类型:
    • *投诉人姓名:
    • *投诉人联系方式:
    • *版权证明:
  • *详细原因: