用qt写的五子棋界面,请问为什么第一行和第一列 不能落棋子? 大佬 bai'tuo

图片说明

ChessWidget::ChessWidget(QWidget *parent)
: QWidget(parent)
{

ui.setupUi(this);
this->setFixedSize(800, 660);
this->setAutoFillBackground(true);
QPalette palette;
palette.setColor(QPalette::Window, QColor("#B1723C"));
this->setPalette(palette);
for (int i = 0; i < 15; ++i)
{
    for (int j = 0; j < 15; ++j)
    {
        chess[i][j] = empyt;
    }
}

}
ChessWidget::~ChessWidget()
{

}
void ChessWidget::paintEvent(QPaintEvent *)
{

QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);//反走样
QPen pen;
pen.setColor(QColor("#8D5822"));
pen.setWidth(7);
painter.setPen(pen);

QBrush brush;
brush.setColor(QColor("#EEC085"));
brush.setStyle(Qt::SolidPattern);
painter.setBrush(brush);
painter.drawRect(10, 10, 620, 620);

QPainter painters(this);
painters.setRenderHint(QPainter::Antialiasing, true);
int i, j;
for (i = 0; i <= 15; ++i)
{
    painters.drawLine(20, 20 + i * 40, 620, 20 + i * 40);
    painters.drawLine(20 + i * 40, 20, 20 + i * 40, 620);
}

brush.setStyle(Qt::SolidPattern);
for (i = 0; i < 15; ++i)
{
    for (j = 0; j < 15; ++j)
    {
        if (chess[i][j] == BLACK)
        {
            brush.setColor(Qt::black);
            painters.setBrush(brush);
            painters.drawEllipse(QPoint((i) * 40 + 20, (j ) * 40 + 20), 20, 20);
        }
        else if (chess[i][j] == WHITE)
        {
            brush.setColor(Qt::white);
            painters.setBrush(brush);
            painters.drawEllipse(QPoint((i) * 40 + 20, (j) * 40 + 20), 20, 20);
        }
    }
}

}

void ChessWidget::mousePressEvent(QMouseEvent *e)
{
int x, y;
if (e->x() >= 20 || e->x() <= 620 || e->y() >= 20 || e->y() <= 620)
{

    x = (e->x()-20)/40;
    y = (e->y()-20)/40;
    if (chess[x][y]==empyt)
    {
        chess[x][y] = player++ % 2 + 1;
    }


}
update();

}




c++

1个回答

为什么我数有16行和列?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!