资源简介
基于QT的用C++编写的中国象棋软件源代码 该代码实现了中国象棋功能,是个C++编写的,文件是源代码,视频教程可以找我单独要

代码片段和文件信息
#include “Board.h“
#include
#include
#include
#define GetRowCol(__row __col __id) \
int __row = _s[__id]._row;\
int __col = _s[__id]._col
Board::Board(QWidget *parent) : Qframe(parent)
{
this->_r = 20;
setMinimumSize(_r*18+1 _r*20+1);
init(true);
}
Board::~Board()
{
}
void Board::init(bool bRedSide)
{
for(int i=0; i<32; ++i)
{
_s[i].init(i);
}
if(bRedSide)
{
for(int i=0; i<32; ++i)
{
_s[i].rotate();
}
}
_selectid = -1;
_bRedTurn = true;
_bSide = bRedSide;
update();
}
void Board::paintEvent(QPaintEvent *)
{
int r = height()/20;
_r = r;
_off = QPoint(r+1 r+1);
QPainter p(this);
p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
p.save();
drawPlate(p);
p.restore();
p.save();
drawPlace(p);
p.restore();
p.save();
drawInitPosition(p);
p.restore();
p.save();
drawStone(p);
p.restore();
}
void Board::drawStone(QPainter &p)
{
for(int i=0; i<32; i++)
{
drawStone(p i);
}
}
bool Board::isDead(int id)
{
if(id == -1)return true;
return _s[id]._dead;
}
void Board::drawStone(QPainter &p int id)
{
if(isDead(id)) return;
QColor color;
if(red(id)) color = Qt::red;
else color = Qt::black;
p.setPen(QPen(QBrush(color) 2));
if(id == _selectid) p.setBrush(Qt::gray);
else p.setBrush(Qt::yellow);
p.drawEllipse(cell(id));
p.setFont(QFont(“system“ _r*1.2 700));
p.drawText(cell(id) name(id) QTextOption(Qt::AlignCenter));
}
QString Board::name(int id)
{
return _s[id].name();
}
bool Board::red(int id)
{
return _s[id]._red;
}
void Board::drawInitPosition(QPainter &p int row int col)
{
QPoint pt = center(row col);
QPoint off = QPoint(_r/6 _r/6);
int len = _r/3;
QPoint ptStart;
QPoint ptEnd;
if(col != 0)
{
/* 左上角 */
ptStart = QPoint(pt.x() - off.x() pt.y() - off.y());
ptEnd = ptStart + QPoint(-len 0);
p.drawLine(ptStart ptEnd);
ptEnd = ptStart + QPoint(0 -len);
p.drawLine(ptStart ptEnd);
/* 左下角 */
ptStart = QPoint(pt.x() - off.x() pt.y() + off.y());
ptEnd = ptStart + QPoint(-len 0);
p.drawLine(ptStart ptEnd);
ptEnd = ptStart + QPoint(0 +len);
p.drawLine(ptStart ptEnd);
}
if(col != 8)
{
/* 右下角 */
ptStart = QPoint(pt.x() + off.x() pt.y() + off.y());
ptEnd = ptStart + QPoint(+len 0);
p.drawLine(ptStart ptEnd);
ptEnd = ptStart + QPoint(0 +len);
p.drawLine(ptStart ptEnd);
/* 右上角 */
ptStart = QPoint(pt.x() + off.x() pt.y() - off.y());
ptEnd = ptStart + QPoint(+len 0);
p.drawLine(ptStart ptEnd);
ptEnd = ptStart + QPoint(0 -len);
p.drawLine(ptStart ptEnd);
}
}
void Board::drawInitPosition(QPainter &
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-04-04 17:26 Chinese_cheese\
文件 12075 2016-06-18 12:19 Chinese_cheese\Board.cpp
文件 2525 2016-06-18 12:19 Chinese_cheese\Board.h
文件 375 2016-06-18 12:19 Chinese_cheese\Chinese_cheese.pro
文件 18421 2016-06-18 12:19 Chinese_cheese\Chinese_cheese.pro.user
文件 806 2016-06-18 12:19 Chinese_cheese\ChooseDlg.cpp
文件 327 2016-06-18 12:19 Chinese_cheese\ChooseDlg.h
文件 542 2016-06-18 12:19 Chinese_cheese\CtrlPanel.cpp
文件 299 2016-06-18 12:19 Chinese_cheese\CtrlPanel.h
文件 431 2018-04-04 17:25 Chinese_cheese\main.cpp
文件 1471 2016-06-18 12:19 Chinese_cheese\MainWnd.cpp
文件 295 2016-06-18 12:19 Chinese_cheese\MainWnd.h
文件 114 2016-06-18 12:19 Chinese_cheese\MultiGame.cpp
文件 229 2016-06-18 12:19 Chinese_cheese\MultiGame.h
文件 2035 2016-06-18 12:19 Chinese_cheese\NetGame.cpp
文件 715 2016-06-18 12:19 Chinese_cheese\NetGame.h
文件 4274 2016-06-18 12:19 Chinese_cheese\SingleGame.cpp
文件 585 2016-06-18 12:19 Chinese_cheese\SingleGame.h
文件 91 2016-06-18 12:19 Chinese_cheese\Step.cpp
文件 304 2016-06-18 12:19 Chinese_cheese\Step.h
文件 1735 2018-04-04 17:25 Chinese_cheese\Stone.cpp
文件 392 2018-04-04 17:26 Chinese_cheese\Stone.h
文件 201 2018-04-04 16:38 Chinese_cheese\widget.cpp
文件 273 2018-04-04 16:38 Chinese_cheese\widget.h
文件 441 2018-04-04 16:38 Chinese_cheese\widget.ui
文件 735 2016-09-16 14:00 Chinese_cheese\教程目录及说明.txt
文件 50 2016-03-16 13:01 Chinese_cheese\获取更多相关课程.url
- 上一篇:mfc视图区域嵌入嵌入外部exe(窗口程序)
- 下一篇:理财管理系统 c++代码
相关资源
- 基于MFC的TCP调试助手源码95706
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- 安科瑞智能电能表MODBUS通讯程序 VC6
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 九齐单片机源码
- 商品库存管理系统 C++ MFC
- Qt画图工具源码(qgraphics draw)
- c++ 多功能计算器
- qt 串口助手源码
- C++17 In Detail
- modbus 主机源码
- 《LINUX C编程从初学到精通》光盘源码
- 嵌入式QtC++编程课件
评论
共有 条评论