Exemple #1
0
void Dialog::gameOver(bool isWin) {
    //disconnect(readWriteSocket, SIGNAL(readyRead()), this, SLOT(calcRead()));
    disconnect(timer, SIGNAL(timeout()), this, SLOT(onTimerOut()));
    timer->stop();
    
    
    if (isWin) {
        QSound::play(":/sound/sound/win.wav");
    }else {
        QSound::play(":/sound/sound/lose.wav");
    }
    gameOverDialog = new QDialog();
    gameOverDialog->setWindowTitle("Game Over");
    gameOverDialog->setFixedSize(300, 200);
    QVBoxLayout *vt = new QVBoxLayout(gameOverDialog);
    QLabel *label = new QLabel(isWin ? "你赢了!" : "你输了!", gameOverDialog);
    QLabel *myTimeLabel = new QLabel(gameOverDialog);
    myTimeLabel->setText("你的总用时为" + QString::number(myTotalTime / 60) + "分" + QString::number(myTotalTime % 60) + "秒");
    QLabel *opTimeLabel = new QLabel(gameOverDialog);
    opTimeLabel->setText("对方的总用时为" + QString::number(opTotalTime / 60) + "分" + QString::number(opTotalTime % 60) + "秒");
    OKGameOverButton = new QPushButton("确定", gameOverDialog);
    vt->addWidget(label, 0, Qt::AlignHCenter);
    vt->addWidget(myTimeLabel, 0, Qt::AlignHCenter);
    vt->addWidget(opTimeLabel, 0, Qt::AlignHCenter);
    vt->addWidget(OKGameOverButton, 0, Qt::AlignHCenter);
    connect(OKGameOverButton, SIGNAL(clicked(bool)), gameOverDialog, SLOT(close()));
    gameOverDialog->show();
}
Exemple #2
0
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    QTextCodec *utfcodec = QTextCodec::codecForName("UTF-8"); //qt4
    QTextCodec::setCodecForTr(utfcodec);
    QTextCodec::setCodecForCStrings(utfcodec);
dozvilNaVyhid=0;

    m_tray_icon = new QSystemTrayIcon(QIcon(":/new/emulator.png"), this);


     QAction *another_action = new QAction( "Показати/Сховати", m_tray_icon );
     another_action->setIcon(QIcon(":/new/emulator.png"));
     connect( another_action, SIGNAL(triggered()), this, SLOT(showHide()) );

     QAction *set_action = new QAction( "Налаштування", m_tray_icon );
     set_action->setIcon(QIcon(":/new/sett.png"));
     connect( set_action, SIGNAL(triggered()), this, SLOT(settigsDialog()) );


     QAction *quit_action = new QAction( "Вихід", m_tray_icon );
     quit_action->setIcon(QIcon(":/new/exit.png"));
     connect( quit_action, SIGNAL(triggered()), this, SLOT(dozvilNaclose()) );

     QMenu *tray_icon_menu = new QMenu;
     tray_icon_menu->addAction( another_action );
     tray_icon_menu->addAction( set_action );
     tray_icon_menu->addAction( quit_action );

     m_tray_icon->setContextMenu( tray_icon_menu );

     connect( m_tray_icon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason)));

     m_tray_icon->show();

     myThreadTimer.setSingleShot(1);
     myThreadTimer.setInterval(3000);


     myUPS=new UPSMonThread(this);

    connect(myUPS, SIGNAL(vyvidDanyh(QStringList)), this, SLOT(vyvidDanyh(QStringList)));
    connect(myUPS, SIGNAL(vyvidMess(QString)), this, SLOT(vyvidPovidomlen(QString)));
    connect(myUPS, SIGNAL(vyvidBattStatus(QString)), this, SLOT(vyvidBattStatus(QString)));
    connect(myUPS, SIGNAL(terminated()), &myThreadTimer, SLOT(start()));
    connect(myUPS, SIGNAL(offcomp()), this, SLOT(dozvilNaclose()));
    connect(&myThreadTimer, SIGNAL(timeout()), this, SLOT(onTimerOut()));

    loadSett();
    myUPS->changeBatAndWaitTime(waitTime, battVal);
    myThreadTimer.start();
//    this->hide();
    QTimer::singleShot(0, this, SLOT(showHide()));

