Exemplo n.º 1
0
void VirtTcpC::init()
{
    if (!this->m_sock) {
        this->m_sock = new QTcpSocket();
        QObject::connect(this->m_sock, &QTcpSocket::readyRead, this, &VirtTcpC::onClientReadyRead);
        QObject::connect(this->m_sock, &QTcpSocket::disconnected, this, &VirtTcpC::onClientDisconnected);
        QObject::connect(this->m_sock, SIGNAL(error(QAbstractSocket::SocketError)), 
                         this, SLOT(onClientError(QAbstractSocket::SocketError)));
    }
}
Exemplo n.º 2
0
GameScreenWidget::GameScreenWidget(QWidget *parent, Server *server, Client *client, bool isServer) :
    QWidget(parent), server(server), client(client), isServer(isServer), currentPlayerId(0), currentPlayerIndex(0), waitTurns(0), rankingPosition(1),requestTurns(0),
    ui(new Ui::GameScreenWidget)
{
	ui->setupUi(this);

    ui->Player3->setOrientation(OpponentCardsWidget::Orientation::Vertical);
    ui->Player4->setOrientation(OpponentCardsWidget::Orientation::Vertical);

    if (!isServer)
    {
        connect(client, SIGNAL(onDisconnected()), this, SLOT(onClientDisconnected()));
        connect(client, SIGNAL(onDataReceived(int,QString)), this, SLOT(onClientDataReceived(int,QString)));
        connect(client, SIGNAL(onError(QAbstractSocket::SocketError)), this, SLOT(onClientError(QAbstractSocket::SocketError)));
        ui->labelCurrentPlayer->setText(client->getPlayer()->getName());
        ui->labelPlayer2->hide();
        ui->labelPlayer3->hide();
        ui->labelPlayer4->hide();
        for (int i = 0; i < client->getOtherPlayers().size(); i++)
        {
            Player* p = client->getOtherPlayers().at(i);
            switch(i)
            {
            case 0:
                ui->labelPlayer2->show();
                ui->labelPlayer2->setText(p->getName());
                break;
            case 1:
                ui->labelPlayer3->show();
                ui->labelPlayer3->setText(p->getName());
                break;
            case 2:
                ui->labelPlayer4->show();
                ui->labelPlayer4->setText(p->getName());
                break;
            }
        }
    }