Qt中国象棋

废话不多说,上图:


可以说,除了背景是张图片外没用到一张图片,二人对弈,非人机,非联网

软件连接:链接:https://pan.baidu.com/s/1LYLiLeoAul1MExDN8Jzgkg 密码:l2ut

源码位置:https://download.csdn.net/download/lhk_int/10510863

Qt贪吃蛇:https://blog.csdn.net/lhk_int/article/details/80870710
Qt中国象棋:https://blog.csdn.net/lhk_int/article/details/80870403
Qt五子棋:https://blog.csdn.net/lhk_int/article/details/80870558
Qt三炮打日本:https://blog.csdn.net/lhk_int/article/details/80872602
Qt俄罗斯方块:https://blog.csdn.net/lhk_int/article/details/80872520

原谅我要5分,写代码时头都炸了;

部分代码(看着都头疼):

void  Chess::mousePressEvent(QMouseEvent *event)
{
    QPalette pe;
    pe.setColor(QPalette::WindowText,listcolor.at(qrand()%listcolor.length()));
    labeltishi->setPalette(pe);
    if(event->button()==Qt::LeftButton)
    {
        mousepoint=event->pos();
         qDebug()<<"点击位置"<<mousepoint;
        if((mousepoint.x()-300)%100>=50)
        {
            x1=mousepoint.x()-(mousepoint.x()-300)%100+100-50;
            qDebug()<<"Q1";
        }
        if((mousepoint.x()-300)%100<50)
        {
           x1=mousepoint.x()-(mousepoint.x()-300)%100-50;
           qDebug()<<"Q2";


        }
        if((mousepoint.y()-100)%100<50)
        {
           y1=mousepoint.y()-(mousepoint.y()-100)%100-50;
           qDebug()<<"Q3";


        }
        if((mousepoint.y()-100)%100>=50)
        {
            y1=mousepoint.y()-(mousepoint.y()-100)%100+100-50;
            qDebug()<<"Q4";


        }
        if(mousepoint.x()<=300) x1=250;
        if(mousepoint.x()>=1200)x1=1150;
        if(mousepoint.y()<=100)y1=50;
        if(mousepoint.y()>=900)y1=850;
        if(!naqi)//为拿起
        {
        diaoyong();
        return;
        }


if(naqi)
{
  for(int i=0;i<listpiece.length();i++)
  {
      if(listpiece.at(i)->pos()==QPoint(x1,y1))//第二次点击
      {
          if(red)
          {
              if(listpiece.at(i)->fontcolor==Qt::red)
              {
                  for(int k=0;k<listpred.length();k++)
                  {
                      listpred.at(k)->close();
                      delete listpred.at(k);


                  }
                  listpred.clear();
                  listpoint.clear();
                  naqi=false;
                  diaoyong();


                  return;
              }
          }
          if(!red)
          {
              if(listpiece.at(i)->fontcolor!=Qt::red)//重选
              {
                  for(int k=0;k<listpred.length();k++)
                  {
                      listpred.at(k)->close();
                      delete listpred.at(k);


                  }
                  listpred.clear();
                  listpoint.clear();
                  naqi=false;
                  diaoyong();


                 return;
              }
          }


      }
  }
  for(int i=0;i<listpoint.length();i++)
  {
      int k=80;
      if(listpoint.at(i)==QPoint(x1,y1))
      {
          for(int j=0;j<listpiece.length();j++)
          {
              if(listpiece.at(j)->pos()==QPoint(x1,y1))
              {
                  k=j;
              }
              if(listpiece.at(j)->pos()==piecepos)
              {
                  listpiece.at(j)->move(x1,y1);
                  for(int k=0;k<listpred.length();k++)
                  {
                      listpred.at(k)->close();
                      delete listpred.at(k);
                  }
                  listpred.clear();
                  listpoint.clear();
                  naqi=false;
                  red=!red;
                  if(red)        labeltishi->setText("该\n红\n子\n下\n了\n!\n!");
                  else         labeltishi->setText("该\n绿\n子\n下\n了\n!\n!");
              }
          }
       }
      if(k!=80)
      {
          listpiece.at(k)->close();
          delete listpiece.at(k);
          listpiece.removeAt(k);
      }
      bool jiang=false,suai=false;
      for(int i=0;i<listpiece.length();i++)
      {
        if(listpiece.at(i)->str=="帥")
        {
           suai=true;
        }
        if(listpiece.at(i)->str=="将")
        {
           jiang =true;
        }
      }
      if(!suai)
      {
         QMessageBox::information(this,"Win","恭喜红方获胜");
      }
      if(!jiang)
      {
          QMessageBox::information(this,"Win","恭喜蓝方获胜");
      }


  }




}


}


}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值