Exemplo n.º 1
0
/**
 * Reads a game in XML representation from the given device and creates a game object for it.
 *
 * @param device Device to read the game from.
 * @return A game representing the state of the XML.
 */
QSharedPointer<Game> GameReader::readGame(QIODevice* device)
{
	this->xmlStream.setDevice(device);

	this->readXML(true);

	auto gameLogic = QSharedPointer< ::GameLogic::FourInALine::Game>::create(this->nRows,
	                                                                         this->nColumns,
	                                                                         this->firstMovePlayerId);
	gameLogic->setTimeLimit(this->timeLimit);
	gameLogic->setTimeoutAction(this->timeoutAction);

	auto game = QSharedPointer<Game>::create(gameLogic, this->firstPlayer, this->secondPlayer);
	game->setSaveHighscore(this->saveHighscore);
	game->setAllowUndo(this->allowUndo);
	game->setAllowHint(this->allowHint);

	for (auto i = this->moves.cbegin(); i != this->moves.cend(); ++i)
	{
		if (game->getCurrentPlayer()->getPlayer() != i->first)
		{
			throw ParseError("Expected other player in current move.");
		}

		game->getGameLogic()->makeMove(i->second);
	}

	return game;
}
Exemplo n.º 2
0
void LastExpressEngine::pollEvents() {
	Common::Event ev;
	_eventMan->pollEvent(ev);

	switch (ev.type) {

	case Common::EVENT_LBUTTONUP:
		getGameLogic()->getGameState()->getGameFlags()->mouseLeftClick = true;
		break;

	case Common::EVENT_RBUTTONUP:
		getGameLogic()->getGameState()->getGameFlags()->mouseRightClick = true;
		break;

	default:
		break;
	}
}
Exemplo n.º 3
0
bool LastExpressEngine::handleEvents() {
	// Make sure all the subsystems have been initialized
	if (!_debugger || !_graphicsMan)
		error("LastExpressEngine::handleEvents: called before the required subsystems have been initialized!");

	// Execute stored commands
	if (_debugger->hasCommand()) {
		_debugger->callCommand();

		// re-attach the debugger
		_debugger->attach();
	}

	// Show the debugger if required
	_debugger->onFrame();

	// Handle input
	Common::Event ev;
	while (_eventMan->pollEvent(ev)) {
		switch (ev.type) {

		case Common::EVENT_KEYDOWN:
			// CTRL-D: Attach the debugger
			if ((ev.kbd.flags & Common::KBD_CTRL) && ev.kbd.keycode == Common::KEYCODE_d)
				_debugger->attach();

			//// DEBUG: Quit game on escape
			//if (ev.kbd.keycode == Common::KEYCODE_ESCAPE)
			//	quitGame();

			break;

		case Common::EVENT_MAINMENU:
			// Closing the GMM

		case Common::EVENT_LBUTTONUP:
		case Common::EVENT_LBUTTONDOWN:
			getGameLogic()->getGameState()->getGameFlags()->mouseLeftClick = true;

			// Adjust frameInterval flag
			if (_frameCounter < _lastFrameCount + 30)
				getGameLogic()->getGameState()->getGameFlags()->frameInterval = true;
			_lastFrameCount = _frameCounter;

			if (_eventMouse && _eventMouse->isValid())
				(*_eventMouse)(ev);
			break;

		case Common::EVENT_RBUTTONUP:
		case Common::EVENT_RBUTTONDOWN:
			getGameLogic()->getGameState()->getGameFlags()->mouseRightClick = true;
			if (_eventMouse && _eventMouse->isValid())
				(*_eventMouse)(ev);
			break;

		case Common::EVENT_MOUSEMOVE:
			if (_eventMouse && _eventMouse->isValid())
				(*_eventMouse)(ev);
			break;

		case Common::EVENT_QUIT:
			quitGame();
			break;

		default:
			break;
		}
	}

	// Game tick event
	if (_eventTick && _eventTick->isValid())
		(*_eventTick)(ev);

	// Update the screen
	_graphicsMan->update();
	_system->updateScreen();
	_system->delayMillis(50);

	// The event loop may have triggered the quit status. In this case,
	// stop the execution.
	if (shouldQuit()) {
		return true;
	}

	return false;
}