Пример #1
0
PlayerStatus::PlayerStatus(QGraphicsItem* parentItem)
	: LabelButton("", parentItem)
{
	BotNeumannApp* app = BotNeumannApp::getInstance();
	connect(app->getPlayerManager(), SIGNAL(playerChanged(Player*)), this, SLOT(playerChanged(Player*)));
	playerChanged( app->getCurrentPlayer() );
}
Пример #2
0
void DixitGame::update(const DixitGame &dixitGame)
{
    if (dixitGame.status() != status())
        setStatus(dixitGame.status());
    if (dixitGame.description() != description())
        setDescription(dixitGame.description());
    if (dixitGame.table() != table())
        setTable(dixitGame.table());
    if (dixitGame.constPlayerList().size() != constPlayerList().size())
    {
        p = dixitGame.constPlayerList();
        emit playerListChanged();
    }
    else
    {
        bool changed = false;
        for (int i = 0; i < constPlayerList().size(); i++)
            if (dixitGame.constPlayerList().at(i) != constPlayerList().at(i))
            {
                p[i] = dixitGame.constPlayerList().at(i);
                emit playerChanged(&p[i]);
                changed = true;
            }
        if (changed)
            emit playerListChanged();
    }
}
Пример #3
0
void GameMenuScene::setupButtons(LinearLayout* rightLayout)
{
	// A label that shows the nickname of the current player. Press it to change player
	playerStatus = new PlayerStatus(this);
	playerStatus->setPaddings(0.2);
	rightLayout->addItem(playerStatus, 1.0 / 6.0);
	connect(playerStatus, SIGNAL(pressed()), this, SLOT(playerControlPressed()));
	PlayerManager* playerManager = BotNeumannApp::getInstance()->getPlayerManager();
	connect(playerManager, SIGNAL(playerChanged(Player*)), this, SLOT(playerChanged(Player*)));

	// Create the buttons for each game mode and configuration
	const QString buttonBackground("gm_button_background");
	trainingButton = new SvgButton(buttonBackground, this, tr("Training"));
	missionsButton = new SvgButton(buttonBackground, this, tr("Missions"));
	collaborationButton = new SvgButton(buttonBackground, this, tr("Collaboration"));
	createButton = new SvgButton(buttonBackground, this, tr("Create"));

	// Add the menu buttons to the layout
	rightLayout->addItem( trainingButton, 1.0 / 6.0 );
	rightLayout->addItem( missionsButton, 1.0 / 6.0 );
	rightLayout->addItem( collaborationButton, 1.0 / 6.0 );
	rightLayout->addItem( createButton, 1.0 / 6.0 );

	// React to each button change
	connect(trainingButton, SIGNAL(pressed()), this, SLOT(trainingButtonPressed()));
	connect(missionsButton, SIGNAL(pressed()), this, SLOT(missionsButtonPressed()));
	connect(collaborationButton, SIGNAL(pressed()), this, SLOT(collaborationButtonPressed()));
	connect(createButton, SIGNAL(pressed()), this, SLOT(createButtonPressed()));

	// Disable if there is not an active player
	playerChanged( BotNeumannApp::getInstance()->getCurrentPlayer() );

	// Create the info, rewards and config buttons
	setupConfigButtons(rightLayout);
}
Пример #4
0
Player* PlayerManager::setCurrentPlayer(Player* player)
{
	if ( currentPlayer && currentPlayer != player )
		currentPlayer->deleteLater();
	currentPlayer = player;
	saveLastPlayer();
	emit playerChanged(currentPlayer);
	return currentPlayer;
}
Пример #5
0
Dialog::Private::Private(Dialog *parent)
    : q(parent)
{
    ui.setupUi(q);

    recommender.setName("npb-similar-player");
    recommender.setTimeout(10);

    bool learn = recommender.getAllRows().isEmpty();

    QFile file(":/baseball.csv");
    file.open(QFile::ReadOnly | QFile::Text);
    QTextStream stream(&file);
    QStringList fields = QStringList() << "チーム" << "打率" << "試合数" << "打席" << "打数" << "安打" << "本塁打" << "打点" << "盗塁" << "四球" << "死球" << "三振" << "犠打" << "併殺打" << "長打率" << "出塁率" << "OPS" << "RC27" << "XR27";

    while (!stream.atEnd()) {
        QStringList list = stream.readLine().split(",");
        QString id = list.takeFirst();
        if (learn) {
            QVariantMap data;
            data.insert(fields.at(0), list.at(0));
            for(int i = 1; i < fields.length(); i++) {
                data.insert(fields.at(i), list.at(i).toFloat());
            }
            recommender.updateRow(id, data);
        }
        ui.player->addItem(id);
    }
    file.close();

    connect(ui.buttonBox, &QDialogButtonBox::rejected, q, &QDialog::close);

    connect(ui.player, &QComboBox::currentTextChanged, [this](const QString &id) {
        playerChanged(id);
    });
    playerChanged(ui.player->currentText());
}
Пример #6
0
bool GLView::record( const QString& fileName ) {
	if (!m_player) return false;
	
	QString fn(fileName);
	fn.replace('/','\\');

    quicktime_recorder *recorder = quicktime_recorder::create(fn.toLatin1(), 
        m_player->get_width(), m_player->get_height(), m_player->get_fps());
    if (!recorder) {
		QMessageBox::critical(this, "Error", "Creation of QuickTime recorder failed!");
		return false;
	}

	parentWidget()->setEnabled(false);

	QProgressDialog progress("Recording...", "Abort", 0, m_player->get_duration(), this);
	progress.setWindowModality(Qt::WindowModal);

	makeCurrent();

	int nextTime = 0;
	while (nextTime >= 0) {
		progress.setValue(nextTime);
		m_player->set_time(nextTime);
		m_player->update();

		updateAll();
		glFinish();

		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_dst.get_id(), 0);
		glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
		glReadPixels(0,0, m_dst.get_width(), m_dst.get_height(), GL_BGRA_EXT, GL_UNSIGNED_BYTE, recorder->get_buffer());
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
		recorder->append_frame();

		nextTime = m_player->get_next_time(nextTime);

		if (progress.wasCanceled())
			break;
	}

	recorder->finish();
	delete recorder;

	parentWidget()->setEnabled(true);
	playerChanged();
	return true;
}
Пример #7
0
bool PlayerManager::reloadLastPlayer()
{
	// Get the last player id from the settings
	QSettings settings;
	const QVariant& playerId = settings.value(sk("Players/LastPlayer"));
	if ( playerId.isNull() ) return false;
	Q_ASSERT(currentPlayer == nullptr);

	// Create a Player object and load it from settings using the ID
	currentPlayer = new Player(playerId.toByteArray());
	currentPlayer->load();

	// Done
	emit playerChanged(currentPlayer);
	return true;
}
Пример #8
0
void DixitGame::ready(DixitGame::UniqueId uid)
{
    Player *pp = findPlayer(uid);
    if (pp == nullptr)
        return;
    if (pp->getReady())
        return;
    pp->setReady();
    emit playerChanged(pp);
    message(QString("玩家%1准备就绪。").arg(pp->getId()));
    if (notYetReady() > 0)
        setMessage(QString("还有%1位玩家没有准备。").arg(notYetReady()));
    else
    {
        setMessage();
        emit gameBegin();
    }
}
Пример #9
0
bool PlayerManager::renamePlayer(const QByteArray& playerId, const QString& newNickname)
{
	if ( currentPlayer && currentPlayer->getId() == playerId )
	{
		currentPlayer->setNickname(newNickname);
		currentPlayer->save();
		emit playerChanged(currentPlayer);
	}
	else
	{
		Player* player = findPlayerById(playerId);
		if ( player )
		{
			player->setNickname(newNickname);
			player->save();
		}
	}
	return true;
}
Пример #10
0
KHPlayersStatus::KHPlayersStatus(KHMatch *m, QWidget *parent, const char *name) : QVBox(parent, name), m_onTurn(true)
{
	setCaption(i18n("Status"));
	
	m_white = m->white()->face();
	m_black = m->black()->face();
	
	setIcon(m_white);
	
	m_whiteBox = new KHPlayerInfoBox(m->white(), this, m->clock()->displayLight());
	m_whiteBox->setPaletteBackgroundColor( Qt::gray);
	m_whiteBox->setPaletteForegroundColor( Qt::black);

	m_blackBox = new KHPlayerInfoBox(m->black(), this, m->clock()->displayBlack());
	m_blackBox->setPaletteBackgroundColor( Qt::black );
	m_blackBox->setPaletteForegroundColor( Qt::gray );
	
	connect(m->clock(), SIGNAL(playerChanged()), this, SLOT(updateIcon()));
	
}
Пример #11
0
bool GLView::open(const QString& fileName) {
    #ifdef HAVE_QUICKTIME
    if (m_player) {
        m_image = QImage();
        delete m_player;
        m_player = 0;
    }
    #endif
    
    m_image = QImage(fileName);
    #ifdef HAVE_QUICKTIME
    if (m_image.isNull() && m_haveQuickTime) {
	    std::string pathStd = fileName.toStdString();
	    #ifdef Q_OS_WIN
	    for (std::string::iterator p = pathStd.begin(); p != pathStd.end(); ++p) if (*p == '/') *p = '\\';
	    #endif
        m_player = quicktime_player::open(pathStd.c_str());
        if (m_player) {
            m_image = QImage((uchar*)m_player->get_buffer(), m_player->get_width(), m_player->get_height(), QImage::Format_RGB32);
            m_player->set_time(0);
            m_player->update();
        }
    } else
    #endif
    {
    	m_image = m_image.convertToFormat(QImage::Format_RGB32);
    }

    if (!m_image.isNull()) {

        int w = m_image.width();
        int h = m_image.height();
        float *noise = new float[w * h];
        {   
            srand(1);
            float *p = noise;
            for (int j = 0; j < h; ++j) {
                for (int i = 0; i < w; ++i) {
                    *p++ = 0.5f + 2.0f * ((float)rand() / RAND_MAX - 0.5); 
                }
            }
            p = noise;
            for (int j = 0; j < h; ++j) {
                *p = (3*p[0] + p[1]) / 4;
                ++p;
                for (int i = 1; i < w-1; ++i) {
                    *p = (p[-1] + 2*p[0] + p[1]) / 4;
                    ++p;
                }
                *p = (p[-1] + 3*p[0]) / 4;
                ++p;
            }
            p = noise;
            for (int i = 0; i < w; ++i) {
                *p = (3*p[0] + p[w]) / 4;
                ++p;
            }
            for (int j = 1; j < h-1; ++j) {
                for (int i = 0; i < w; ++i) {
                    *p = (p[-w] + 2*p[0] + p[w]) / 4;
                    ++p;
                }
            }
            for (int i = 0; i < w; ++i) {
                *p = (p[-w] + 3*p[0]) / 4;
                ++p;
            }
        }
        makeCurrent();
        m_noise = texture_2d(GL_LUMINANCE16F_ARB, w, h, GL_LUMINANCE, GL_FLOAT, noise);
		assert(glGetError() == GL_NO_ERROR);
		delete[] noise;
    } else {
        QMessageBox::critical(this, "Error", QString(
			"QuickTime can't load '%1'. To get further information "\
			"please try load the file with the QuickTime player.").arg(fileName));
    }

	playerChanged();
	setOrigin(QPoint(0,0));
	setZoom(1.0);
	updateAll();
	this->fileName = fileName;

	return !m_image.isNull();
}
Пример #12
0
void GameHandler::changeCurrentPlayer(const bool undo) {
	this->deselectTiles();
	
	this->players[this->getNextPlayerId()]->startTurn();
	this->players[this->currentPlayer]->finishTurn();
	
	if (!undo && this->lastMoveId != (int)this->turnsHistory[currentTurnId].size() - 1)
		this->dropHistoryTail();
	
	if (!undo) {
		this->historyHandler.finishTurn();
		//for (int i = 0; i < PLAYERS_QTY; ++i)
			//this->players[i]->play(this->players[this->currentPlayer]->getPlayerInfo().player,
				//this->turnsHistory[this->currentTurnId]);

		if ((int)this->turnsHistory.size() <= this->currentTurnId + 1)
			this->turnsHistory.push_back(vector<Move>());
		if ((int)this->movesLeft.size() <= this->currentTurnId + 1)
			this->movesLeft.push_back(make_pair(2, 1));
		
		this->movesLeft[this->currentTurnId] = make_pair(this->game.getMovesLeft(), this->game.getPassessLeft());
		this->currentTurnId++;
		this->lastMoveId = -1;
	} else {
// 		qDebug("player change for undo");
		bool tmp = true;
		
		if (this->currentTurnId > 0) {
 			if (this->turnsHistory[this->currentTurnId].empty()) {
//  				this->turnsHistory.pop_back();
				tmp = false;
			}
			
			this->movesLeft.pop_back();
			
			this->currentTurnId--;
			
			//TODO stopped here
			//if (tmp)
				//this->sendUndoTurn(this->players[this->currentPlayer]->getPlayerInfo().player,
					//this->currentTurnId + 1);
			
			this->lastMoveId = this->turnsHistory[this->currentTurnId].size() - 1;
		} else {
			this->currentTurnId = 0;
			this->lastMoveId = -1;
		}
	}
	
	this->currentPlayer = this->getNextPlayerId();
	this->game.setCurrentPlayer(engine::getOppositePlayer(this->game.getCurrentPlayer()), 
		this->movesLeft[this->currentTurnId].first, this->movesLeft[this->currentTurnId].second);
	qDebug("Next player! %s", qPrintable(this->players[this->currentPlayer]->getPlayerInfo().name));
	
	if (this->hintAI != NULL)
		this->hintAI->gameChanged(this->game);
	
	//hashes
	if (!undo) {
		//new configuration
		QString h = QString::fromStdString(this->game.getHash());
		
		if (this->hashes.contains(h)) {	//state repetition - draw
			this->game.setCurrentPlayer(NONE);
			emit gameFinished();
			return;
		}
		this->hashes.insert(h);
		this->hashesHistory.push_back(h);
	} else {
		this->hashes.remove(hashesHistory.back());
		this->hashesHistory.pop_back();
	}
	
	emit playerChanged();
}