예제 #1
0
bool
VolumeInformation::xmlHeaderFile(QString volfile)
{
  bool xmlheader = false;

  QFile qfl(volfile);
  if (!qfl.open(QIODevice::ReadOnly | QIODevice::Text))
    {
      QMessageBox::information(0, "Cannot open", volfile);
      return false;
    }
  QString line = qfl.readLine();
  // interested in second line
  line = qfl.readLine();
  line = line.trimmed();
  //QMessageBox::information(0, volfile, "["+line+"]");
  if (line == "<PvlDotNcFileHeader>")
    xmlheader = true;
  qfl.close();

  return xmlheader;
}
예제 #2
0
파일: new_game.cpp 프로젝트: cjlano/eliot
PublicGame * NewGame::createGame() const
{
    // Game parameters
    GameParams params(m_dic);
    if (radioButtonTraining->isChecked())
        params.setMode(GameParams::kTRAINING);
    else if (radioButtonFreeGame->isChecked())
        params.setMode(GameParams::kFREEGAME);
    else if (radioButtonDuplicate->isChecked())
        params.setMode(GameParams::kDUPLICATE);
    else if (radioButtonArbitration->isChecked())
        params.setMode(GameParams::kARBITRATION);
    else
        params.setMode(GameParams::kTOPPING);

    if (checkBoxJoker->isChecked())
        params.addVariant(GameParams::kJOKER);
    if (checkBoxExplosive->isChecked())
        params.addVariant(GameParams::kEXPLOSIVE);
    if (checkBox7Among8->isChecked())
        params.addVariant(GameParams::k7AMONG8);

    // Load the master game if needed
    Game *masterGame = NULL;
    if (checkBoxUseMaster->isChecked())
    {
        const QString &path = lineEditMaster->text();
        try
        {
            masterGame = GameFactory::Instance()->load(lfq(path), m_dic);
        }
        catch (const GameException &e)
        {
            // Should not happen, since we have already done validation.
            // But the user may have changed the file itself after the validation...
            emit notifyProblem("Error loading master game: " + qfl(e.what()));
            // Give up loading the game
            return NULL;
        }
    }

    // Create the game
    Game *tmpGame = GameFactory::Instance()->createGame(params, masterGame);
    PublicGame *game = new PublicGame(*tmpGame);

    // Add the players
    if (!radioButtonTraining->isChecked() &&
        !radioButtonTopping->isChecked())
    {
        const QList<PlayerDef> &players = m_helper->getPlayers(false);
        set<QString> allNames;
        for (int num = 0; num < players.size(); ++num)
        {
            QString name = players.at(num).name;
            if (name == "")
                name = _q("Player %1").arg(num + 1);
            // Ensure uniqueness of the players names
            if (allNames.find(name) != allNames.end())
            {
                int n = 2;
                while (allNames.find(name + QString(" (%1)").arg(n)) != allNames.end())
                {
                    ++n;
                }
                name += QString(" (%1)").arg(n);
            }
            allNames.insert(name);

            QString type = players.at(num).type;
            Player *player;
            if (type == _q(kHUMAN))
                player = new HumanPlayer;
            else
            {
                double level = players.at(num).level.toInt();
                player = new AIPercent(level / 100.);
            }
            player->setName(wfq(name));
            game->addPlayer(player);
        }
    }
    else
    {
        game->addPlayer(new HumanPlayer);
    }

    return game;
}