Пример #1
0
// See whether the card under the cursor can be moved somewhere else
// Returns 'true' if it can be moved, 'false' otherwise
bool Game::CanYouGo(int x, int y)
{
    Pile* pile = WhichPile(x, y);
    if (pile && pile != m_pack)
    {
        Card* card = pile->GetTopCard();

        if (card)
        {
            int i;
            for(i = 0; i < 8; i++)
            {
                if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
                {
                    return true;
                }
            }
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->GetTopCard() &&
                    m_bases[i]->AcceptCard(card) &&
                    m_bases[i] != pile)
                {
                    return true;
                }
            }
        }
    }
    return false;
}
Пример #2
0
// See whether the card under the cursor can be moved somewhere else
// Returns 'true' if it can be moved, 'false' otherwise
bool Game::CanYouGo(int x, int y)
{
    Pile* pile = WhichPile(x, y);
    if (pile && pile != m_pack)
    {
        Card* card = pile->GetTopCard();

        if (card)
        {
            int i;
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
            for(i = 0; i < 8; i++)
            {
                if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
                {
                    return true;
                }
            }
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->GetTopCard() &&
                    m_bases[i]->AcceptCard(card) &&
                    m_bases[i] != pile)
                {
                    return true;
                }
            }
        }
    }
    return false;
}
Пример #3
0
// Left button is pressed - if cursor is over the m_pack then deal a card
// otherwise if it is over a card pick it up ready to be dragged - see MouseMove()
bool Game::LButtonDown(wxDC& dc, int x, int y)
{
    m_srcPile = WhichPile(x, y);
    if (m_srcPile == m_pack)
    {
        Card* card = m_pack->RemoveTopCard();
        if (card)
        {
            m_pack->Redraw(dc);
            card->TurnCard(faceup);
            m_discard->AddCard(dc, card);
            DoMove(dc, m_pack, m_discard);
        }
        m_srcPile = 0;
    }
    else if (m_srcPile)
    {
        m_srcPile->GetTopCardPos(m_xPos, m_yPos);
        m_xOffset = m_xPos - x;
        m_yOffset = m_yPos - y;

        // Copy the area under the card
        // Initialise the card bitmap to the background colour
        {
            wxMemoryDC memoryDC;
            memoryDC.SelectObject(*m_bmap);
            m_liftedCard = m_srcPile->RemoveTopCard(memoryDC, m_xPos, m_yPos);
        }

        // Draw the card in card bitmap ready for blitting onto
        // the screen
        {
            wxMemoryDC memoryDC;
            memoryDC.SelectObject(*m_bmapCard);
            m_liftedCard->Draw(memoryDC, 0, 0);
        }
    }
    return m_srcPile != 0;
}
Пример #4
0
// Called when the left button is double clicked
// If a card is under the pointer and it can move elsewhere then move it.
// Move onto a foundation as first choice, a populated base as second and
// an empty base as third choice.
// NB Cards in the m_pack cannot be moved in this way - they aren't in play
// yet
void Game::LButtonDblClk(wxDC& dc, int x, int y)
{
    Pile* pile = WhichPile(x, y);
    if (!pile) return;

    // Double click on m_pack is the same as left button down
    if (pile == m_pack)
    {
        LButtonDown(dc, x, y);
    }
    else
    {
        Card* card = pile->GetTopCard();

        if (card)
        {
            int i;

            // if the card is an ace then try to place it next
            // to an ace of the same suit
            if (card->GetPipValue() == 1)
            {
                for(i = 0; i < 4; i++)
                {
                    Card* m_topCard = m_foundations[i]->GetTopCard();
                    if ( m_topCard )
                    {
                        if (m_topCard->GetSuit() == card->GetSuit() &&
                            m_foundations[i + 4] != pile &&
                            m_foundations[i + 4]->GetTopCard() == 0)
                        {
                            pile->RemoveTopCard(dc);
                            m_foundations[i + 4]->AddCard(dc, card);
                            DoMove(dc, pile, m_foundations[i + 4]);
                            return;
                        }
                    }
                }
            }

            // try to place the card on a foundation
            for(i = 0; i < 8; i++)
            {
                if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
                {
                    pile->RemoveTopCard(dc);
                    m_foundations[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_foundations[i]);
                    return;
                }
            }
            // try to place the card on a populated base
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->AcceptCard(card) &&
                    m_bases[i] != pile &&
                    m_bases[i]->GetTopCard())
                {
                    pile->RemoveTopCard(dc);
                    m_bases[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_bases[i]);
                    return;
                }
            }
            // try to place the card on any base
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->AcceptCard(card) && m_bases[i] != pile)
                {
                    pile->RemoveTopCard(dc);
                    m_bases[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_bases[i]);
                    return;
                }
            }
        }
    }
}
Пример #5
0
// Called when the left button is double clicked
// If a card is under the pointer and it can move elsewhere then move it.
// Move onto a foundation as first choice, a populated base as second and
// an empty base as third choice.
// NB Cards in the m_pack cannot be moved in this way - they aren't in play
// yet
void Game::LButtonDblClk(wxDC& dc, int x, int y)
{
    Pile* pile = WhichPile(x, y);
    if (!pile) return;

    // Double click on m_pack is the same as left button down
    if (pile == m_pack)
    {
        LButtonDown(dc, x, y);
    }
    else
    {
        Card* card = pile->GetTopCard();

        if (card)
        {
            int i;

            // if the card is an ace then try to place it next
            // to an ace of the same suit
            if (card->GetPipValue() == 1)
            {
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
                for(i = 0; i < 4; i++)
                {
                    Card* m_topCard = m_foundations[i]->GetTopCard();
                    if ( m_topCard )
                    {
                        if (m_topCard->GetSuit() == card->GetSuit() &&
                            m_foundations[i + 4] != pile &&
                            m_foundations[i + 4]->GetTopCard() == 0)
                        {
                            pile->RemoveTopCard(dc);
                            m_foundations[i + 4]->AddCard(dc, card);
                            DoMove(dc, pile, m_foundations[i + 4]);
                            return;
                        }
                    }
                }
            }

            // try to place the card on a foundation
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
            for(i = 0; i < 8; i++)
            {
                if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
                {
                    pile->RemoveTopCard(dc);
                    m_foundations[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_foundations[i]);
                    return;
                }
            }
            // try to place the card on a populated base
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->AcceptCard(card) &&
                    m_bases[i] != pile &&
                    m_bases[i]->GetTopCard())
                {
                    pile->RemoveTopCard(dc);
                    m_bases[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_bases[i]);
                    return;
                }
            }
            // try to place the card on any base
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->AcceptCard(card) && m_bases[i] != pile)
                {
                    pile->RemoveTopCard(dc);
                    m_bases[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_bases[i]);
                    return;
                }
            }
        }
    }
}