Exemple #1
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 #2
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 );
}