MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); computer_timer.setSingleShot(true); connect(&computer_timer, SIGNAL(timeout()), this, SLOT(computerPlay())); //connect(this, SIGNAL(gameOver(QString)), this, SLOT(setGameOver(QString))); //connect(ui->gameBoard, SIGNAL(boardLeftClicked(QString,QString)),this,SLOT(doPlay(QString))); connect(ui->gameBoard, SIGNAL(boardLeftClicked(QString)),this,SLOT(doPlay(QString))); connect(&players, SIGNAL(blackScore(QString)), this, SLOT(updateBlackScore(QString))); connect(&players, SIGNAL(whiteScore(QString)), this, SLOT(updateWhiteScore(QString))); connect(>p, SIGNAL(move(QString,QString)),ui->gameBoard,SLOT(placeStone(QString,QString))); connect(>p, SIGNAL(move(QString,QString)),this,SLOT(addHistory(QString,QString))); connect(>p, SIGNAL(stoneListing(QString,QStringList)), ui->gameBoard, SLOT(checkStones(QString,QStringList))); connect(>p, SIGNAL(hints(QString,QStringList)), ui->gameBoard, SLOT(showTopMoves(QString,QStringList))); connect(>p, SIGNAL(blackScore(QString)), this, SLOT(updateBlackScore(QString))); connect(>p, SIGNAL(whiteScore(QString)), this, SLOT(updateWhiteScore(QString))); connect(&engine.process, SIGNAL(started()), this, SLOT(engineStarted())); readSettings(); engine.addProgramArg("--mode gtp"); engine.addProgramArg("--level 1"); engine.start(); gtp.setEngine(engine); ui->labelBlack->setStyleSheet("#labelBlack { color:#000000; background: #785229;}"); ui->labelWhite->setStyleSheet("#labelWhite { color:#FFFFFF; background: #785229;}"); }
void play() { //randomly assign yourself as black or white srand((int)time(NULL)); int playerNum = rand() % 2; cout << "By random selection, you are " << WhichPlayer(playerNum) << endl; Alex_Ayerdi * b = new Alex_Ayerdi(); if (playerNum) b->setPlayer(playerNum); //if 1 then set as 1 else b->setPlayer(-1); //else set as -1 int humanPlayer = b->getPlayer(); int cpuPlayer = humanPlayer == 1 ? -1 : 1; //start by displaying the board cout << b->toString(); int consecutivePasses = 0; bool human = humanPlayer == 1 ? true : false; while(!b->full_board() && consecutivePasses<2) { //player to go first is whomever has value 1 (black), -1 (white) goes second if (human) { //ask for the human play if (!humanPlay(b, humanPlayer, consecutivePasses)) continue; human = false; } else { //play the computer move if (!computerPlay(b, cpuPlayer, consecutivePasses)) continue; human = true; } } //tally up the score and report it int score = b->score(); if(score == 0) cout << "Tie game." << endl; else if(score > 0) cout << "Black wins by " << score << endl; else if(score < 0) cout << "White wins by " << -score << endl; cout << "Press Enter to Exit" << endl; cin.ignore(); cin.ignore(); }
void Scene::rotateQuadrant(int quadrant, int direction) { if (gameState == ROTATE) { board->playHistory.back().at(1) = quadrant; board->playHistory.back().at(2) = direction; board->rotateQuadrant(socket, quadrant, direction); checkVictory(); if (gameState != GAMEOVER) { if (gameMode == PVC) computerPlay(); else switchPlayer(); } } }
void TicTacToe::checkGameCondition() { if (checkDraw()) { ++mDrawCount; ui->drawCount->setText(QString("%1").arg(mDrawCount)); clearGrid(); } else if (checkUserWin()) { ++mUserScore; ui->userScore->setText(QString("%1").arg(mUserScore)); clearGrid(); } else { computerPlay(); if(checkComputerWin()) { ++mComputerScore; ui->computerScore->setText(QString("%1").arg(mComputerScore)); clearGrid(); } } }
void Scene::display() { //limpa a cor activa debackground e define nova cor RGBA if (gameEnvironment==1) glClearColor(backgroundR, backgroundG, backgroundB, backgroundA); else if (gameEnvironment==2) glClearColor(backgroundR2, backgroundG2, backgroundB2, backgroundA2); // Clear image and depth buffer everytime we update the scene glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //Define drawmode glPolygonMode(GL_FRONT_AND_BACK, this->drawMode); // Initialize Model-View matrix as identity (no transformation glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Apply transformations corresponding to the camera position relative to the origin CGFscene::activeCamera->applyView(); GLint rMode; glGetIntegerv(GL_RENDER_MODE, &rMode); if (rMode == GL_RENDER) //se em modo normal, desenha a cena { // Draw (and update) light std::list<CGFlight *>::iterator it = scene_lights.begin(); for (; it != scene_lights.end(); ++it) ((Light *)(*it))->draw(); // Draw axis //axis.draw(); // ---- END Background, camera and axis setup processGraph(rootNode); //temos de passar o id do nó inicial //board->draw(); // We have been drawing in a memory area that is not visible - the back buffer, // while the graphics card is showing the contents of another buffer - the front buffer // glutSwapBuffers() will swap pointers so that the back buffer becomes the front buffer and vice-versa //board->drawHotspots(); //Testing } if (!Animation::animationRunning || !waitForAnimations) { if (inReplay) replay(); else if (!computerPlaying) //only draw arrows and hotspots if it's a human player's turn { if (rMode == GL_SELECT && gameState == PLACEPIECE && gameStarted) //se em modo de pick, desenha os hotspots board->drawHotspots(); if (gameState == ROTATE) //in all render modes board->drawArrows(player); } else //if the computer is playing, start the rotation computerPlay(); } glutSwapBuffers(); //std::this_thread::sleep_for(std::chrono::milliseconds(17)); }