Ejemplo n.º 1
0
void KReversiView::setGame(KReversiGame *game)
{
    // disconnect signals from previous game if they exist,
    // we are not interested in them anymore
    if (m_game) {
        disconnect(m_game, SIGNAL(boardChanged()), this, SLOT(updateBoard()));
        disconnect(m_game, SIGNAL(moveFinished()), this, SLOT(gameMoveFinished()));
        disconnect(m_game, SIGNAL(gameOver()), this, SLOT(gameOver()));
        disconnect(m_game, SIGNAL(whitePlayerCantMove()), this, SLOT(whitePlayerCantMove()));
        disconnect(m_game, SIGNAL(blackPlayerCantMove()), this, SLOT(blackPlayerCantMove()));
        delete m_game;
    }

    m_game = game;

    if (m_game) {
        connect(m_game, SIGNAL(boardChanged()), this, SLOT(updateBoard()));
        connect(m_game, SIGNAL(moveFinished()), this, SLOT(gameMoveFinished()));
        connect(m_game, SIGNAL(gameOver()), this, SLOT(gameOver()));
        connect(m_game, SIGNAL(whitePlayerCantMove()), this, SLOT(whitePlayerCantMove()));
        connect(m_game, SIGNAL(blackPlayerCantMove()), this, SLOT(blackPlayerCantMove()));

        m_game->setDelay(m_delay);
    }

    m_hint = KReversiMove();

    updateBoard();
}
GraphicsUserListItem::GraphicsUserListItem(UserData* userData, QGraphicsItem* parent):QGraphicsItem(parent) {
    mUserData = userData;
    connect(mUserData, SIGNAL(dataAltered()), this, SLOT(userDataAltered()));

    mUserSelections = NULL;
    mUserSelectionsItem = NULL;

    mUserSelections = new UserSelectionsWidget(mUserData);

    mWidth = 100;
    mHeight = DEFAULT_HEIGHT;
    mPixmapWidth = DEFAULT_PIXMAP_WIDTH;
    updateBounds();

    mHoverTimer.setDuration(UL_HOVER_DURATION);
    mHoverTimer.setUpdateInterval(10);
    connect(&mHoverTimer, SIGNAL(valueChanged(qreal)), this, SLOT(hoverValueChanged(qreal)));
    connect(&mHoverTimer, SIGNAL(finished()), this, SLOT(hoverFinished()));
    connect(&mMoveTimer, SIGNAL(valueChanged(qreal)), this, SLOT(moveValueChanged(qreal)));
    connect(&mMoveTimer, SIGNAL(finished()), this, SLOT(moveFinished()));

    mHighlightTimer.setDuration(ANIM_HIGHLIGHT_DURATION);
    mHighlightTimer.setUpdateInterval(10);
    mHighlightAnimation.setItem(this);
    mHighlightAnimation.setTimeLine(&mHighlightTimer);
    mHighlightAnimation.setScaleAt(0,1,1);
    mHighlightAnimation.setTranslationAt(0, 0,0);
    mHighlightAnimation.setTranslationAt(.25, 10,0);
    mHighlightAnimation.setScaleAt(.15, 1.2,1.2);
    mHighlightAnimation.setScaleAt(.85, 1.2,1.2);
    mHighlightAnimation.setTranslationAt(.85, 10,0);
    mHighlightAnimation.setTranslationAt(1,0,0);
    mHighlightAnimation.setScaleAt(1, 1,1);
    connect(&mHighlightTimer, SIGNAL(valueChanged(qreal)), this, SLOT(moveValueChanged(qreal)));
    connect(&mHighlightTimer, SIGNAL(finished()), this, SLOT(moveFinished()));

//	mHoverAnimation.setItem(this);
//	mHoverAnimation.setTimeLine(&mHoverTimer);
//	mHoverAnimation.setScaleAt(0,1,1);
//	mHoverAnimation.setScaleAt(1,1,2);

    hoverValueChanged(0);
    hoverFinished();
    setAcceptsHoverEvents(true);

    mHovering = false;
    mPressed = false;
}
Ejemplo n.º 3
0
void GameHandler::redoTurn() {
	qDebug("\nredoTurn()");
	StateHandler::getInstance().setGamePaused(true);
	
	//check if there is a move available in this turn or the next
	if (this->lastMoveId + 1 >= (int)this->turnsHistory[this->currentTurnId].size() && 
		this->currentTurnId + 1 < (int)this->turnsHistory.size()) 
			this->changeCurrentPlayer();
	else if (this->lastMoveId + 1 >= (int)this->turnsHistory[this->currentTurnId].size() && 
		this->currentTurnId + 1 >= (int)this->turnsHistory.size())
			return;
	
	//perform all the moves from the turn
	for (int i = this->lastMoveId + 1; i < (int)this->turnsHistory[this->currentTurnId].size(); ++i) {	//redo the moves in the right order
		Move move = this->turnsHistory[this->currentTurnId][i];
		assert(this->game.isMoveValid(move));
		
		this->moveTile(move, false);
		this->game.makeMove(move);
	}

	this->lastMoveId = this->turnsHistory[this->currentTurnId].size() - 1;
	
	if (this->currentTurnId + 1 < (int)this->turnsHistory.size() || 
		this->players[this->currentPlayer]->getPlayerInfo().type == AI_PLAYER)
		this->changeCurrentPlayer();
	
	emit moveFinished();
}
Ejemplo n.º 4
0
void GameHandler::undoTurn() {
	qDebug("\nundoTurn()");
	
	StateHandler::getInstance().setGamePaused(true);
	
	//if we need to change the player
	if (this->currentTurnId > 0 && this->lastMoveId == -1)
		this->changeCurrentPlayer(true);
	else 	//or it's mid-turn and we have to go back to the beginning
		if (this->lastMoveId  > -1)
			this->sendUndoTurn(this->players[this->currentPlayer]->getPlayerInfo().player, this->currentTurnId);
	
	for (int i = this->lastMoveId; i >= 0; --i) {	//undo the moves in the right order
		Move move = this->turnsHistory[this->currentTurnId][i];
		move.revert();
		assert(this->game.isMovePossible(move));
		
		this->moveTile(move, false);
		this->game.makeMove(move, true);
	}
	
	this->lastMoveId = -1;
	
	//if it was the first turn, we need to let the players know it was undone
	if (this->currentTurnId == 0 && this->lastMoveId == -1)
		this->sendUndoTurn(this->players[this->currentPlayer]->getPlayerInfo().player, this->currentTurnId);
	
	emit moveFinished();
}
Ejemplo n.º 5
0
void GameHandler::undoMove() {
	qDebug("\nundoMove() %d %d", this->currentTurnId, this->lastMoveId);
	StateHandler::getInstance().setGamePaused(true);

	if (this->lastMoveId < 0 && this->currentTurnId > 0) {
		this->changeCurrentPlayer(true);	//we cannot move back, have to switch player
	} else if (this->lastMoveId == 0 /*&& this->currentTurnId == 0*/) {	//it's the last move we can undo from this turn
		if (this->turnsHistory[this->currentTurnId].empty() == false)
			this->sendUndoTurn(this->players[this->currentPlayer]->getPlayerInfo().player, this->currentTurnId);
// 			for (Player* player: this->players)
// 				player->undoTurn(this->players[this->currentPlayer]->getPlayerInfo().player,
// 						 this->turnsHistory[this->currentTurnId]);
// 		return;
	}
	
	Move move = this->turnsHistory[this->currentTurnId][this->lastMoveId];
	move.revert();
	
	if (this->game.isMovePossible(move)) {
		qDebug("Undo possible!");
		this->moveTile(move);
		this->lastMoveId--;
		this->game.makeMove(move, true);
		emit moveFinished();
	}
}
Ejemplo n.º 6
0
SideBySideLayout::SideBySideLayout( QWidget* parent )
           : QLayout( parent ), m_currentItem( 0 ), m_timeLine( new QTimeLine( 300, this ) )
{
    m_timeLine->setUpdateInterval( 25 );
    connect( m_timeLine, SIGNAL(frameChanged( int )), SLOT(onFrameChanged( int )));
    connect( m_timeLine, SIGNAL(finished()), SIGNAL(moveFinished()));
}
Ejemplo n.º 7
0
void GameHandler::checkForNewMoves() {
	if (StateHandler::getInstance().isEditorMode()) {
		for (Player* player: this->players)
			if (player->isMoveReady()) {
				Move move = player->getMove();
				if (this->getSource(move) != NULL) {
					this->moveTile(move, false);
					this->game.makeUnsafeMove(move);
				}
			}
		return;
	}
	
	if (this->players[this->currentPlayer]->isTurnFinished())
		this->changeCurrentPlayer();
	
	if (this->players[this->currentPlayer]->isMoveReady()) {
		this->playersTimer.stop();
		
		Move move = this->players[this->currentPlayer]->getMove();
		
		if (this->game.isMoveValid(move) ) {
			qDebug("Valid move!");

			this->moveTile(move);
			
			//if the move was the next from the history, increase the index
			//if not, erase the end of the vector and start appending new moves
			//forgetting the move if it's not from history:
			if (this->lastMoveId + 1 < (int)this->turnsHistory[this->currentTurnId].size() &&
				this->turnsHistory[this->currentTurnId][this->lastMoveId + 1] != move) {	//a different move
				this->sendUndoTurn(this->players[this->currentPlayer]->getPlayerInfo().player, this->currentTurnId);
				this->dropHistoryTail();
			}
			
			this->lastMoveId++;
			if ((int)this->turnsHistory[this->currentTurnId].size() == this->lastMoveId)
				this->turnsHistory[this->currentTurnId].push_back(move);
			
			this->game.makeMove(move);
			emit moveFinished();
		}
		
		//TODO make this a feature
		/*if (this->game.getMovesLeft() <= 0 && this->game.getPassessLeft() <= 0)
			this->changeCurrentPlayer();*/
	
		if (this->game.isFinished()) {
			qDebug("Game finished!");
 			emit gameFinished();
			return;
		}
		
		this->playersTimer.start();
	}
}
Ejemplo n.º 8
0
void Figure::moveTo(const uint aX, const uint aY)
{
	setPos(XTopWorld + (aX - 1) * WordCeilSize + WordCeilSize * (0.5f - ScaleFigure * 0.5f),
		   YTopWorld + (8u - aY) * WordCeilSize + WordCeilSize * (0.5f - ScaleFigure * 0.5f));

	if(mX != aX || mY != aY)
	{
		moveFinished(mX, mY, aX, aY);
		mX = aX;
		mY = aY;
	}
}
/*!
 \brief Slot which is called when moving of scroll area is finished.
 
 Resets internal isMoving flag.
 */
