第22篇 Qt实现简单五子棋游戏(六)测试

1.界面效果

界面因为棋盘是固定的,所以放大之后不会改变,所以索性可以把界面锁死,不能放大与缩小,这样就比较好,而且不用再担心图片与界面不匹配的问题。
界面直接按设定的屏幕大小画上去。

1.1.简单双人对战模式测试(进入默认,也可自选)

在这里插入图片描述在这里插入图片描述可以判断输赢。
感觉优化了,反而又觉得没有以前的有感觉,好像还有bug,就是没有那种感觉了,去下以前的版本反而更有感觉。

人机模式是可以正常进行的。

1.2.帮助

在这里插入图片描述
点击帮助之后是这样的,没有太多的说明。

1.3.悔棋

棋子在这里插入图片描述在这里插入图片描述悔棋功能很正常。棋盘上没有棋子就提示无棋可悔。

1.4.小功能选择

在这里插入图片描述选择人机模式,先手,白棋,则我们是先手,白棋,因为电脑速度快,我没加休息时间。
在这里插入图片描述我选择的是白棋后手,所以电脑先下了一颗黑棋。

1.5.总结

bug还很多吧,有时间再好好地修改修改,判断输赢的方法很多,我也在网上看了几篇文章,但不觉得有我这种好的,初始的我是写在一个函数里的。

bool Widget::isWin(int x,int y,int color){
    int yt = 0;
    int count = 0;

    //南-北
    yt = y;
    count = 0;
    while(yt - 1 >= 0 && this->chessBoard->getLocationColor(x,yt - 1) == color){
        count++;
        yt--;
    }
    yt = y;
    while(yt + 1 <= 15 && this->chessBoard->getLocationColor(x,yt + 1) == color){
        count++;
        yt++;
    }
    if(count >= 4){
        return true;
    }
    
    //东-西
    int xt = x;
    count = 0;
    while(xt - 1 >= 0 && this->chessBoard->getLocationColor(xt - 1,y) == color){
        count++;
        xt--;
    }
    xt = x;
    while(xt + 1 <= 15 && this->chessBoard->getLocationColor(xt + 1,y) == color){
        count++;
        xt++;
    }
    if(count >= 4){
        return true;
    }
    
    //东南-西北
    xt = x,yt = y;
    count = 0;
    while(xt - 1 >= 0 && yt - 1 >= 0 && this->chessBoard->getLocationColor(xt - 1,yt - 1) == color){
        count++;
        xt--;
        yt--;
    }
    xt = x,yt = y;
    while(xt + 1 <= 15 && yt + 1 <= 15 && this->chessBoard->getLocationColor(xt + 1,yt + 1) == color){
        count++;
        xt++;
        yt++;
    }
    if(count >= 4){
        return true;
    }
    
    //西南-东北
    xt = x,yt = y;
    count = 0;
    while(xt + 1 <= 15 && yt - 1 >= 0 && this->chessBoard->getLocationColor(xt + 1,yt - 1) == color){
        count++;
        xt++;
        yt--;
    }
    xt = x,yt = y;
    while(xt - 1 >= 0 && yt + 1 <= 15 && this->chessBoard->getLocationColor(xt - 1,yt + 1) == color){
        count++;
        xt--;
        yt++;
    }
    if(count >= 4){
        return true;
    }

    return false;
}

就是从四个方向判断。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大唐不良猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值