/** * Creates a new game according to the settings the user made. * * @param factory Player factory to use to create the players. * @return New game. */ QSharedPointer< ::Game::Game> NewGame::createGame(::Game::Players::Factory& factory) const { QSharedPointer< ::GameLogic::FourInALine::Game> fourInALine; QSharedPointer< ::Game::Game> game; auto firstPlayer = this->createFirstPlayer(factory); auto secondPlayer = this->createSecondPlayer(factory); auto boardConfigurationWidget = this->gameSetupWidget->getBoardConfigurationWidget(); auto timeLimitConfigurationWidget = this->gameSetupWidget->getTimeLimitConfigurationWidget(); auto gameConfigurationWidget = this->gameSetupWidget->getGameConfigurationWidget(); unsigned int nRows = boardConfigurationWidget->getNumberOfRows(); unsigned int nColumns = boardConfigurationWidget->getNumberOfColumns(); unsigned int firstMove = gameConfigurationWidget->getFirstMove(); fourInALine.reset(new ::GameLogic::FourInALine::Game(nRows, nColumns, firstMove)); if (timeLimitConfigurationWidget->hasTimeLimit()) { fourInALine->setTimeLimit(timeLimitConfigurationWidget->getTimeLimit()); fourInALine->setTimeoutAction(timeLimitConfigurationWidget->getTimeoutAction()); } game = QSharedPointer< ::Game::Game>(new ::Game::Game(fourInALine, firstPlayer, secondPlayer)); game->setAllowHint(gameConfigurationWidget->isAllowHintEnabled() && gameConfigurationWidget->getAllowHint()); game->setAllowUndo(gameConfigurationWidget->isAllowUndoEnabled() && gameConfigurationWidget->getAllowUndo()); game->setSaveHighscore(gameConfigurationWidget->isSaveHighscoreEnabled() && gameConfigurationWidget->getSaveHighscore()); return game; }
int main (int argc, char *argv[]) { othelloBoard board; int choice; cout << "Load a game or start a new one?\n"; cout << "1 -> Load a saved board state\n"; cout << "2 -> Start a new game\n"; bool validSelection = false; do { cout << "Selection: "; string str; cin >> str; istringstream iss(str); iss >> choice; if (iss.eof() == false) { cout << "Non-integer input, please try again." << endl; } else if(choice > 2 || choice < 0) { cout << "Integer selection out of range, please try again" << endl; } else { validSelection = true; } } while (!validSelection); othelloGame game (&board); if (choice == 1) game.newGame = false; bool whiteMovesFirst = false; bool cpu1; bool cpu2; float limit; if (game.newGame) { cpu1 = checkCPU(1); cpu2 = checkCPU(2); if (cpu1 || cpu2) { limit = getTimeLimit(); } cout << "New Game\n"; game.firstMove(); } else { string filename; cout << "Give filename of savefile: "; cin >> filename; game.loadGame(filename, whiteMovesFirst, limit); cpu1 = checkCPU(1); cpu2 = checkCPU(2); } heuristicEvaluation h; // humanPlayer, playerId, n, symbol player playerOne (!cpu1, 1, board.n,-1, h); // black player playerTwo (!cpu2, 0, board.n,1, h); // white if (cpu1 || cpu2) { playerOne.limit = limit; playerTwo.limit = limit; } if (whiteMovesFirst) { game.move(playerTwo); game.statusUpdate(); } while (!game.complete) { game.move(playerOne); // player one moves game.move(playerTwo); game.statusUpdate(); // updates value of game.complete }; }
/******************************* Main... *********************************/ int main(int argc, char *argv[]) { clock_t inicial, previous, delta; double deltaTime; /*Primeiramente lemos os parametros passados:*/ interpretaParametros(argc, argv); /*Entao inicializamos nossas coisas, comecando com os graficos...*/ if (allegro_init() != 0) { printf("Incapaz de inicializar o Allegro...\n"); return 1; } set_color_depth(32); if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1024, 768, 0, 0) != 0) { printf("Incapaz de setar o modo grafico/janela. \n"); return 2; } /* set the color palette */ set_palette(desktop_palette); srand( getRandomSeed() ); inicializaEntidades(); inicializaPassageiros(); inicializaBotes(); inicializaDesenho(); /*Qualquer codigo necessario para inicializacao de outras coisas vem aqui.*/ criaAsimov(); inicial = clock(); previous = 0; while (clock() - inicial < CLOCKS_PER_SEC*getTimeLimit() ) { delta = clock() - previous; if (delta > (double)CLOCKS_PER_SEC/(double)getFramesPerSec() ) { previous = clock(); /*Calculo da variacao de tempo (em segundo) entre o ciclo anterior e esse.*/ deltaTime = (double)delta/(double)CLOCKS_PER_SEC; /*===================================================*/ /*executa update aqui (desenho -> logica). */ /*update logico...*/ colisaoGeral(deltaTime); updateGameLogic(deltaTime); updateLogic(deltaTime); /*update grafico...*/ preparaPraDesenho(); updateDesenho(); /*Chama o update grafico de todas entidades...*/ updateScreen(); /*CHECK: >arrumar colisao pra setar a direcao certa depois de uma colisao (a normal da tangente da superficie naquele ponto) >pode ser necessario arrumar passageiro para que ele nao sete explicitamente sua direcao, mas sim que tome a cadeia de markov como "o quanto virar" para algum lado, assim poderemos ter que as entidades possam se mexer em qualquer direcao nesse incrivel mundo R2 continuo :P */ /*====================================================*/ } } /*Qualquer codigo necessario para finalizacao de outras coisas vem aqui.*/ /*Finalmente terminamos esses modulos do programa, liberando toda a memoria usada.*/ terminaDesenho(); allegro_exit(); terminaBotes(); terminaPassageiros(); terminaEntidades(); return 0; }
#include "GatherItemQuestStatus.h" #include "GatherItemQuestInfo.h" #include "PlayerCreature.h" GatherItemQuestStatus* GatherItemQuestInfo::makeQuestStatus(PlayerCreature* pPC ) const throw(Error) { __BEGIN_TRY return new GatherItemQuestStatus(getQuestID(), VSDateTime::currentDateTime().addSecs(getTimeLimit()), m_TargetItemClass, m_TargetItemType, m_TargetNum); __END_CATCH }
// doDraw //--------------------------------------------------------------------------- void GameInfoView::doDraw(const Surface &viewArea, const Surface &clientArea) { char unitsBuf[64]; char killsBuf[64]; char lossesBuf[64]; char fragsBuf[64]; char timeBuf[64]; char pingBuf[64]; char gameBuf[64]; char fpsBuf[64]; iXY pos(2, 2); // Resize the game info rect to nothing so it can be resized based on the text, // to be used in it. gameInfoRect = getClientRect(); //gameInfoRect.max.x = 0; sprintf(gameBuf, "game %s", GameConfig::getGameTypeString() ); checkGameInfoRect(gameBuf); int unitPerPlayer = GameConfig::GetNumberUnits() / GameConfig::GetNumberPlayers(); sprintf(unitsBuf, "units %d/%d", int(UnitInterface::getUnitCount(PlayerInterface::getLocalPlayerIndex())), unitPerPlayer); checkGameInfoRect(unitsBuf); if( GameConfig::GetGameType() == _gametype_fraglimit ) { sprintf(fragsBuf, "frags %d/%d", getPlayerFrags(), GameConfig::GetFragLimit() ); checkGameInfoRect(fragsBuf); } else { sprintf(fragsBuf, "frags NA" ); checkGameInfoRect(fragsBuf); } /* sprintf(killsBuf, "kills %d", getPlayerKills()); checkGameInfoRect(killsBuf); sprintf(lossesBuf, "losses %d", getPlayerLosses()); checkGameInfoRect(lossesBuf); */ if( GameConfig::GetGameType() == _gametype_timelimit ) { sprintf(timeBuf, "time %s/%s", (const char*) getPlayerTime(), (const char*) getTimeLimit() ); checkGameInfoRect(timeBuf); } else { sprintf(timeBuf, "time %s", (const char *) getPlayerTime() ); checkGameInfoRect(timeBuf); } sprintf(pingBuf, "ping %.0f ms", NetworkState::ping_time ); checkGameInfoRect(pingBuf); sprintf(fpsBuf, "FPS %f", TimerInterface::getFPSAvg() ); checkGameInfoRect(fpsBuf); bltViewBackground(viewArea); clientArea.bltStringShadowed(pos, gameBuf, Color::white, Color::black); pos.y += 12; clientArea.bltStringShadowed(pos, unitsBuf, Color::white, Color::black); pos.y += 12; clientArea.bltStringShadowed(pos, fragsBuf, Color::white, Color::black); pos.y += 12; /* clientArea.bltStringShadowed(pos, killsBuf, Color::white, Color::black); pos.y += 12; clientArea.bltStringShadowed(pos, lossesBuf, Color::white, Color::black); pos.y += 12; */ clientArea.bltStringShadowed(pos, timeBuf, Color::white, Color::black); pos.y += 12; clientArea.bltStringShadowed(pos, pingBuf, Color::white, Color::black); pos.y += 12; clientArea.bltStringShadowed(pos, fpsBuf, Color::white, Color::black); pos.y += 12; View::doDraw(viewArea, clientArea); // Make sure the view stays in the screen when the view is resized. //resizeClientArea(gameInfoRect.getSize()); //moveTo(min); } // end GameInfoView::doDraw