void CalenDayContentScrollArea::moveFinished()
{
    // Disconnect from signal, move is finished now
    disconnect(this, SIGNAL(scrollingEnded()), this, SLOT(moveFinished()));
    mIsMoving = false;
    
    // Emit signal that moving has just finished and reset direction
    if (mMoveDirection != ECalenScrollNoDayChange) {
        emit scrollAreaMoveFinished(mMoveDirection);
        mMoveDirection = ECalenScrollNoDayChange;
    }
}
Ejemplo n.º 10
0
int Widget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: on_pushButton_2_clicked(); break;
        case 1: on_pushButton_clicked(); break;
        case 2: moveFinished(); break;
        case 3: doorFinished(); break;
        case 4: doorOpened(); break;
        case 5: slotRequestReceived((*reinterpret_cast< StateObject(*)>(_a[1]))); break;
        case 6: slotFloorChanged((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 7: slotArrived((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])),(*reinterpret_cast< StateObject(*)[]>(_a[3]))); break;
        default: ;
        }
        _id -= 8;
    }
    return _id;
}
/*!
 \brief Scrolls the contents to the newPosition in a given time.
 
 Sets the flag to indicate that scrolling is in progress. Use this function
 for scrolling with timeout > 0 to block gesture and focus events during
 scroll area movement.
 
 \param newPosition Destination position
 \param time Time of scroll movement
 */
void CalenDayContentScrollArea::moveTo(const QPointF &newPosition, int time)
{
    bool canMove(true);
    if (mDisallowedDirection != ECalenScrollNoDayChange) {
        canMove = (mMoveDirection != mDisallowedDirection);
    }
    
    if (canMove) {
        // Connect to scrollingEnded SIGNAL to get feedback when scrolling ends
        connect(this, SIGNAL(scrollingEnded()), this, SLOT(moveFinished()));
        
        // Scroll the content to new position and set isMoving flag
        scrollContentsTo(newPosition, time);
        mIsMoving = true;
        
        // Emit signal that moving has just started
        if (mMoveDirection != ECalenScrollNoDayChange) {
            emit scrollAreaMoveStarted(mMoveDirection);
        }
    }
}