//must be called after setWindow
void GuiGameController::setNetworkInterface(){
    if( net == nullptr){

        net = new NetworkInterface(this);

        qDebug() << "connecting network signals";

        //gameController -> network
        connect( this, SIGNAL(gameIsOver()), net, SLOT( tellMeGameIsOver()) );

        //network -> GUI
        connect( net,   SIGNAL(opponentDisconnectedEarly()),                    gui,    SIGNAL(opponentDisconnected()) );
        connect( net,   SIGNAL(connectionReestablished()),                      gui,    SIGNAL(opponentReconnected()) );
        connect( net,   SIGNAL( challengeReceived(QVariant, QVariant) ),        gui,    SIGNAL(challengeReceivedFromNetwork(QVariant, QVariant)),   Qt::QueuedConnection );
        connect( net,   SIGNAL( challengeResponseReceived(bool)),               this,   SLOT(challengeResponseReceivedFromNetwork(bool)),           Qt::QueuedConnection );
        connect( net,   SIGNAL( networkTurnReceived(int,int,int,int) ),         this,   SLOT(networkTurnReceivedFromNetwork(int,int,int,int)),      Qt::QueuedConnection );
        connect( this,  SIGNAL( challengeAccepted()),                           gui,    SIGNAL(challengeWasAccepted() ),                            Qt::QueuedConnection );
        connect( this,  SIGNAL( challengeDeclined()),                           gui,    SIGNAL(challengeWasDeclined()) ,                            Qt::QueuedConnection );
        connect( gui,   SIGNAL( challengeTimedOutAsIfDeclined()),              net,    SLOT(forceNotBusy()), Qt::QueuedConnection );
        connect( net,   SIGNAL( playerJoinedNetwork(QVariant, QVariant, int, bool )), gui,    SIGNAL(playerEnteredLobby(QVariant, QVariant, int, bool )),       Qt::QueuedConnection );
        connect( net,   SIGNAL( playerLeftNetwork(int)),                        gui,    SIGNAL(playerLeftLobby(int)));
        connect( net,   SIGNAL( networkPlayerBecameBusy(QVariant)),             gui,    SIGNAL(networkPlayerBecameBusy(QVariant)),                  Qt::QueuedConnection );
        connect( net,   SIGNAL( networkPlayerNoLongerBusy(QVariant)),           gui,    SIGNAL(networkPlayerNoLongerBusy(QVariant)),                Qt::QueuedConnection );
        //GUI -> network
        connect(gui, SIGNAL(sendThisChallenge(QVariant)),               net,    SLOT(sendChallenge(QVariant)),              Qt::QueuedConnection );
        connect(gui, SIGNAL(sendThisChallengeResponse(bool)),           this,   SLOT(forwardChallengeResponse(bool)),       Qt::QueuedConnection );

    }else{
int startGame(){
    int posX, posY; /* User coordinates input */
    system("clear");

    /* Initialize some positions for enemy ships */
    enemyShipTable[0][0]=1;
    enemyShipTable[1][1]=1;
    enemyShipTable[2][2]=1;
    enemyShipTable[3][3]=1;
    enemyShipTable[4][4]=1;

    do{
        printf("Digite a posicao que deseja atirar (x y):\n");
        printf("*Para sair digite (-1 -1)\n");
        scanf("%i %i", &posX, &posY);
        while(!coordIsValid(posX, posY)){
            printf("Coordenadas invalidas! Tente novamente\n");
            scanf("%i" "%i", &posX, &posY);
        }
        system("clear");
        
        if(posX!=-1 && posY!=-1){
            if(isAHit(posX, posY)==1){
                removeShip(posX, posY);
                printf("Acertou um navio!\n");
            }

            else
                printf("Errou! Tente novamente\n");

            if(gameIsOver())
                printf("Acertou todos os navios\nParabens voce venceu!\n");
        }
        else /* Back to main menu if (-1 -1)*/
            return 0;

    }while((posX!=-1 && posY!=-1) && gameIsOver()==0);

    printf("\n[Pressione ENTER para voltar ao menu]\n");
    getchar();
    getchar();

    return 0;
}
void GameWidget::startNewGame()
{
    isGameStarted = true;

    background->setPos(0, 328);
    scene->addItem(background);

    player = new Player;
    army = new EnemyArmy(scene, player);
    airGun = new AirGun(scene);

    setGameText();

    QObject::connect(player, SIGNAL(gameOver()),
                     this, SLOT(gameIsOver()));
}
Exemple #4
0
void MainWindow::startGame(KDiamond::Mode mode)
{
	//delete old board
	delete m_game;
	//start new game
	m_gameState->startNewGame();
	m_gameState->setMode(mode);
	m_game = new Game(m_gameState);
	connect(m_gameState, SIGNAL(stateChanged(KDiamond::State)), m_game, SLOT(stateChange(KDiamond::State)));
	connect(m_gameState, SIGNAL(message(QString)), m_game, SLOT(message(QString)));
	connect(m_game, SIGNAL(numberMoves(int)), m_infoBar, SLOT(updateMoves(int)));
	connect(m_game, SIGNAL(pendingAnimationsFinished()), this, SLOT(gameIsOver()));
	connect(m_hintAct, SIGNAL(triggered()), m_game, SLOT(showHint()));
	m_view->setScene(m_game);
	//reset status bar
	m_infoBar->setUntimed(mode == KDiamond::UntimedGame);
	m_infoBar->updatePoints(0);
	m_infoBar->updateRemainingTime(KDiamond::GameDuration);
}
void GuiGameController::setGuiTurnHole( int qIndex, int pIndex ){
    BoardLocation bl;
    bl.quadrantIndex = qIndex;
    bl.pieceIndex = pIndex;
    qGuiTurn.setHole(bl);

    //checks for case when a player wins before a rotate
    GameData test = copyCurrentBoard().checkEarlyWin( bl, guiPlayerColor );

    if( test.winner == guiPlayerColor ){
        gameData = test;

        if( isNetworkGame ){

            //we won without rotating, so we need to inform the other player
            net -> sendGuiTurn( bl.quadrantIndex, bl.pieceIndex, DONT_ROTATE_CODE, Direction::NO_DIRECTION, guiPlayerColor );
        }

        emit gameIsOver();
    }
}
bool TicTacToe::handleGameOver()  {
	bool draw = false;
	Role whoWin = Human;
	if (gameIsOver(draw, whoWin)) {
		if (draw) {
			cout << "Draw!" << endl;
		}
		else {
			if (whoWin == Comp) {
				cout << "You lose!" << endl;
			}
			else if (whoWin == Human) {
				cout << "Congratulations! You defeat the computer." << endl;
			}
		}
		return true;
	}
	else {
		return false;
	}
}
Exemple #7
0
void playGame(void)
{
    bool gameLoaded = false;
    uint8_t ch;
    
    gScoreBar = 0;
    gShouldSave = false;
    
    printf("\n\nChecking for a saved game...");
    
    if (loadGame()) {
        bool gotAnswer = false;
        
        printf("\n\nYou have a saved game!\n    Would you like to continue it (Y/N)");
        
        while (!gotAnswer) {
            ch = cgetc();
            switch (ch) {
                case 'y':
                case 'Y':
                    printf("\n\nLoading your saved puzzle");
                    gotAnswer = true;
                    gShouldSave = true;
                    gameLoaded = true;
                    break;
                    
                case 'n':
                case 'N':
                    gotAnswer = true;
                    break;
                    
                default:
                    badThingHappened();
                    break;
            }
        }
    }
    
    showAndClearDblLoRes();
    if (!gameLoaded) {
        startNewGame();
    }
    drawBoard();
    speakGo();
    while (true) {
        resetStarAnim();
        
        while (true) {
            doStarAnim();
            
            if (pollKeyboard()) {
                break;
            }
            
            if ((gGameOptions.enableJoystick) &&
                (pollJoystick())) {
                break;
            }
            
            if ((gGameOptions.enableMouse) &&
                (pollMouse())) {
                break;
            }
        }
        
        if (gameIsOver()) {
            endGame();
            showAndClearDblLoRes();
            refreshScore(0);
            startNewGame();
            gShouldSave = false;
        }
    }
}