board_2048::board_2048(const QString &strHost, int nPort, QWidget *parent) : QMainWindow(parent), ui(new Ui::board_2048) { ui->setupUi(this); file = new QFile("best.txt"); file->open(QIODevice::ReadOnly); QString strBest1 = file->readAll(); Score = 0; Best = strBest1.toInt(); TcpSocket = new QTcpSocket(this); TcpSocket->connectToHost(strHost, nPort); connect(TcpSocket, SIGNAL(readyRead()), SLOT(slotReadyRead())); connect(TcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotError(QAbstractSocket::SocketError))); socket = new QUdpSocket(this); QTimer *timer = new QTimer(this); timer->setInterval(500); timer->start(); connect(timer, SIGNAL(timeout()), SLOT(slotSendToServer())); QObject::connect(ui->newGame, SIGNAL(clicked()), this, SLOT(NewGameSlot())); QObject::connect(ui->right_But, SIGNAL(clicked()), this, SLOT(But_clicked(str))); QObject::connect(ui->left_But, SIGNAL(clicked()), this, SLOT(But_clicked())); QObject::connect(ui->up_But, SIGNAL(clicked()), this, SLOT(But_clicked())); QObject::connect(ui->down_But, SIGNAL(clicked()), this, SLOT(But_clicked())); Initialization(); random_Tiles(); this->setFocus(); setFixedSize(440, 700); setWindowTitle("2048"); }
Client::Client(const QString& strHost, int nPort, QWidget* parent /*=0*/ ) : QMainWindow(parent),m_nNextBlockSize(0), ui(new Ui::Client) { ui->setupUi(this); m_pTcpSocket = new QTcpSocket(this); field=new GameFields(this); four = new fourPalubs(this); three= new threePalubs(this); two = new twoPalubs(this); one = new OnePalub(this); msgBox.setText("Game is over! "); msgBox.setInformativeText("Would you like to play again?"); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::Yes); msgBox2.setText("Game is over! "); msgBox2.setInformativeText("Your partner has disconnected from server! Would you like to play again?"); msgBox2.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox2.setDefaultButton(QMessageBox::Yes); setWindowTitle("Battleships"); m_pTcpSocket->connectToHost(strHost, nPort); connect(m_pTcpSocket, SIGNAL(connected()), SLOT(slotConnected())); connect(m_pTcpSocket, SIGNAL(readyRead()), SLOT(slotReadyRead())); connect(m_pTcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotError(QAbstractSocket::SocketError)) ); connect(ui->SendBtn, SIGNAL(clicked()), this, SLOT(slotSendToServer()) ); ui->m_ptxtInfo->setReadOnly(true); ui->fieldLayout->addWidget(field); ui->shipLayout->addWidget(four); ui->shipLayout->addWidget(three); ui->shipLayout->addWidget(two); ui->shipLayout->addWidget(one); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { shipcells[i][j]=0; field->targetMap->cells[i][j]->isEnemy=false; field->fleetMap->cells[i][j]->isEnemy=true; } } for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { SurroundShip[i][j]=0; } } ui->placeShipBtn->setEnabled(false); ui->DoneBtn->setEnabled(false); ui->ClearBtn->setEnabled(false); ui->m_ptxtInfo->setEnabled(false); ui->m_ptxtInput->setEnabled(false); //ui->shipLayout->setEnabled(false); //slotSendToServer("start"); }