void Settings::setPlayerName(const QString& newPlayerName)
{
    if (playerName() != newPlayerName) {
        setValue(PLAYERNAME_KEY, newPlayerName);
        emit playerNameChanged(newPlayerName);
    }
}
Example #2
0
void CUIManager::Options()
{
   CBox box(100, 100, 440, 280, 200, 50, 170);

   CTextBox playerName(180, 120, 20, cfg.Get("GAME", "PlayerName", "Player"));
   gpGeneral->DrawText(msg("menu_playername"), 110, 120, 255, 250, 50);
   CCheckBox cbSound(110, 150, !atoi(cfg.Get("OPTIONS", "NoSound", "0")));
   gpGeneral->DrawText(msg("menu_sound"), 130, 150, 255, 250, 50);
   CCheckBox cbShowCards(110, 180, (atoi(cfg.Get("GAME", "ShowCards", "1")) != 0));
   gpGeneral->DrawText(msg("menu_showcards"), 130, 180, 255, 250, 50);

   CButton btnOK(1, 110, 350, 100, 20, 50, 220, 200);
   gpGeneral->DrawText(msg("menu_ok"), 160 - strlen(msg("menu_ok")) * 4, 352, 255, 250, 50);
   CButton btnCancel(2, 220, 350, 100, 20, 50, 220, 200);
   gpGeneral->DrawText(msg("menu_cancel"), 270 - strlen(msg("menu_cancel")) * 4, 352, 255, 250, 50);

   while (1) {
      int key = gpGeneral->ReadKey() - SDLK_LAST;
      if (key == 1) {
         // OK button pressed
         if (strlen(playerName.Text()) > 0) {
            cfg.Set("GAME", "PlayerName", playerName.Text());
         }
         cfg.Set("OPTIONS", "NoSound", cbSound.Checked() ? "0" : "1");
         cfg.Set("GAME", "ShowCards", cbShowCards.Checked() ? "1" : "0");
         g_fNoSound = !cbSound.Checked();
         return;
      } else if (key == 2) {
         // Cancel button pressed
         return; // do nothing
      }
   }
}
Example #3
0
/**
 * SLOT
 * Takes a shot from the local player.
 * Places the shot on the oponents board or send the
 * coordinates through the network.
 * @param index
 */
