• 大小: 16.13MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-07-06
  • 语言: 其他
  • 标签: QT  五子棋  

资源简介

基于QT的五子棋系统,包括人人对战,人机对战和局域网联机对战三种模式。还包括悔棋,提示,计时,截图,即时聊天,背景音乐,背景图片。页面简洁美观。个人作业,可能写得不太清晰,请多多包涵~

资源截图

代码片段和文件信息

#include “client.h“
#include “testdialog.h“
#include 
#include 


client::client(QPushButton*btnQLineEdit*lineQTextEdit*textMainWindow*window)

{

    this->btn=btn;
    this->line=line;
    this->text=text;
    init();
    connect(btnSIGNAL(clicked(bool))thisSLOT(onSendMessage()));
    connect(thisSIGNAL(thePose(intint))(Qobject*)windowSLOT(recPos(intint)));

}

client::~client()
{
}

void client::init()
{
    TestDialog *dlg = new TestDialog();
   // dlg->setWindowFlags(Qt::WindowStaysOnTopHint);
    connect(dlg SIGNAL(dlgReturn(QString)) this SLOT(recIpData(QString)));
    dlg->exec();
}

void client::newTcpConnect(QString ip)
{
    tcpSocket->abort();
    tcpSocket->connectToHost(ip5555);
}

void client::onReciveData()
{
    QByteArray data = tcpSocket->readAll();
    QTextCodec *tc = QTextCodec::codecForName(“GBK“);
    QString str = tc->toUnicode(data);
    if(str.mid(08).compare(“00000000“)==0){
        int xy;
        QString temp=str.mid(82);
        if(temp.at(0)==‘0‘)
            x=((QString)temp.at(1)).toInt();
        else
            x=((QString)temp.mid(02)).toInt();
        temp=str.mid(102);
        if(temp.at(0)==‘0‘)
            y=((QString)temp.at(1)).toInt();
        else
            y=((QString)temp.mid(02)).toInt();

        emit thePose(xy);

    }
    else if(str.mid(08).compare(“11111111“)==0){
        emit thePose(-1-1);
    }
    else if(str.mid(08).compare(“22222222“)==0){
         emit thePose(-2-2);
    }
    else
    {
    mChat += (“Recv “ + str);
    text->setText(mChat);
    }
}

void client::onSendMessage()
{
    QString textEdit = line->text();
    line->clear();
    QString strData =QString::fromLocal8Bit(“Time: “) + QTime::currentTime().toString() + “\n“ + textEdit +“\n“;
    mChat+= (“Send “ + strData);
    text->setText(mChat);
    QByteArray sendMessage = strData.toLocal8Bit();
    tcpSocket->write(sendMessage);
}

void client::sendPos(int xint y)
{
    QString s1s2;
    QByteArray sendMessage;
    if(x==-1&&y==-1){  //regret信号
        sendMessage=QString(“11111111“).toLocal8Bit();
    }
    else if(x==-2&&y==-2){ //restart信号
        sendMessage=QString(“22222222“).toLocal8Bit();
    }

    else{
        if(x<10)
            s1=“0“+QString::number(x);
        else
            s1=QString::number(x);
        if(y<10)
            s2=“0“+QString::number(y);
        else
            s2=QString::number(y);
        QString strData =“00000000“+s1+s2;
        sendMessage= strData.toLocal8Bit();
    }
    tcpSocket->write(sendMessage);
}

void client::closeConnect()
{
    tcpSocket->close();
}

void client::recIpData(QString data){
    tcpSocket = new QTcpSocket;
    newTcpConnect(data);
    connect(tcpSocketSIGNAL(readyRead())SLOT(onReciveData()));
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2902  2017-04-13 13:19  QTwuziqi\client.cpp

     文件        874  2017-04-13 00:31  QTwuziqi\client.h

     文件     245038  2017-04-15 23:14  QTwuziqi\debug\client.o

     文件     229514  2017-04-16 01:20  QTwuziqi\debug\GameModel.o

     文件     221861  2017-04-15 23:57  QTwuziqi\debug\main.o

     文件     516266  2017-04-16 13:17  QTwuziqi\debug\mainwindow.o

     文件       3482  2017-04-15 23:14  QTwuziqi\debug\moc_client.cpp

     文件     229457  2017-04-15 23:14  QTwuziqi\debug\moc_client.o

     文件       5012  2017-04-15 23:57  QTwuziqi\debug\moc_mainwindow.cpp

     文件     254585  2017-04-15 23:57  QTwuziqi\debug\moc_mainwindow.o

     文件       3717  2017-04-15 23:14  QTwuziqi\debug\moc_server.cpp

     文件     339437  2017-04-15 23:14  QTwuziqi\debug\moc_server.o

     文件       3244  2017-04-15 23:14  QTwuziqi\debug\moc_testdialog.cpp

     文件     132155  2017-04-15 23:14  QTwuziqi\debug\moc_testdialog.o

     文件    2442320  2017-04-16 13:17  QTwuziqi\debug\QTwuziqi.exe

     文件     247007  2017-04-15 23:14  QTwuziqi\debug\server.o

     文件     199072  2017-04-15 23:14  QTwuziqi\debug\testdialog.o

     文件        201  2017-03-31 14:23  QTwuziqi\dialog.cpp

     文件        415  2017-03-31 14:23  QTwuziqi\dialog.h

     文件        358  2017-03-31 14:23  QTwuziqi\dialog.ui

     文件      13869  2017-04-13 19:38  QTwuziqi\GameModel.cpp

     文件       1340  2017-04-13 19:39  QTwuziqi\GameModel.h

     文件        183  2017-03-29 00:02  QTwuziqi\main.cpp

     文件      19718  2017-04-16 13:17  QTwuziqi\mainwindow.cpp

     文件       2071  2017-04-15 23:57  QTwuziqi\mainwindow.h

     文件       8031  2017-04-16 01:20  QTwuziqi\mainwindow.ui

     文件       5588  2017-04-13 19:28  QTwuziqi\Makefile

     文件       7927  2017-04-13 19:28  QTwuziqi\Makefile.Debug

     文件       8097  2017-04-13 19:28  QTwuziqi\Makefile.Release

     文件        225  2017-04-13 19:28  QTwuziqi\object_script.QTwuziqi.Debug

............此处省略37个文件信息

评论

共有 条评论