/** * Adds a new player. Parameters are read from UI components. */ void WindowPlayers::addPlayer() { Player *player; char *name = fieldName->getText(); //Limit number of players if (gameEngine.getPlayerCount() >= MAX_PLAYERS) { this->sounds.playSound(SOUND_TICK); return; } else { this->sounds.playSound(SOUND_CLICK); } //Default names if (name == NULL) { name = new char[20]; if (newPlayerType > 0) { sprintf(name, "AI %d", aiNumbering); aiNumbering++; } else { sprintf(name, "Player %d", humanNumbering); humanNumbering++; } } //Create player player = new Player(name, gameEngine); player->setColor(colors[playerCount][0], colors[playerCount][1], colors[playerCount][2]); playerCount++; //Set AI switch (newPlayerType) { case 1: //Stupid computer player->setAI(*(new Ai(*player, 0))); break; case 2: //Normal computer player->setAI(*(new Ai(*player, 1))); break; case 3: //Clever computer player->setAI(*(new Ai(*player, 2))); break; } gameEngine.addPlayer(*player); delete [] name; updatePlayers(); fieldName->clear(); }
/** Public driver routine to call * other private update methods */ void Window::update() { updateRink(); updatePlayers(); updatePuck(); updateStats(); // Swap buffers to show the whole thing SDL_Flip(mainSurface); }
/** * Handles mouse up events */ void WindowPlayers::mouseUp(SDL_MouseButtonEvent button) { //Find out if a button was hit UIComponent *component = findComponent(button.x, button.y); //'Start game' button if (component == buttonStart) { this->sounds.playSound(SOUND_CLICK); this->startGame(); } //'Add player' button else if (component == butAdd) { addPlayer(); } //Player type (increase) else if (component == butIncrType) { newPlayerType++; if (newPlayerType > 3) newPlayerType = 0; this->sounds.playSound(SOUND_CLICK); updatePlayerType(); } //Player type (decrease) else if (component == butDecrType) { newPlayerType--; if (newPlayerType < 0) newPlayerType = 3; this->sounds.playSound(SOUND_CLICK); updatePlayerType(); } //'Remove all' button else if (component == butRemoveAll) { gameEngine.removeAllPlayers(); this->humanNumbering = 1; this->aiNumbering = 1; this->playerCount = 0; this->sounds.playSound(SOUND_TICK); updatePlayers(); } redraw(); }
void Server::manageClientMessages() { sf::TcpSocket* toRemove = 0; ClientManager* managerToRemove = 0; for (std::list<ClientManager*>::iterator it = cms.begin(); it!=cms.end(); ++it) { ClientManager* cm = *it; sf::TcpSocket* client = cm->getSocket(); if (selector.isReady(*client)) { MessageObject msg; sf::Packet packet; sf::TcpSocket::Status status = client->receive(packet); packet >> msg; if (status == sf::Socket::Done) { if (msg.type == MessageObject::START && msg.message == "start") { std::cout << "no more player\n"; canConnect = false; } if (msg.type == MessageObject::PLAYER && msg.message == "player") { sf::Mutex mutex; mutex.lock(); sf::Packet packet; client->receive(packet); std::stringstream ss; ss.write((char*)packet.getData(), packet.getDataSize()); //Player* player = getFromPacket<Player>(packet); //Player player; ss >> *player; map->updatePlayer(player); updatePlayers(); mutex.unlock(); } else { sf::Mutex mutex; mutex.lock(); cm->appendMessage(msg); //sendAllExceptSender(msg, *client); sendAll(msg); mutex.unlock(); } }
void Window::processStatisticsPlayers(QHash<QString, QList<StatisticsWebSite::PlayerInfo>> playersHash) { QVariant selectedIndexData = planetTreeView->selectionModel()->currentIndex().data(); for (int i = 0; i < planetTreeModel->rowCount(); i ++) { QStandardItem* planetItem = planetTreeModel->item(i, 0); updatePlayers(planetItem, playersHash); } if (selectedIndexData != planetTreeView->selectionModel()->currentIndex().data()) { // selected item disappeared planetTreeView->selectionModel()->clear(); } planetTreeView->expandAll(); resizeColumnsToContents(); }
void Simulation::update() { updateProjectiles(); updatePlayers(); // remove players that don't have health left. auto pred = [](const std::pair<const std::string, Robot> &robot) { return robot.second.getHealth() <= 0; }; auto it = players.begin(); while ((it = std::find_if(it, players.end(), pred)) != players.end()) { std::string name = it->first; players.erase(it++); deathSignal(name); } simulationStepSignal(); runTime += rules.timeStep; }
void kMancalaMain::unPauseGame(void) { if ( !_gamePaused ) return; if ( !_gameActive ) return; if ( _gameOver ) return; int row = _historyListWidget->currentRow(); int count = _historyListWidget->count(); qDebug("Count: %d, Row: %d", count, row); if ( row != -1 ) { for(int i = count; i != row+1; i--) { _historyListWidget->removeState(i-1); } _historyListWidget->setCurrentRow(-1); emit updateBoard(_board); emit updatePlayers(_players); qApp->processEvents(); } qDebug("Current Row: %d, Count: %d", _historyListWidget->currentRow(), _historyListWidget->count()); _gamePaused = false; _guiBoard->setClickable(true); emit gameUnPause(); if ( _players[PLAYER_1]->getType() == PLAYER_AI && _players[PLAYER_2]->getType() == PLAYER_AI ) emit disableHint(); else emit enableHint(); qApp->processEvents(); if ( _players[_controller->currentPlayer()]->getType() == PLAYER_AI ) { playerAIMove(); } }
LobbyEntry::LobbyEntry(Vector2f size, Vector2f pos, std::string name, int players, int maxPlayers, int id) : Button(pos,size,"", id,true) { m_dimensions.width = size.x; m_dimensions.height = size.y; m_dimensions.left = pos.x; m_dimensions.top = pos.y; m_maxPlayers = maxPlayers; m_players = players; m_ID = id; m_nameText.setFont(MyFonts::getFont(GameFonts::ARIAL)); m_nameText.setString(name); m_nameText.setColor(MyColors.Black); m_nameText.setPosition(m_dimensions.left + LOBBYENTRYBORDER, m_dimensions.top + LOBBYENTRYBORDER); m_numberText.setFont(MyFonts::getFont(GameFonts::ARIAL)); m_numberText.setColor(MyColors.Black); updatePlayers(); }
void LobbyEntry::setMaxPlayers(int maxPlayers) { m_maxPlayers = maxPlayers; updatePlayers(); }
void LobbyEntry::setPlayers(int players) { m_players = players; updatePlayers(); }
void PlayerTrackerClass::onBegin() { updatePlayers(); }
void CMapGenOptions::finalize(CRandomGenerator & rand) { logGlobal->info("RMG settings: players %d, teams %d, computer players %d, computer teams %d, water %d, monsters %d", static_cast<int>(getPlayerCount()), static_cast<int>(getTeamCount()), static_cast<int>(getCompOnlyPlayerCount()), static_cast<int>(getCompOnlyTeamCount()), static_cast<int>(getWaterContent()), static_cast<int>(getMonsterStrength())); if(!mapTemplate) { mapTemplate = getPossibleTemplate(rand); } assert(mapTemplate); if (getPlayerCount() == RANDOM_SIZE) { auto possiblePlayers = mapTemplate->getPlayers().getNumbers(); //ignore all non-randomized players, make sure these players will not be missing after roll possiblePlayers.erase(possiblePlayers.begin(), possiblePlayers.lower_bound(countHumanPlayers() + countCompOnlyPlayers())); assert(!possiblePlayers.empty()); setPlayerCount (*RandomGeneratorUtil::nextItem(possiblePlayers, rand)); updatePlayers(); } if(teamCount == RANDOM_SIZE) { teamCount = rand.nextInt(getPlayerCount() - 1); if (teamCount == 1) teamCount = 0; } if(compOnlyPlayerCount == RANDOM_SIZE) { auto possiblePlayers = mapTemplate->getCpuPlayers().getNumbers(); compOnlyPlayerCount = *RandomGeneratorUtil::nextItem(possiblePlayers, rand); updateCompOnlyPlayers(); } if(compOnlyTeamCount == RANDOM_SIZE) { compOnlyTeamCount = rand.nextInt(std::max(compOnlyPlayerCount - 1, 0)); } if(waterContent == EWaterContent::RANDOM) { waterContent = static_cast<EWaterContent::EWaterContent>(rand.nextInt(EWaterContent::NONE, EWaterContent::ISLANDS)); } if(monsterStrength == EMonsterStrength::RANDOM) { monsterStrength = static_cast<EMonsterStrength::EMonsterStrength>(rand.nextInt(EMonsterStrength::GLOBAL_WEAK, EMonsterStrength::GLOBAL_STRONG)); } assert (vstd::iswithin(waterContent, EWaterContent::NONE, EWaterContent::ISLANDS)); assert (vstd::iswithin(monsterStrength, EMonsterStrength::GLOBAL_WEAK, EMonsterStrength::GLOBAL_STRONG)); //rectangular maps are the future of gaming //setHeight(20); //setWidth(50); logGlobal->trace("Player config:"); int humanPlayers = 0, cpuOnlyPlayers = 0, AIplayers = 0; for (auto player : players) { std::string playerType; switch (player.second.getPlayerType()) { case EPlayerType::AI: playerType = "AI"; AIplayers++; break; case EPlayerType::COMP_ONLY: playerType = "computer only"; cpuOnlyPlayers++; break; case EPlayerType::HUMAN: playerType = "human only"; humanPlayers++; break; default: assert(false); } logGlobal->trace("Player %d: %s", player.second.getColor(), playerType); } setCompOnlyPlayerCount(cpuOnlyPlayers); //human players are set automaticlaly (?) logGlobal->info("Final player config: %d total, %d cpu-only", players.size(), (int)getCompOnlyPlayerCount()); }
Window::Window() { // Set window title SDL_WM_SetCaption("RoboHockey",NULL); // Create surfaces mainSurface = SDL_SetVideoMode(1024, 768, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_SRCALPHA); rinkSurface = IMG_Load("data/surfaces/rink.png"); SDL_SetColorKey(rinkSurface, SDL_RLEACCEL, rinkSurface->format->colorkey); statSurface = IMG_Load("data/surfaces/stat.png"); puck = IMG_Load("data/objects/puck.png"); SDL_SetColorKey(puck, SDL_RLEACCEL, puck->format->colorkey); greenPlayer = IMG_Load("data/objects/green_player.png"); SDL_SetColorKey(greenPlayer, SDL_RLEACCEL, greenPlayer->format->colorkey); bluePlayer = IMG_Load("data/objects/blue_player.png"); SDL_SetColorKey(bluePlayer, SDL_RLEACCEL, bluePlayer->format->colorkey); // Blit the surfaces SDL_BlitSurface(rinkSurface, NULL, mainSurface, NULL); // Statistics surface statRect.x = rinkSurface->w; statRect.w = mainSurface->w - rinkSurface->w; statRect.y = 0; statRect.h = mainSurface->h; SDL_BlitSurface(statSurface, NULL, mainSurface, &statRect); // Puck updatePuck(); // Create Font(s) arcade = TTF_OpenFont("data/fonts/arcade.ttf", 72); arcadeSmall = TTF_OpenFont("data/fonts/arcade.ttf", 48); nameFont = TTF_OpenFont("data/fonts/sb.ttf", 12); // Players withPuck.x = 44; withPuck.y = 0; withPuck.w = 44; withPuck.h = 44; withoutPuck.x = 0; withoutPuck.y = 0; withoutPuck.w = 44; withoutPuck.h = 44; updatePlayers(); // Set up text rectangles clockRect.x = 695; clockRect.y = 65; clockRect.w = 154; clockRect.h = 34; homeScore.x = 605; homeScore.y = 175; homeScore.w = 33; homeScore.h = 34; period.x = 753; period.y = 195; period.w = 33; period.h = 34; awayScore.x = 902; awayScore.y = 175; awayScore.w = 33; awayScore.h = 34; homeShots.x = 660; homeShots.y = 340; homeShots.w = 22; homeShots.h = 23; awayShots.x = 852; awayShots.y = 340; awayShots.w = 22; awayShots.h = 23; // Default texts drawText(&clockRect, arcade, (Game::instance()->getClock()).c_str()); drawText(&homeScore, arcade, "0"); drawText(&period, arcade, "1"); drawText(&awayScore, arcade, "0"); drawText(&homeShots, arcadeSmall, "0"); drawText(&awayShots, arcadeSmall, "0"); // Swap buffers to show the whole thing SDL_Flip(mainSurface); }