//    connect(this, SIGNAL())

}
Exemple #3
0
void Dialog::prepareToBegin() {
    isMeBegin = true;
    sendMessage("start");
    beginButton->setDisabled(true);
    if (isOpBegin) {
        isGameBegin = true;
        connect(timer, SIGNAL(timeout()), this, SLOT(onTimerOut()));
        update();
        timer->start();
    }
}
Exemple #4
0
DelayedResponse::DelayedResponse(JsonClient * client,
                                 const QtJson::JsonObject & command,
                                 int interval, int timerOut)
    : QObject(client), m_client(client), m_hasResponded(false), m_nbCall(0) {
    Q_ASSERT(client);
    m_timer.setInterval(interval);
    connect(&m_timer, SIGNAL(timeout()), this, SLOT(timerCall()));

    QTimer::singleShot(timerOut, this, SLOT(onTimerOut()));

    m_action = command["action"].toString();
}
Exemple #5
0
Controller::Controller() :
    _deviceNeedResolve(0),
    _lastTimeFocused(0),
    _service(&_udpDiscovery, this),
    _udpDiscoveryTimer(this)
{
    _service.moveToThread(&_serviceThread);
    _serviceThread.start();

    _view = new View(&_model);
    _bonjourBrowser = new BonjourServiceBrowser(this);

    connect(&_udpDiscovery, SIGNAL(devicesFound(const QList<Device *> &)), this, SLOT(updateDevices(const QList<Device *> &)));
    connect(&_udpDiscovery, SIGNAL(pongReceived(const QString&)), this, SLOT(onPong(const QString &)));

    connect(_bonjourBrowser, SIGNAL(currentBonjourRecordsChanged(const QList<BonjourRecord> &)),
            this, SLOT(updateRecords(const QList<BonjourRecord> &)));
    connect(_bonjourBrowser, SIGNAL(error(DNSServiceErrorType)),
            this, SLOT(error(DNSServiceErrorType)));

    connect(_view, SIGNAL(sendFile(const QString&, const QList<QUrl>&, DataType)),
            this, SLOT(onSendFile(const QString&, const QList<QUrl>&, DataType)));
    connect(_view, SIGNAL(sendText(const QString&, const QString&, DataType)),
            this, SLOT(onSendText(const QString&, const QString&, DataType)));
    connect(_view, SIGNAL(cancelTransfert(const QString&)),
            this, SLOT(onCancelTransfert(const QString&)));
    connect(_view, SIGNAL(focused()), this, SLOT(onWindowFocused()));
    connect(_view, SIGNAL(forceRefresh()), this, SLOT(onForceRefresh()));

    connect(_view, SIGNAL(registerService()),
            &_service, SLOT(serviceRegister()));
    connect(_view, SIGNAL(unregisterService()),
            &_service, SLOT(serviceUnregister()));
    connect(_view, SIGNAL(deleteFromHistory(int)),
            &_service, SLOT(onDeleteFromHistory(int)));
    connect(_view, SIGNAL(clearHistoryTriggered()),
            &_service, SLOT(onClearHistory()));
    connect(_view, SIGNAL(serviceNameChanged()),
            &_service, SLOT(onTimerOut()));
    connect(_view, SIGNAL(cancelIncomingTransfert()),
            &_service, SLOT(deleteFileReset()));

    connect(&_service, SIGNAL(historyChanged(const QList<HistoryElement>&)),
            _view, SLOT(onHistoryChanged(const QList<HistoryElement>&)));
    connect(&_service, SIGNAL(historyElementProgressUpdated(unsigned)),
            _view, SLOT(historyElementProgressUpdated(unsigned)));

    connect(&_service, SIGNAL(serviceError(ServiceErrorState,bool)),
            _view, SLOT(onServiceError(ServiceErrorState,bool)));
    connect(&_service, SIGNAL(receivingFile(const QString&,int)),
             _view, SLOT(onReceivingFile(const QString&,int)));
    connect(&_service, SIGNAL(receivingFolder(const QString&,int)),
            _view, SLOT(onReceivingFolder(const QString&,int)));
    connect(&_service, SIGNAL(receivingText(const QString&)),
            _view, SLOT(onReceivingText(const QString&)));
    connect(&_service, SIGNAL(receivingUrl(const QString&)),
            _view, SLOT(onReceivingUrl(const QString&)));

    connect(&_model, SIGNAL(newDeviceCreated(Device*)),
            this, SLOT(onNewDeviceCreated(Device*)));
    connect(&_model, SIGNAL(deviceRemoved()),
            _view, SLOT(updateDevices()));

    connect(&_updater, SIGNAL(updateNeeded(const QString&,const QString&)),
            _view, SLOT(onUpdateNeeded(const QString&,const QString&)));

    checkForBonjourState();
    _view->updateDevices();
    _view->onHistoryChanged(_service.getHistory());

    _bonjourBrowser->browseForServiceType(QLatin1String("_fdnd._tcp."));

    connect(&_udpDiscoveryTimer, SIGNAL(timeout()), &_udpDiscovery, SLOT(startDiscovery()));
    _udpDiscoveryTimer.start(UDP_DISCOVERY_INTERVAL);
    _udpDiscovery.startDiscovery();

    createSendTo();
}
Exemple #6
0
void Dialog::calcRead() {
    /*if (opAvatarPixmap.isNull()) {
        opAvatarPixmap.loadFromData(readWriteSocket->readAll());
        sendUsername();
        return;
    }*/
    QString info;
    info = readWriteSocket->readAll();
    qDebug() << "calcRead " << info;
    if (opUserName == "") {
        QStringList infoList2 = info.split("@");
        opAvatarFileName = infoList2[0];
        opUserName = infoList2[1];
        opAvatarPixmap.load(opAvatarFileName);
        qDebug() << opAvatarFileName + " " + opUserName;
        prepareGameWidget();
        return;
    }
    if (info == "start") {
        isOpBegin = true;
        if (isMeBegin) {
            isGameBegin = true;
            connect(timer, SIGNAL(timeout()), this, SLOT(onTimerOut()));
            update();
            timer->start();
        }
        return;
    }
    if (info == "requestQuit") {
        timer->stop();
        QMessageBox::StandardButton b1 = QMessageBox::question(NULL, "Request", "对方请求退出游戏");
        if (b1 == QMessageBox::Yes) {
            timer->start();
            sendMessage("agreeQuit");
            InitialGame();
            //this->close();
        }else {
            timer->start();
            sendMessage("disagreeQuit");
        }
        return;
    }
    if (info == "agreeQuit") {
        timer->start();
        InitialGame();
        //this->close();
        return;
    }
    if (info == "disagreeQuit") {
        timer->start();
        QMessageBox::about(NULL, "Result", "对方不同意退出游戏");
        return;
    }
    if (info == "requestSave") {
        timer->stop();
        QMessageBox::StandardButton b2 = QMessageBox::question(NULL, "Request", "对方请求保存残局");
        if (b2 == QMessageBox::Yes) {
            timer->start();
            QTime time = QTime::currentTime();
            map->save(QString::number(time.hour()) + "_" + QString::number(time.minute()) + ".txt");
            sendMessage("agreeSave");
        }else {
            timer->start();
            sendMessage("disagreeSave");
        }
        return;
    }
    if (info == "agreeSave") {
        timer->start();
        QTime time = QTime::currentTime();
        map->save(QString::number(time.hour()) + "_" + QString::number(time.minute()) + ".txt");
        return;
    }
    if (info == "disagreeSave") {
        timer->start();
        QMessageBox::about(NULL, "Result", "对方不同意保存残局");
        return;
    }
    if (info.contains("requestLoad")) {
        timer->stop();
        QStringList list1 = info.split("#");
        QMessageBox::StandardButton b3 = QMessageBox::question(NULL, "Request", "对方请求加载残局" + list1[(int)list1.size() - 1]);
        if (b3 == QMessageBox::Yes) {
            timer->start();
            map->load(list1[(int)list1.size() - 1]);
            update();
            sendMessage("agreeLoad#" + list1[(int)list1.size() - 1]);
        }else {
            timer->start();
            sendMessage("disagreeLoad");
        }
        return;
    }
    if (info == "disagreeLoad") {
        timer->start();
        QMessageBox::about(NULL, "Result", "对方不同意加载残局");
        return;
    }
    if (info.contains("agreeLoad")) {
        timer->start();
        QStringList list2 = info.split("#");
        map->load(list2[(int)list2.size() - 1]);
        update();
        return;
    }
    if (info == "requestWithdraw") {
        timer->stop();
        QMessageBox::StandardButton b4 = QMessageBox::question(NULL, "Request", "对方请求悔棋");
        if (b4 == QMessageBox::Yes) {
            timer->start();
            sendMessage("agreeWithdraw");
            map->pop(player ^ 1);
            renewTime();
        }else {
            timer->start();
            sendMessage("disagreeWithdraw");
        }
        return;
    }
    if (info == "agreeWithdraw") {
        timer->start();
        ++withDrawTime;
        if (withDrawTime >= 2) {
            withdrawButton->setDisabled(true);
        }
        map->pop(player);
        if (checkNoMyChess()) {
            withdrawButton->setDisabled(true);
        }
        renewTime();
        return;
    }
    if (info == "disagreeWithdraw") {
        timer->start();
        QMessageBox::about(NULL, "Result", "对方不同意悔棋");
        return;
    }
    QStringList infoList = info.split("_");
    int x = infoList[0].toInt();
    int y = infoList[1].toInt();
    map->arr[x][y] = player ^ 1;
    map->place.push_back(QPoint(x, y));
    
    changePlayer();
    /*if (map->curPlayer == Map::Black)
        map->curPlayer = Map::White;
    else
        map->curPlayer = Map::Black;*/
    update();
    
    if (gameLogic->checkWin()) {
        gameOver(0);
    }
}