Exemple #1
0
void GameState::handleEvents()
{
    m_error.str(""); // On vide la précédente erreur
    if (m_waitingChoiceAction) {
        m_waitingChoiceAction = false;
        makeChoiceAction();
    } else if (m_waitingChoiceMove) {
        m_waitingChoiceMove = false;
        makeChoiceMove();
    } else if (m_waitingChoiceWallCol) {
        m_waitingChoiceWallCol = false;
        makeChoiceWallCol();
    } else if (m_waitingChoiceWallRow) {
        m_waitingChoiceWallRow = false;
        makeChoiceWallRow();
    } else if (m_waitingChoiceWallDir) {
        m_waitingChoiceWallDir = false;
        makeChoiceWallDir();
    } else if (m_waitingChoiceWin) {
        m_waitingChoiceWin = false;
        finishGame();
    } else if (m_waitingChoiceDraw) {
        m_waitingChoiceDraw = false;
        finishGame();
    }
}
Exemple #2
0
bool BoxCar::run()
{
  while (state_ != Quit) {
    switch (state_)
    {
    case Menu:
      Logger::getInstance().log(INFO_LOG_NAME, "Switching to menu");
      initMenu();
      mainLoop();
      finishMenu();
      break;
    case Game:
      Logger::getInstance().log(INFO_LOG_NAME, "Switching to game");
      initGame();
      mainLoop();
      finishGame();
      break;
    case ShowCredits:
      Logger::getInstance().log(INFO_LOG_NAME, "Switching to credits");
      initCredits();
      mainLoop();
      finishCredits();
      break;
    default:
      Logger::getInstance().log(ERROR_LOG_NAME, "Encountered unknown state. Terminating.");
      state_ = Quit;
      break;
    }
  }
  close();
  return true;
}
Exemple #3
0
void ScoreStateMachine::update() {
	switch( state ) {
		case gsTraining:
			break;
		case gsPlaying: {
		    if( IsPaused ) return;
			int level = LevelMeter.value();
            CashMeter -= TimePrice;
			bool revealSubsurface = false;
		    if( CashMeter.value()>=200 ) {
				state = gsBonus;
				bonusStartTime = HostClockTime();
				revealSubsurface = true;
			} else if( CashMeter.value()<=0 ) {
				CashMeter.setValue(0);
				VisibleDialog = &TheBankruptDialog;
				state = gsOver;
				TheBeginGameItem.setEnabled(true); 
	            TheEndGameItem.setEnabled(false);
				revealSubsurface = true;
			}
			if( revealSubsurface ) {
			    if( !ShowGeology ) ToggleShowGeology();
				if( !ShowReservoir ) ToggleShowReservoir();
	        }
			break;
		}
		case gsBonus:
			if( HostClockTime()>bonusStartTime+0.5 ) {
				state = gsWait;
				VisibleDialog = &TheLevelContinueDialog;
			}
			break;
		case gsWait:
			if( VisibleDialog!=&TheLevelContinueDialog ) {
				LevelMeter+=1;
				CashMeter.setValue(100);
				startNewArea();
			}
			break;
		case gsOver:
			if( VisibleDialog!=&TheBankruptDialog ) {
				finishGame();
			}
			break;
		default:
			Assert(false);
			break;
	}
}
Exemple #4
0
void View_Board::init(Game *_game) {
	qDebug() << "View_Board::init(Game *_game) -> BEGIN";
	
	// model
	game = _game;
	board = &game->getBoard();
	end_flag = END_NONE;
	
	// signal to update model
	connect(game, SIGNAL(updateBoard()), SLOT(updateBoard()));
	// signal to finish game
	connect(game, SIGNAL(finishGame(GAMESTATE)), SLOT(finishGame(GAMESTATE)));
	
	// draw board wrapper
	setGeometry(10, 10, 450, 400);
	
	// events
	installEventFilter(this);
	
	// show board
	show();
	
	qDebug() << "View_Board::init(Game *_game) -> END";
}
Exemple #5
0
void Scene::timer(int value) {
    int a = 4;
    int i;
    for (i=0; i < 3; i++) {
        if (r[i][1] > r[i][0]) {
            r[i][0] += a;
            rotate(i, axis, a);
        } else if (r[i][1] < r[i][0]) {
            r[i][0] -= a;
            rotate(i, axis, -a);
        }
    }
    
    if (game) {
        short found = TRUE;
        float approximate = 0.004;
        int i, j;
        for (i=0; i<4 && found; i++) {
            for (j=0; j < 3 && found; j++) {
                float difference = abs(originalVertex[i][j] - exludedVertex[i][j]);
                if (difference > approximate) {
                    found = FALSE;
                }
            }
        }
        if (!found) {
            found = TRUE;            
            for (i=0; i<4 && found; i++) {
                for (j=0; j < 3 && found; j++) {
                    int i2 = i > 1 ? i - 2 : i + 2;
                    float difference = abs(originalVertex[i][j] - exludedVertex[i2][j]);
                    if (difference > approximate) {
                        found = FALSE;
                    }
                }
            }
        }
        if (found) {
            finishGame();
        }
    }
    
    glutPostRedisplay();
}
// public methods
void MastermindGame::playGame()
{
	while (continuePlaying)
	{
		
		cout << "Play against player (Y) or a computer (N)?" << endl;
		if (promptBoolean())
			startTwoPlayerGame();
		else
		{
			cout << "Play as the code breaker (Y) or code maker (N)?" << endl;
			if (promptBoolean())
				startComputerGame();
			else startComputerGuessingGame();
		}
		
		finishGame();
		continuePlaying = promptNewGame();
	}
}
void XboardEngine::endGame(const Chess::Result& result)
{
	State s = state();
	if (s != Thinking && s != Observing)
		return;

	if (s != Thinking)
		m_gotResult = true;

	stopThinking();
	setForceMode(true);
	write("result " + result.toVerboseString());

	ChessEngine::endGame(result);

	// If the engine can't be pinged, we may have to wait for
	// for a move or a result, or an error, or whatever. We
	// would like to extend our middle fingers to every engine
	// developer who fails to support the ping command.
	if (!m_ftPing && m_gotResult)
		finishGame();
}
Exemple #8
0
void Model::finishGame() {
    gameStatus = STOPPED;
    gameTimer.stop();
    emit finishGame(score);
}
Exemple #9
0
void Game::finish(GAMESTATE res_flag) {
	//qDebug() << "Game::finish(GAMESTATE res_flag)";
	
	emit finishGame(res_flag);
}