Chinaunix首页 | 论坛 | 博客
  • 博客访问: 626221
  • 博文数量: 144
  • 博客积分: 5037
  • 博客等级: 大校
  • 技术积分: 1581
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-30 21:49
文章存档

2010年(16)

2009年(128)

分类: C/C++

2009-04-20 14:36:32

代码是mousePressEvent事件的获得
void ChessBoard::mousePressEvent(QMouseEvent *event)
{
    int tmp_x = 0;
    int tmp_y = 0;
    tmp_x = event->x();
    tmp_y = event->y();
    if((tmp_x > point_x && tmp_x < point_x + 8*line) && (tmp_y > point_y && tmp_y < point_y + 8*line))
    {
        if(mutex == 0)
        {
            if(chess[(tmp_x-point_x)/line][(tmp_y-point_y)/line] == 0)
            {
                arithmetic( (tmp_x-point_x)/line, (tmp_y-point_y)/line, 1);
                if(signal == 1)
                {
                    chess[(tmp_x-point_x)/line][(tmp_y-point_y)/line] = 1;
                    mutex = 1;
                    emit(turn_red());
                    signal = 0;
                }
            }
            else
                mutex = 0;
        }
        else
        {
            if(chess[(tmp_x-point_x)/line][(tmp_y-point_y)/line] == 0)
            {
                arithmetic( (tmp_x-point_x)/line, (tmp_y-point_y)/line, 2);
                if(signal == 1)
                {
                    chess[(tmp_x-point_x)/line][(tmp_y-point_y)/line] = 2;
                    mutex = 0;
                    emit(turn_blue());
                    signal = 0;
                }
            }
            else
                mutex = 1;
        }
        update();
    }
    else
    {
        ;
    }
    if(total_num != 64)
    {
        get_chess_num();
    }
}

 

附件为:源码,不过不是人机对战,人机对战的我已经实现,不过算法过于简单,(我设计的电脑太笨了,不敢拿出来献丑),顾想求一算法,希望大家帮忙,谢过。

文件: bwchess.tar.gz
大小: 54KB
下载: 下载

阅读(823) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~