• 大小: 1.56MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-24
  • 语言: 其他
  • 标签: qtc++算法  

资源简介

简单的QT操作,包含了widget,socket,QTcpServer,pushbutton,等控件,是毕设,项目的好帮手

资源截图

代码片段和文件信息

#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)
{
    _r = 20;
    setMinimumSize(_r*18+1 _r*20+1);//设置最小尺寸
    init(true);
}
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是某个数值
    int r =20;//和上面那句的效果是一样的
    _r = r;
    _off =QPoint(r+1 r+1);//F1查阅QPoint,若00就会返回true

    QPainter p(this);//构建一个p的句柄
    p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
//QPainter::Antialiasing表示如果可能的话,引擎应该使用原语的别名。
    //
    p.save();//保存当前的画家状态(将状态推到堆栈上)。一个save()必须后面跟着一个相应的恢复();end()函数解除堆栈。
    drawPlate(p);//绘制棋盘
    p.restore();

    p.save();//
    drawPlace(p);//画了2个士的走线
    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)//id等于-1返回真?其余情况,返回棋子是否死亡的状态
{
    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() + 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-12-04 15:18  chessbymySelf\
     目录           0  2017-12-04 17:36  chessbymySelf\chess\
     文件       14089  2017-12-04 16:02  chessbymySelf\chess\Board.cpp
     文件        2735  2017-12-04 17:13  chessbymySelf\chess\Board.h
     文件         926  2017-12-04 16:02  chessbymySelf\chess\Choosedlg.cpp
     文件         372  2017-12-04 16:02  chessbymySelf\chess\Choosedlg.h
     文件         579  2017-12-04 16:02  chessbymySelf\chess\Ctrlpanel.cpp
     文件         336  2017-12-04 17:35  chessbymySelf\chess\Ctrlpanel.h
     目录           0  2017-12-04 17:34  chessbymySelf\chess\Debug\
     文件         835  2017-12-04 17:34  chessbymySelf\chess\Debug\.qmake.stash
     文件       31793  2017-12-04 17:34  chessbymySelf\chess\Debug\Makefile
     文件      169960  2017-12-04 17:34  chessbymySelf\chess\Debug\Makefile.Debug
     文件      170188  2017-12-04 17:34  chessbymySelf\chess\Debug\Makefile.Release
     目录           0  2017-12-04 17:35  chessbymySelf\chess\Debug\debug\
     文件      201840  2017-12-04 17:35  chessbymySelf\chess\Debug\debug\Board.obj
     文件      111288  2017-12-04 17:34  chessbymySelf\chess\Debug\debug\Choosedlg.obj
     文件       98097  2017-12-04 17:35  chessbymySelf\chess\Debug\debug\Ctrlpanel.obj
     文件      114900  2017-12-04 17:35  chessbymySelf\chess\Debug\debug\Mainwnd.obj
     文件       89843  2017-12-04 17:35  chessbymySelf\chess\Debug\debug\Multigame.obj
     文件      134267  2017-12-04 17:35  chessbymySelf\chess\Debug\debug\Netgame.obj
     文件      143458  2017-12-04 17:35  chessbymySelf\chess\Debug\debug\Singlegame.obj
     文件       57153  2017-12-04 17:35  chessbymySelf\chess\Debug\debug\Step.obj
     文件       94960  2017-12-04 17:35  chessbymySelf\chess\Debug\debug\Stone.obj
     文件      167424  2017-12-04 17:36  chessbymySelf\chess\Debug\debug\chess.exe
     文件     1399456  2017-12-04 17:36  chessbymySelf\chess\Debug\debug\chess.ilk
     文件     2166784  2017-12-04 17:36  chessbymySelf\chess\Debug\debug\chess.pdb
     文件     1593344  2017-12-04 17:35  chessbymySelf\chess\Debug\debug\chess.vc.pdb
     文件       92382  2017-12-04 17:35  chessbymySelf\chess\Debug\debug\main.obj
     文件        3369  2017-12-04 17:35  chessbymySelf\chess\Debug\debug\moc_Board.cpp
     文件       71268  2017-12-04 17:35  chessbymySelf\chess\Debug\debug\moc_Board.obj
     文件        3467  2017-12-04 17:34  chessbymySelf\chess\Debug\debug\moc_Choosedlg.cpp
............此处省略30个文件信息

评论

共有 条评论

相关资源