bool Battleships::playersShoot(const int index)
{
    setLocalePlayersTurn(false);
    addShoot();
    bool isHit = false;
    if (m_playerMode == SinglePlayer) {
        const Ship *hiddenShip = m_foesGameBoard->shootAt(index);
        if (hiddenShip) {
            setInfoText("You hit one of the ships.");
        } else {
            setInfoText("You shot into the water.");
        }
        if (! m_foesGameBoard->hasUndestroyedShip()) {
            setWinnerName(playerName());
            setCurrentView("GameOverDialog");
        }
        emit botShoot();
    } else {
        m_indexLastShot = index;
        QJsonObject object;
        object.insert("type", "SHOT");
        QJsonObject options;
        QPoint pt = m_foesGameBoard->getPointObject(index);
        options.insert("x", pt.x());
        options.insert("y", pt.y());
        object.insert("options", options);
        QJsonDocument *message = new QJsonDocument(object);
        emit sendMessage(message);
    }

    return isHit;
}
Example #4
0
void Server::processMessage(QString address, int port, QString message){
//    qDebug() << "\nServer::processMessage()";
    int playerIndex = getPlayerIndex(address, port);
    Q_ASSERT(playerIndex >=0);

    if(networkAnswers[playerIndex].isEmpty()){
        nbNetworkAnswers++;
    }
    else{
        qDebug() << "Server::processMessage() : SUPER WEIRD, player sent first message "
                 << networkAnswers[playerIndex] << " then message " <<  message;
    }
    networkAnswers[playerIndex] = message;
//    qDebug() << "Player " << playerIndex << " : " << message;

    // Send immediate feedback
    switch(waitingForMessage){
    case(WAITING_FOR_MESSAGE::INFO):
        if(rxPlayerName.indexIn(message)>=0){
            emit playerName(playerIndex, rxPlayerName.cap(1));
        }
        if(rxStatusAvailable.indexIn(message) >= 0){
            emit playerAvailable(playerIndex, true);
        }
        else{
            emit playerAvailable(playerIndex, false);
        }
        break;
    case(WAITING_FOR_MESSAGE::START):
        if(rxReady.indexIn(message) >= 0){
            emit playerReady(playerIndex, true);
        }
        else{
            emit playerReady(playerIndex, false);
        }
        break;
    case(WAITING_FOR_MESSAGE::PLAY):
        moves[playerIndex] = message;
        emit outputPlayerMessage(playerIndex, message);
        break;
    case(WAITING_FOR_MESSAGE::DONE):
        if(message != "done"){
            manageError(address, port, QAbstractSocket::UnknownSocketError);
        }
        emit outputPlayerMessage(playerIndex, message);
        break;
    default:
        break;
    }

    //
    if(nbNetworkAnswers == addresses.size()){
        // Finish the job
//        qDebug() << "Server::processMessage() : Got all the messages";
        handleTransition();
    }
}
Example #5
0
void Tippeligaen::insertPlayerToTeamOfTheRound(){
    actionShowTeamOfTheRound_triggered();

    QSqlQuery insertTeamOfTheRound;
    insertTeamOfTheRound.prepare("INSERT INTO rundenslag (rundensLagNavn, navn, posisjon, lagNavn)"
                         "VALUES (:rundensLagNavn, :navn, :posisjon, :lagNavn)");
    insertTeamOfTheRound.bindValue(":rundensLagNavn", teamOfTheRoundIdLabel()->text());
    insertTeamOfTheRound.bindValue(":navn", playerName()->text());
    insertTeamOfTheRound.bindValue(":posisjon", playerPosition()->text());
    insertTeamOfTheRound.bindValue(":lagNavn", playerTeam()->text());
    insertTeamOfTheRound.exec();
}
Example #6
0
void Scene::banIP(CString playerIP)
{
	if (server)
	{
		CString playerName("MANUAL-IP-BAN");
		server->banList.push_back(std::pair<CString,CString>(playerName,playerIP) );

		std::ofstream file("main/banlist", std::ios::app | std::ios::binary);
		playerName.resize(32);
		playerIP.resize(16);
		file.write(playerName.s, sizeof(char)*32);
		file.write(playerIP.s, sizeof(char)*16);
	}
}
Example #7
0
int CUIManager::NetGameMenu()
{
   CBox box(100, 100, 440, 280, 200, 50, 170);
   CTextBox playerName(180, 120, 20, cfg.Get("GAME", "PlayerName", "Player"));
   gpGeneral->DrawText(msg("menu_playername"), 110, 120, 255, 250, 50);
   CTextBox pwd(180, 150, 20, cfg.Get("GAME", "ServerPwd", ""));
   gpGeneral->DrawText(msg("menu_password"), 110, 150, 255, 250, 50);
   CTextBox hostName(180, 180, 20, cfg.Get("GAME", "HostName", ""));
   gpGeneral->DrawText(msg("menu_hostaddr"), 110, 180, 255, 250, 50);

   CButton btnServer(1, 110, 350, 100, 20, 50, 220, 200);
   gpGeneral->DrawText(msg("menu_server"), 160 - strlen(msg("menu_server")) * 4, 352, 255, 250, 50);
   CButton btnClient(2, 220, 350, 100, 20, 50, 220, 200);
   gpGeneral->DrawText(msg("menu_client"), 270 - strlen(msg("menu_client")) * 4, 352, 255, 250, 50);
   CButton btnCancel(3, 330, 350, 100, 20, 50, 220, 200);
   gpGeneral->DrawText(msg("menu_cancel"), 380 - strlen(msg("menu_cancel")) * 4, 352, 255, 250, 50);

   while (1) {
      int key = gpGeneral->ReadKey() - SDLK_LAST;
      if (key == 1) {
         // SERVER button pressed
         if (strlen(playerName.Text()) > 0) {
            cfg.Set("GAME", "PlayerName", playerName.Text());
         }
         cfg.Set("GAME", "ServerPwd", pwd.Text());
         gpGeneral->DrawText(msg("connecting"), 0, 440, 255, 255, 0);
         return 1;
      } else if (key == 2) {
         // CLIENT button pressed
         if (strlen(hostName.Text()) <= 0) {
            continue;
         }
         if (strlen(playerName.Text()) > 0) {
            cfg.Set("GAME", "PlayerName", playerName.Text());
         }
         cfg.Set("GAME", "HostName", hostName.Text());
         cfg.Set("GAME", "ServerPwd", pwd.Text());
         gpGeneral->DrawText(msg("connecting"), 0, 440, 255, 255, 0);
         return 2;
      } else if (key == 3) {
         // Cancel button pressed
         return 0; // do nothing
      }
   }
   return 0;
}
Example #8
0
void CPlayerLevels::AddLevel( const FData& level, const std::string& levelId, std::list<CLevel>& levelList )
{
	FData value;
	value = level.get("PlayerId",value);
	if(!value.isString())
	{
		return;
	}
	std::string playerId(value.asString());
	value = level.get("PlayerName",value);
	std::string playerName(value.asString());
	value = level.get("PlayerSource",value);
	std::string playerSource(value.asString());
	value = level.get("Name",value);
	std::string name(value.asString());
	value = level.get("Data",value);
	std::string ldata(value.asString());
	value = level.get("thumb",value);
	std::string lthumb(value.asString());
	value = level.get("RDate",value);
	std::string relativeDate(value.asString());
	value = level.get("SDate",value);
	std::string date(value.asString());
	value = level.get("Plays",value);
	int plays = value.asInt();
	value = level.get("Votes",value);
	int votes = value.asInt();
	value = level.get("Score",value);
	int score = value.asInt();
	value = level.get("Rating",value);
	float rating = value.asFloat();
	value = level.get("CustomData",value);

	CustomData	customData;
	Json::ValueIterator it = value.begin();
	for(; it != value.end(); it++)
	{
		customData.insert(std::make_pair(it.key().asString(), (*it).asString()));
	}
	
	levelList.push_back( CLevel(name, playerName, playerId,
						playerSource, ldata, lthumb, votes, plays,
						rating, score, date, relativeDate, customData, levelId));
}
Example #9
0
void MainWindow::scanPlayers() {
  ui->menuSelect_Player->clear();
  
  bool enabled = false;
  for (const QString &playerDir : settings->getPlayers()) {
    QDir dir(playerDir);
  
    QActionGroup *group = new QActionGroup(this);
  
    bool checked = false;
    QDirIterator it(dir);
    QList<QAction *> actions;
    while (it.hasNext()) {
      it.next();
      if (it.fileName().endsWith(".plr")) {
        QString name = playerName(it.filePath());
        if (!name.isNull()) {
          QAction *p = new QAction(this);
          p->setCheckable(true);
          p->setActionGroup(group);
          p->setText(name);
          p->setData(it.filePath());
          connect(p, SIGNAL(triggered()),
                  this, SLOT(selectPlayer()));
          if (!checked) {
            p->setChecked(true);
            p->trigger();
          }
          checked = true;
          actions.append(p);
        }
      }
    }
    if (!actions.isEmpty()) {
      ui->menuOpen_World->addSection(playerDir);
      ui->menuSelect_Player->addActions(actions);
      enabled = true;
    }
  }
  ui->menuSelect_Player->setDisabled(!enabled);
}
Example #10
0
void LoginState::createGUIWindow()
{
  assert(pGui);

    // Load the previous login settings from login.cfg, if one exists
  std::string ipAddress(""), playerName("nameless newbie");
  float colorSelection = 0.0f;
  Ogre::ConfigFile loginConfig;
  try {
      loginConfig.load(bundlePath() + "login.cfg");
      ipAddress = loginConfig.getSetting("IPaddress");
      playerName = loginConfig.getSetting("PlayerName");
      if (!from_string<float>(colorSelection, loginConfig.getSetting("PlayerColor"), std::dec))
        colorSelection = 0.0f;
  } catch (Ogre::FileNotFoundException e) {}

  pGui->setupLoginWindow(ipAddress, playerName, colorSelection);
  pGui->setLoginReceiver(this);

  mViewport = new MenuStateViewport(pSceneManager);
}
Example #11
0
void Tippeligaen::createTeamInfoGroupBox(){
    playerInfoGroupBox = new QGroupBox(tr("Spillerinfo"));
    _shirtLabel = new QLabel();
    _shirtLabel->setAlignment(Qt::AlignRight);
    _shirtLabel->setPixmap(QPixmap(":/bilder/0.png"));

    _playerNameLabel = new QLabel;
    _playerNameLabel->setText(tr("Spillernavn: "));
    _playerPositionLabel = new QLabel;
    _playerPositionLabel->setText(tr("Posisjon: "));
    _playerTeamLabel = new QLabel;
    _playerTeamLabel->setText(tr("Lag: "));

    deletePlayerButton = new QPushButton;
    deletePlayerButton->setText(tr("Slett"));
    addToTeamOfTheRoundButton = new QPushButton;
    addToTeamOfTheRoundButton->setText(tr("Legg til i rundens lag"));

    _playerName = new QLabel;
    _playerTeam = new QLabel;
    _playerPosition = new QLabel;

    QGridLayout *layout = new QGridLayout;
    layout->addWidget(playerNameLabel(), 0, 0);
    layout->addWidget(playerName(), 0, 1);
    layout->addWidget(playerPositionLabel(), 1, 0);
    layout->addWidget(playerPosition(), 1, 1);
    layout->addWidget(playerTeamLabel(), 2, 0);
    layout->addWidget(playerTeam(), 2, 1);
    layout->addWidget(deletePlayerButton, 3, 0);
    layout->addWidget(addToTeamOfTheRoundButton, 3, 1);
    layout->addWidget(shirtLabel(), 0, 2, 4, 1);
    playerInfoGroupBox->setLayout(layout);

    playerInfoGroupBox->setMinimumHeight(170);
}
Example #12
0
void CharGen::draw(PlayerClass c, PlayerRace r, Gender g, const std::string& name)
{
	const Viewport& view = CharGen::view;
	TCODConsole window(view.width, view.height);
	int imgWidth, imgHeight;

	TCODConsole playerClass(view.width / 3, view.height * 3 / 4 );
	playerClass.printFrame(0, 0, playerClass.getWidth(), playerClass.getHeight(), true, TCOD_BKGND_DEFAULT, "Class");
	if (c == NUM_CLASS)
	{
		for (int i=0; i<NUM_CLASS; i++)
		{
			playerClass.printEx(2, 2 + 2*i, TCOD_BKGND_DEFAULT, TCOD_LEFT, "%c - %s", util::letters[i], CLASS_NAMES[i].c_str());
		}
		playerClass.printEx(2, playerClass.getHeight() - 3, TCOD_BKGND_DEFAULT, TCOD_LEFT, "r - random");
	}
	else
	{
		std::stringstream ss;
		ss << "assets/chargen/class-" << CLASS_NAMES[c] << ".png";
		TCODImage classImage(ss.str().c_str());
		classImage.setKeyColor(TCODColor::fuchsia);
		classImage.getSize(&imgWidth, &imgHeight);
		classImage.blitRect(&playerClass, playerClass.getWidth() / 2 - imgWidth / 2, 3);
		playerClass.printEx(playerClass.getWidth() / 2, playerClass.getHeight() - 5, TCOD_BKGND_DEFAULT, TCOD_CENTER, "%s", CLASS_NAMES[c].c_str());
	}
	TCODConsole::blit(&playerClass, 0, 0, 0, 0, &window, 0, 0, 1.f, 1.f);

	TCODConsole playerRace(view.width / 3, view.height * 3 / 4 );
	playerRace.printFrame(0, 0, playerRace.getWidth(), playerRace.getHeight(), true, TCOD_BKGND_DEFAULT, "Race");
	if (c != NUM_CLASS && r == NUM_RACE)
	{
		for (int i=0; i<NUM_RACE; i++)
		{
			if (ClassRace[c][i])	playerRace.printEx(2, 2 + 2*i, TCOD_BKGND_DEFAULT, TCOD_LEFT, "%c - %s", util::letters[i], RACE_NAMES[i].c_str());
		}
		playerRace.printEx(2, playerRace.getHeight() - 2, TCOD_BKGND_DEFAULT, TCOD_LEFT, "r - random");
	}
	else if (r != NUM_RACE)
	{
		std::stringstream ss;
		ss << "assets/chargen/race-" << RACE_NAMES[r] << ".png";
		TCODImage raceImage(ss.str().c_str());
		raceImage.setKeyColor(TCODColor::fuchsia);
		raceImage.getSize(&imgWidth,&imgHeight);
		raceImage.blitRect(&playerRace, playerRace.getWidth() / 2 - imgWidth / 2, 3);
		playerRace.printEx(playerRace.getWidth() / 2, playerRace.getHeight() - 5, TCOD_BKGND_DEFAULT, TCOD_CENTER, "%s", RACE_NAMES[r].c_str());
	}
	TCODConsole::blit(&playerRace, 0, 0, 0, 0, &window, playerClass.getWidth(), 0, 1.f, 1.f);

	TCODConsole playerGender(view.width / 3, view.height * 3 / 4 );
	playerGender.printFrame(0, 0, playerGender.getWidth(), playerGender.getHeight(), true, TCOD_BKGND_DEFAULT, "Gender");
	if (r != NUM_RACE && g == NUM_GENDER)
	{
		for (int i=0; i<NUM_GENDER; i++)
		{
			playerGender.printEx(2, 2 + 2*i, TCOD_BKGND_DEFAULT, TCOD_LEFT, "%c - %s", util::letters[i], GENDER_NAMES[i].c_str());
		}
		playerGender.printEx(2, playerGender.getHeight() - 2, TCOD_BKGND_DEFAULT, TCOD_LEFT, "r - random");
	}
	else if (g != NUM_GENDER)
	{
		std::stringstream ss;
		ss << "assets/chargen/gender-" << GENDER_NAMES[g] << ".png";
		TCODImage genderImage(ss.str().c_str());
		genderImage.setKeyColor(TCODColor::fuchsia);
		genderImage.getSize(&imgWidth, &imgHeight);
		genderImage.blitRect(&playerGender, playerGender.getWidth() / 2 - imgWidth / 2, 3);
		playerGender.printEx(playerGender.getWidth() / 2, playerGender.getHeight() - 5, TCOD_BKGND_DEFAULT, TCOD_CENTER, "%s", GENDER_NAMES[g].c_str());
	}
	TCODConsole::blit(&playerGender, 0, 0, 0, 0, &window, playerClass.getWidth() + playerRace.getWidth(), 0, 1.f, 1.f);

	TCODConsole playerName(view.width, view.height - view.height * 3 / 4);
	playerName.printFrame(0, 0, playerName.getWidth(), playerName.getHeight(), true, TCOD_BKGND_DEFAULT, "Name");
	if (g != NUM_GENDER) playerName.printEx(20, playerName.getHeight() / 2, TCOD_BKGND_DEFAULT, TCOD_LEFT, "Name: %s", name.c_str());
	TCODConsole::blit(&playerName, 0, 0, 0, 0, &window, 0, playerClass.getHeight(), 1.f, 1.f);

	TCODConsole::root->clear();
	TCODConsole::blit(&window, 0, 0, 0, 0, TCODConsole::root, view.x, view.y, 1.f, 0.9f);
	TCODConsole::root->flush();
}
Example #13
0
void K3ChessSettings::setPlayerName(const QString& name)
{
   if(name==playerName()) return;
   settings_.setValue("PlayerName", name);
   emit playerNameChanged();
}