Presenter::Presenter(IView *view) { this->view = view; this->game = new GameController(); QObject* qview = dynamic_cast<QObject*>(view); connect(qview, SIGNAL(onNewGame()), this->game, SLOT(onNewGame())); connect(qview, SIGNAL(onPause()), this->game, SLOT(onPause())); connect(qview, SIGNAL(onRotate()), this->game, SLOT(onRotate())); connect(qview, SIGNAL(onToLeft()), this->game, SLOT(onMoveLeft())); connect(qview, SIGNAL(onToRight()), this->game, SLOT(onMoveRight())); connect(qview, SIGNAL(onSpeedup()), this->game, SLOT(onSpeedup())); connect(qview, SIGNAL(onEndGame()), this->game, SLOT(onEnd())); connect(game, SIGNAL(onStateChanged()), this, SLOT(StateChange())); connect(game, SIGNAL(onGameEnd()), this, SLOT(EndGame())); // instead of speedup connect(qview, SIGNAL(onMakeMove()), this->game, SLOT(onMove())); }
MainMenuScene::MainMenuScene(AppContext& appContext): appContext(appContext) { staticImages = appContext.getDevice()->getVideoDriver()->getTexture("graphics/mainmenu.png"); // load positions of static images from XML file irr::io::IFileSystem* filesys = appContext.getDevice()->getFileSystem(); irr::io::IReadFile* rectanglesFile = filesys->createAndOpenFile(L"graphics/mainmenu.xml"); irr::io::IXMLReader* reader = filesys->createXMLReader(rectanglesFile); loadRectangleList(reader, staticImagesRects); reader->drop(); rectanglesFile->drop(); // create menu arcadeMenu = std::make_shared<ArcadeMenu>(appContext.getDevice()->getTimer(), appContext.getDevice()->getVideoDriver()); addListener(arcadeMenu); ArcadeMenuNode* rootNode = new ArcadeMenuNode(); ArcadeMenuNode* pressStartNode = new ArcadeMenuNode(staticImages, staticImagesRects[HashedString("pressstart")]); ArcadeMenuNode* newGameNode = new ArcadeMenuNode(staticImages, staticImagesRects[HashedString("newgame")]); newGameNode->onClickAction = [this]{ onNewGame(); }; ArcadeMenuNode* optionsNode = new ArcadeMenuNode(staticImages, staticImagesRects[HashedString("options")]); ArcadeMenuNode* quitNode = new ArcadeMenuNode(staticImages, staticImagesRects[HashedString("quit")]); quitNode->onClickAction = [this]{ onQuitGame(); }; rootNode->addChild(pressStartNode); pressStartNode->addChild(newGameNode); pressStartNode->addChild(optionsNode); pressStartNode->addChild(quitNode); arcadeMenu->setRootNode(rootNode); if (!loadControlSchemes(L"save/controls.xml", appContext.getDevice()->getFileSystem(), controlSchemes)) { std::cout << "Failed to load controls." << std::endl; } else { for (size_t i = 0; i < controlSchemes.size(); i++) { arcadeMenu->addControlScheme(&controlSchemes[i]); } } objectEngine.addObject(arcadeMenu); auto fpsDisplay = std::make_shared<FPSDisplay>(appContext); objectEngine.addObject(fpsDisplay); }
void MainWindow::onMoveWasMade(const Grid *newMove) { #ifdef DEBUG_VIEW print("mainWindow->onMoveWasMade"); #endif switchCurrentPlayer(); emit validMove(newMove); } void MainWindow::onMakeMove(Grid *newMove) { #ifdef DEBUG_VIEW printLine2("mainWindow->onMakeMove() with new grid at address: ", newMove); #endif emit makeMove(newMove); } void MainWindow::init() { //Window to widget connect(this, SIGNAL(validMove(const Grid*)), m_mainWidget, SLOT(onUpdateGrid(const Grid*))); connect(this, SIGNAL(tellResetBoard()), m_mainWidget, SLOT(onResetBoard())); //Widget to window connect(m_mainWidget, SIGNAL(onMakeMove(Grid*)), this, SLOT(onMakeMove(Grid *))); connect(m_mainWidget, SIGNAL(swapInHuman(Elements::PlayerType)), this, SLOT(onSwapInHuman(Elements::PlayerType))); connect(m_mainWidget, SIGNAL(swapInAI(Elements::PlayerType)), this, SLOT(onSwapInAI(Elements::PlayerType))); connect(m_mainWidget, SIGNAL(createAI(Elements::PlayerType,QString)), this, SLOT(onCreateAI(Elements::PlayerType,QString))); connect(m_mainWidget, SIGNAL(trainAI(Elements::PlayerType)), this, SLOT(onTrainAI(Elements::PlayerType))); connect(m_mainWidget, SIGNAL(newGame()), this, SLOT(onNewGame())); }
int main(void) { int running = 1; State currState = MainMenu; Game* game = NULL; #ifdef DEBUG game = createGame(); printf("---------------- Open the game successfully \n"); if (!game->setting->useAI) selectOpponent(game); printf("---------------- Changing the game to AI mode \n"); printf("---------------- Going to run 100 times AI vs AI \n"); printf(" Press enter to continue \n"); getchar(); fflush(stdin); while (game->turn < 100) { onAIsTurn(game); } printf("---------------- AI and check is tested \n"); saveLog(game, "log.txt"); printf("---------------- Save record successfully \n"); printf(" Press enter to continue \n"); getchar(); replay(game); printf("---------------- Replay successfully \n"); printf(" Press enter to exit \n"); getchar(); deleteGame(game); printf("---------------- Delete the game successfully \n"); exit(0); #endif game = createGame(); while (running) { switch(currState) { case MainMenu: /*printf("currState = MainMenu\n");*/ currState = onMainMenu(game); break; case NewGame: /*printf("currState = NewGame\n");*/ currState = onNewGame(game); break; case GameMenu: /*printf("currState = GameMenu\n");*/ currState = onGameMain(game); break; case TurnPlayer: /*printf("currState = Player's Turn\n");*/ currState = onPlayersTurn(game); break; case TurnAI: /*printf("currState = AI's Turn\n");*/ currState = onAIsTurn(game); break; case Exit: /*printf("currState = Exit\n");*/ running = 0; break; default: break; } } deleteGame(game); return 0; /* added by Cesar on 1/27 */ }