Exemple #1
0
CanvasCard* CanvasPlayer::hasCard( int cardid ) const
{
    for(unsigned int i=0;i<NUMCARDS;i++)
    {
        CanvasCard* card = m_items[i];
        if(card->card()->id() == cardid )
            return card;
    }
    return NULL;
}
Exemple #2
0
bool ChicaneCardGame::mousePressCard( Card *card, QPoint p )
{
    Q_UNUSED(p);

    CanvasCard *item = (CanvasCard *)card;
    if (item->isFacing() != TRUE) {
	// From facedown stack
	if ((item->x() == 2) && ((int)item->y() == 10)) {		// Deal a row of 8 cards
	    // Move 8 cards, one to each workingPile
	    beginDealing();
	    for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) {
		CanvasCard *card =  (CanvasCard *)faceDownDealingPile->cardOnTop();
	        card->setZ(highestZ);
	        highestZ++;
		faceDownDealingPile->removeCard(card);
		workingPiles[i]->addCardToTop(card);
		card->setCardPile( workingPiles[i] );
		card->setFace(FALSE);
		QPoint p = workingPiles[i]->getCardPos(card);
		card->flipTo( p.x(), p.y() );
	    }
	    endDealing();
	}
	moving = NULL;
	moved = FALSE;

	return TRUE;
    } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {	// Don't allow unclean columns to be moved
       	moving = NULL;
        return TRUE;
    }

    return FALSE;
}
Exemple #3
0
CanvasCard* CanvasPlayer::canvasCard( int index )
{
    if( index < 0 || index >= NUMCARDS )
        return NULL;

    CanvasCard* card = m_items[index];
    if( card->isVisible() )
        return card;
    else 
        return NULL;
}
Exemple #4
0
void GameCanvas::cardForbidden( int cardid )
{
    for(unsigned int z=0;z<PLAYERS;z++)
    {
        CanvasCard* c = m_players[z]->hasCard( cardid );
        if( c )            
        {
            c->forbidden();
            break;
        }
    }
}
Exemple #5
0
void GameCanvas::cardClicked( QGraphicsItem* item )
{
    if( item )
        item->setSelected( false );

    if( item->type() == CANVASCARD )
    {
        CanvasCard* card = static_cast<CanvasCard*>(item);

        for( unsigned int i = 0; i < PLAYERS; i++ ) 
        {
            if( m_players[i]->isHuman() && m_players[i]->hasCard( card->card()->id() ) )
            {
                m_result = card->card()->id();
                disconnect( this, SIGNAL(clicked( QGraphicsItem* )), this, SLOT(cardClicked(QGraphicsItem*)));

                // be sure that focusOutEvent does not use its parameter
                focusOutEvent( NULL );
                m_loop.exit();
            }
        }
Exemple #6
0
int GameCanvas::getCard()
{
    CanvasPlayer* human = humanPlayer();
    CanvasCard* c = NULL;
    unsigned int i;

    connect( this, SIGNAL(clicked( QGraphicsItem* )), this, SLOT(cardClicked(QGraphicsItem*)));
    m_result = -1;

    if( hasFocus() && human )
        for( i=0;i<NUMCARDS;i++)
        {
            c = human->canvasCard( i );
            if( c )
            {
                c->setSelected( true );
                break;
            }
        }

    m_loop.exec();

    return m_result;
}
Exemple #7
0
void CanvasPlayer::position()
{
    int x = 0, y = 0;
    int num = 0;
    int w = m_scene->width();
    int h = m_scene->height();
    int offsetl = 0; //Hiermit kann man am linken Rand Platz schaffen fuer z.B. ein Bild des Spielers (Netzwerkmodus).
    int availw = m_scene->width() - 2*DIST - offsetl;
    int cardw = Card::backgroundPixmap()->width();
    int cardh = Card::backgroundPixmap()->height();
    float cardoverlap = 1./8.; //Ueberlapp der Karten im Verhaeltnis zur Kartenbreite

    for( unsigned int z = 0; z < NUMCARDS; z++ )
    {
        CanvasCard* card = m_items[z];
        if(card->isVisible())
            num++;
    }

    if(!Settings::instance()->rearrangeCards())
        num=NUMCARDS;

    if(m_position==1||m_position==3)
        qSwap( cardw, cardh );

    switch( m_position ) 
    {
        case 0:
            if(availw>num*cardw+(num-1))
                x=(w-cardw*num)/2-(num-1)/2-offsetl;
            else
                x=DIST+offsetl;
            y=h-cardh-DIST;

            m_name->setPos( (w-m_name->sceneBoundingRect().width())/2, y-m_name->sceneBoundingRect().height() );
            break;
        case 1:
            x=DIST; 
            y=(h-((cardh*cardoverlap)*(num-1)+cardh))/2; 

            m_name->setPos(x,y-m_name->sceneBoundingRect().height());
            break;
        case 2:
            x=( w-( (cardw*cardoverlap)*(num-1)+cardw ) )/2; //berechnet die Position der linken Seite des Kartenstapels
            y=DIST;

            m_name->setPos( (w-m_name->sceneBoundingRect().width())/2, y+cardh );
            break;
        case 3:
        default:
            x=w-cardw-DIST;
            y=(h-((cardh*cardoverlap)*(num-1)+cardh))/2; 

            m_name->setPos(x, y-m_name->sceneBoundingRect().height());
            break;
    }

    for( unsigned int z = 0; z < NUMCARDS; z++ )
    {
        CanvasCard* card = m_items[z];
        // only move if necessary!
        if(card->isVisible() || !Settings::instance()->rearrangeCards())
        {
            if( x != card->x() || y != card->y() )
            {
                if(num==NUMCARDS)
                    card->setPos( x, y );
                else
                {
                    card->setDestination( x, y );
                    card->animatedMove();
                }
            }
            if(m_position==0)
            {
                if(availw>num*cardw+(num-1))
                    x += cardw+1;
                else
                    x += (availw-cardw)/(num-1);
            }
            else
            {
                if(m_position==2)
                    x += (cardw*cardoverlap);
                else
                    y += (cardh*cardoverlap);
            }
        }
    }

    // swap them back
    if(m_position==1||m_position==3)
        qSwap( cardw, cardh );
}
Exemple #8
0
void CanvasPlayer::init()
{
    m_name->setText( m_player_name );

    if( m_cards->count() )
    {
        for( int z = 0; z < m_cards->count(); z++ )
        {
            CanvasCard *c = m_items[z];
            c->setCard( m_cards->at( z ) );
            c->setZValue( double(-1 - z) );
            c->show();

            if(m_position==1)
                c->setRotation(270);
            else if(m_position==3)
                c->setRotation(90);
    #ifdef CHEAT
            c->setFrontVisible( true );
    #else            
            if( m_is_human )
            {
                if( m_has_doubled )
                    c->setFrontVisible( true );
                else
                {
                    if( m_is_last )
                        c->setFrontVisible( z >= NUMCARDS/2 );
                    else
                        c->setFrontVisible( z < NUMCARDS/2 );
                }
            }
            else
                c->setFrontVisible( false );
    #endif
        }
        m_name->show();
    }
    else
    {
        for( unsigned int z = 0;z<NUMCARDS;z++)
            m_items[z]->hide();

        m_name->hide();
    }
}