Esempio n. 1
0
CardStack CreatePlayDeck()
{
    CardStack newStack;
    int i, colors = 1, num = 0;
    
    switch (dwDifficulty)
    {
        case IDC_DIF_ONECOLOR:
            colors = 1;
            break;
        case IDC_DIF_TWOCOLORS:
            colors = 2;
            break;
        case IDC_DIF_FOURCOLORS:
            colors = 4;
            break;
    }
    for (i = 0; i < NUM_SPIDER_CARDS; i++)
    {
        num += NUM_CARD_COLORS / colors;
        Card newCard(num % NUM_STD_CARDS);
        newStack.Push(newCard);
    }
    return newStack;
}
Esempio n. 2
0
int main()
{
	srand(time(NULL));
	CardStack cards;
	int players[NUM_PLAYERS];
	ofstream outFile;
	outFile.open("Output.txt");

	InitalizeScores(players);
	BuildDeck(cards);
	Header(players, outFile);

	while (cards.GetSize() != 0)
	{
		DealCards(cards, players, outFile);
	}

	DetermineWinner(players, outFile);

	cout << "Results have been sent to \"Output.txt\"\n";

	outFile.close();

	return 0;
}
Esempio n. 3
0
/* Cards dropped to a stack */
bool CARDLIBPROC StackDropProc(CardRegion &stackobj, CardStack &dragcards)
{
    Card dragcard = dragcards[dragcards.NumCards() - 1];
    int faceup, facedown;

    /* Only drop our cards on other stacks */
    if (stackobj.Id() == from->Id())
    {
        return false;
    }
    
    /* If stack is empty, everything can be dropped */
    if (stackobj.NumCards() != 0)
    {
        const CardStack &mystack = stackobj.GetCardStack();

        /* Can only drop if card is 1 less */
        if (mystack[0].LoVal() != dragcard.LoVal() + 1)
        {
            return false;
        }

        /* Check if stack complete */
        stackobj.GetFaceDirection(&facedown);
        faceup = stackobj.NumCards() - facedown;

        if (faceup + dragcards.NumCards() >= NUM_ONECOLOR_CARDS)
        {            
            int i, max = NUM_ONECOLOR_CARDS - dragcards.NumCards() - 1;

            /* Dragged cards have been checked to be in order, check stack cards */
            if (mystack[0].Suit() == dragcard.Suit() &&
                stackLookingGood(mystack, max)) 
            {
                CardStack s = stackobj.GetCardStack();
                CardStack f;

                /* Remove from card stack */
                for (i = 0; i < max + 1; i++)
                {
                    s.RemoveCard(0);
                }
                /* Remove dragged cards */
                dragcards = f;
                stackobj.SetCardStack(s);
                cardsFinished += NUM_ONECOLOR_CARDS;
                /* Flip top card of the dest stack */
                TurnStackCard(stackobj);
            }
        }
    }
    /* Flip the top card of the source stack */
    TurnStackCard(*from);
    fGameStarted = true;
    return true;
}
Esempio n. 4
0
void DealCards(CardStack& cards, int players[], ofstream& outFile)
{
	outFile << "  SCORE: ";
	for (int index = 0; index < NUM_PLAYERS; index++)
	{
		players[index] += cards.Top();
		cards.Pop();
		outFile << "\t" << players[index];
	}
	outFile << endl;
}
Esempio n. 5
0
CardStack* GameState::findById(int cardId, int* idx)
{
    for (int i=0; i<STACK_COUNT; i++)
    {
        CardStack* cs = getStack(i);
        for (int j=0; j<cs->size(); j++) {
            if ((*cs)[j].id == cardId) 
            {
                *idx = j;
                return cs;
            }
        }
    }

    return NULL_PTR;
}
Esempio n. 6
0
void BuildDeck(CardStack& cards)
{
	for (int index = 0; index < NUM_CARDS; index++)
	{
		//Num [2,14].
		cards.Push( rand() % 13 + 2);
	}
}
Esempio n. 7
0
/* Click on the deck */
void CARDLIBPROC DeckClickProc(CardRegion &stackobj, int NumDragCards)
{
    CardStack temp, fakeDeck = pDeck->GetCardStack();
    fGameStarted = true;

    if (fakeDeck.NumCards() != 0 && deck.NumCards() != 0)
    {
        int i, facedown, faceup;
        /* Add one card to every stack */
        for (i = 0; i < NUM_STACKS; i++)
        {
            temp = pStack[i]->GetCardStack();
            temp.Push(deck.Pop());

            /* Check if we accidentally finished a row */
            pStack[i]->GetFaceDirection(&facedown);
            faceup = temp.NumCards() - facedown;
            if (faceup >= NUM_ONECOLOR_CARDS)
            {
                /* Check stack finished, remove cards if so */
                if (stackLookingGood(temp, NUM_ONECOLOR_CARDS - 1))
                {
                    int j;
                    for (j = 0; j < NUM_ONECOLOR_CARDS; j++)
                    {
                        temp.RemoveCard(0);
                    }
                    cardsFinished += NUM_ONECOLOR_CARDS;
                    pStack[i]->SetCardStack(temp);
                    /* Turn now topmost card */
                    TurnStackCard(*pStack[i]);
                }
            }
            pStack[i]->SetCardStack(temp);
        }
        /* Remove one card from the fake ones */
        pDeck->SetCardStack(fakeDeck.Pop(fakeDeck.NumCards() - 1));
    }
    pDeck->Update();
    SpiderWnd.Redraw();
}
Esempio n. 8
0
void NewGame(void)
{
    int i, j;
    /* First four stack with five, all other with 4 */
    int covCards = 5; 
    CardStack fakeDeck, temp;

    SpiderWnd.EmptyStacks();

    /* Create a new card-deck, fake deck */
    deck = CreatePlayDeck();
    deck.Shuffle();
    fakeDeck.NewDeck();
    fakeDeck.Shuffle();
    
    /* Reset progress value */
    cardsFinished = 0;

    /* Deal to each stack */
    for (i = 0; i < NUM_STACKS; i++)
    {
        temp.Clear();       
        if (i == NUM_SMALLER_STACKS)
        {
            covCards--;
        }
        for (j = 0; j <= covCards; j++)
        {
            temp.Push(deck.Pop(1));
        }
        pStack[i]->SetFaceDirection(CS_FACE_DOWNUP, covCards);
        pStack[i]->SetCardStack(temp);
    }
    /* Deal five fake cards to the deck */
    pDeck->SetCardStack(fakeDeck.Pop(5));  

    SpiderWnd.Redraw();
    fGameStarted = false;
}
Esempio n. 9
0
//
//    Can only drop a card onto suit stack if it is same suit, and 1 higher
//
bool CARDLIBPROC SuitStackDropProc(CardRegion &stackobj, CardStack &dragcards)
{
    TRACE("ENTER SuitStackDropProc()\n");
    //only drop 1 card at a time
    if(dragcards.NumCards() != 1)
    {
        TRACE("EXIT SuitStackDropProc()\n");
        return false;
    }

    bool b = CanDrop(stackobj, dragcards[0]);
    TRACE("EXIT SuitStackDropProc()\n");
    return b;
}
Esempio n. 10
0
//
//    What happens when a card is removed from face-up pile?
//
void CARDLIBPROC PileRemoveProc(CardRegion &stackobj, int iItems)
{
    TRACE("ENTER PileRemoveProc()\n");
    //modify our "virtual" pile by removing the same card
    //that was removed from the physical card stack
    activepile.Pop(iItems);

    //if there is just 1 card left, then modify the
    //stack to contain ALL the face-up cards..the effect
    //will be, the next time a card is dragged, all the
    //previous card-triplets will be available underneath
    if(stackobj.NumCards() == 1)
    {
        stackobj.SetOffsets(0,0);
        stackobj.SetCardStack(activepile);
    }
    TRACE("EXIT PileRemoveProc()\n");
}
Esempio n. 11
0
void NewGame(void)
{
    TRACE("ENTER NewGame()\n");
    int i, j;

    SolWnd.EmptyStacks();

    //create a new card-stack
    CardStack deck;
    deck.NewDeck();
    deck.Shuffle();
    activepile.Clear();

    //deal to each row stack..
    for(i = 0; i < NUM_ROW_STACKS; i++)
    {
        CardStack temp;
        temp.Clear();

        pRowStack[i]->SetFaceDirection(CS_FACE_DOWNUP, i);

        for(j = 0; j <= i; j++)
        {
            temp.Push(deck.Pop());
        }

        pRowStack[i]->SetCardStack(temp);
    }

    //put the other cards onto the deck
    pDeck->SetCardStack(deck);
    pDeck->Update();

    // For the 1-card-mode, all cards need to be completely overlapped
    if(!(dwOptions & OPTION_THREE_CARDS))
        pPile->SetOffsets(0, 0);

    SolWnd.Redraw();

    fGameStarted = false;
    TRACE("EXIT NewGame()\n");
}
Esempio n. 12
0
//
//    Row a row-stack, we can only drop cards
//    that are lower / different colour
//
bool CARDLIBPROC RowStackDropProc(CardRegion &stackobj, CardStack &dragcards)
{
    TRACE("ENTER RowStackDropProc()\n");
    Card dragcard = dragcards[dragcards.NumCards() - 1];

    //if we are empty, can only drop a stack with a King at bottom
    if(stackobj.NumCards() == 0)
    {
        if(dragcard.LoVal() != 13)
        {
            TRACE("EXIT RowStackDropProc(false)\n");
            return false;
        }
    }
    else
    {
        const CardStack &mystack = stackobj.GetCardStack();

        //can only drop if card is 1 less
        if(mystack[0].LoVal() != dragcard.LoVal() + 1)
        {
            TRACE("EXIT RowStackDropProc(false)\n");
            return false;
        }

        //can only drop if card is different colour
        if( (mystack[0].IsBlack() && !dragcard.IsRed()) ||
           (!mystack[0].IsBlack() &&  dragcard.IsRed()) )
        {
            TRACE("EXIT RowStackDropProc(false)\n");
            return false;
        }
    }

    fGameStarted = true;

    TRACE("EXIT RowStackDropProc(true)\n");
    return true;
}
Esempio n. 13
0
//
//    Double-click on the deck
//    Move 3 cards to the face-up pile
//
void CARDLIBPROC DeckClickProc(CardRegion &stackobj, int iNumClicked)
{
    TRACE("ENTER DeckClickProc()\n");
    CardStack cardstack = stackobj.GetCardStack();
    CardStack pile      = pPile->GetCardStack();

    fGameStarted = true;

    //reset the face-up pile to represent 3 cards
    if(dwOptions & OPTION_THREE_CARDS)
        pPile->SetOffsets(CS_DEFXOFF, 1);

    if(cardstack.NumCards() == 0)
    {
        pile.Clear();

        activepile.Reverse();
        cardstack.Push(activepile);
        activepile.Clear();
    }
    else
    {
        int numcards = min((dwOptions & OPTION_THREE_CARDS) ? 3 : 1, cardstack.NumCards());

        //make a "visible" copy of these cards
        CardStack temp;
        temp = cardstack.Pop(numcards);
        temp.Reverse();

        if(dwOptions & OPTION_THREE_CARDS)
            pile.Clear();

        pile.Push(temp);

        //remove the top 3 from deck
        activepile.Push(temp);
    }

    activepile.Print();

    pDeck->SetCardStack(cardstack);
    pPile->SetCardStack(pile);

    SolWnd.Redraw();
    TRACE("EXIT DeckClickProc()\n");
}
Esempio n. 14
0
void CreateSol()
{
    int i;

//    hbmBitmap = (HBITMAP)LoadImage(0,"test.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
//    SolWnd.SetBackImage(hbmBitmap);

    activepile.Clear();

    // Compute the value for yRowStackCardOffset based on the height of the card, so the card number isn't hidden on larger cards
    yRowStackCardOffset = (int)(__cardheight / 6.7);

    pDeck = SolWnd.CreateRegion(DECK_ID, true, X_BORDER, Y_BORDER, 2, 1);
    pDeck->SetEmptyImage(CS_EI_CIRC);
    pDeck->SetThreedCount(6);
    pDeck->SetDragRule(CS_DRAG_NONE, 0);
    pDeck->SetDropRule(CS_DROP_NONE, 0);
    pDeck->SetClickProc(DeckClickProc);
    pDeck->SetDblClickProc(DeckClickProc);
    pDeck->SetFaceDirection(CS_FACE_DOWN, 0);

    pPile = SolWnd.CreateRegion(PILE_ID, true, X_BORDER + __cardwidth + X_PILE_BORDER, Y_BORDER, CS_DEFXOFF, 1);
    pPile->SetEmptyImage(CS_EI_NONE);
    pPile->SetDragRule(CS_DRAG_TOP, 0);
    pPile->SetDropRule(CS_DROP_NONE, 0);
    pPile->SetDblClickProc(PileDblClickProc);
    pPile->SetRemoveCardProc(PileRemoveProc);

    //
    //    Create the suit stacks
    //
    for(i = 0; i < 4; i++)
    {
        pSuitStack[i] = SolWnd.CreateRegion(SUIT_ID+i, true, 0, Y_BORDER, 0, 0);
        pSuitStack[i]->SetEmptyImage(CS_EI_SUNK);
        pSuitStack[i]->SetPlacement(CS_XJUST_CENTER, 0, i * (__cardwidth + X_SUITSTACK_BORDER) , 0);

        pSuitStack[i]->SetDropRule(CS_DROP_CALLBACK, SuitStackDropProc);
        pSuitStack[i]->SetDragRule(CS_DRAG_TOP);

        pSuitStack[i]->SetAddCardProc(SuitStackAddProc);
    }

    //
    //    Create the row stacks
    //
    for(i = 0; i < NUM_ROW_STACKS; i++)
    {
        pRowStack[i] = SolWnd.CreateRegion(ROW_ID+i, true, 0, Y_BORDER + __cardheight + Y_ROWSTACK_BORDER, 0, yRowStackCardOffset);
        pRowStack[i]->SetEmptyImage(CS_EI_SUNK);
        pRowStack[i]->SetFaceDirection(CS_FACE_DOWNUP, i);

        pRowStack[i]->SetPlacement(CS_XJUST_CENTER, 0,
            (i - NUM_ROW_STACKS/2) * (__cardwidth + X_ROWSTACK_BORDER),     0);

        pRowStack[i]->SetEmptyImage(CS_EI_NONE);

        pRowStack[i]->SetDragRule(CS_DRAG_CALLBACK, RowStackDragProc);
        pRowStack[i]->SetDropRule(CS_DROP_CALLBACK, RowStackDropProc);
        pRowStack[i]->SetClickProc(RowStackClickProc);
        pRowStack[i]->SetDblClickProc(RowStackDblClickProc);
    }
}
Esempio n. 15
0
bool CardRegion::OnLButtonUp(int x, int y)
{
    CardRegion *pDestStack = 0;
    HDC hdc;
    int dropstackid = CS_DROPZONE_NODROP;

    RECT dragrect;
    DropZone *dropzone;

    fMouseDragging = false;

    //first of all, see if any drop zones have been registered
    SetRect(&dragrect, x-mousexoffset, y-mouseyoffset, x-mousexoffset+nDragCardWidth, y-mouseyoffset+nDragCardHeight);

    dropzone = parentWnd.GetDropZoneFromRect(&dragrect);

    if(dropzone)
    {
        dropstackid = dropzone->DropCards(dragstack);

        if(dropstackid != CS_DROPZONE_NODROP)
            pDestStack = parentWnd.CardRegionFromId(dropstackid);
        else
            pDestStack = 0;
    }
    else
    {
        pDestStack = parentWnd.GetBestStack(x - mousexoffset, y - mouseyoffset, nDragCardWidth, nDragCardHeight);
    }

    // If have found a stack to drop onto
    //
    TRACE ( "can I drop card?\n" );
    if(pDestStack && pDestStack->CanDropCards(dragstack))
    {
        TRACE ( "yes, dropping card\n" );
        hdc = GetDC((HWND)parentWnd);
        //            UseNicePalette(hdc);
        ZoomCard(hdc, x - mousexoffset, y  - mouseyoffset, pDestStack);
        ReleaseDC((HWND)parentWnd, hdc);

        //
        //add the cards to the destination stack
        //
        CardStack temp = pDestStack->GetCardStack();
        temp.Push(dragstack);

        pDestStack->SetCardStack(temp);
//        pDestStack->Update();        //Update this stack's card count + size
//        pDestStack->UpdateFaceDir(temp);

        //    Call the remove callback on THIS stack, if one is specified
        //
        if(RemoveCallback)
            RemoveCallback(*this, iNumDragCards);

        //    Call the add callback, if one is specified
        //
        if(pDestStack->AddCallback)
            pDestStack->AddCallback(*pDestStack, pDestStack->cardstack);//index, deststack->numcards);

        RedrawIfNotDim(pDestStack, true);
        TRACE ( "done dropping card\n" );
    }

    //
    //    Otherwise, let the cards snap back onto this stack
    //
    else
    {
        TRACE ( "no, putting card back\n" );
        hdc = GetDC((HWND)parentWnd);
        TRACE ( "calling ZoomCard()\n" );
        ZoomCard(hdc, x - mousexoffset, y - mouseyoffset, this);
        TRACE ( "cardstack += dragstack\n" );
        cardstack += dragstack;
        TRACE ( "calling ReleaseDC()\n" );
        ReleaseDC((HWND)parentWnd, hdc);

        TRACE ( "calling Update()\n" );
        Update();        //Update this stack's card count + size
        TRACE ( "done putting card back\n" );
    }

    ReleaseDragBitmaps();
    ReleaseCapture();

    TRACE ( "OnLButtonUp() done\n" );
    return true;
}
Esempio n. 16
0
void GameBoard::showValidTurn()
{
	std::map<PlayingCard*, int> srcCards;
	std::map<PlayingCard*, int> dstCards;
	std::vector<std::pair<int, int> > validTurns;
	std::vector<std::pair<int, PlayingCard*> > indexMap;

	for(int iColumn = 0; iColumn < k_cardColumnCount; iColumn++)
	{
		CardStack* topStack = m_cardColumns[iColumn].getTopStack();
		if(topStack == 0) 
		{
			continue;
		}

		dstCards.insert(std::make_pair(topStack->getTopCard(), iColumn));

		CardStackIterator& it = topStack->getCardIterator();
		for(; !it.isLast(); it.moveNext())
		{
			PlayingCard* card = it.getCurrent();
			srcCards.insert(std::make_pair(card, iColumn));
		}
	}

	
	for(std::map<PlayingCard*, int>::iterator src_it = srcCards.begin();
		src_it != srcCards.end(); ++src_it)
	{
		PlayingCard* srcCard = src_it->first;
		int iSrcColumn = src_it->second;

		for(std::map<PlayingCard*, int>::iterator dst_it = dstCards.begin();
			dst_it != dstCards.end(); ++dst_it)
		{
			PlayingCard* dstCard = dst_it->first;
			int iDstColumn = dst_it->second;

			if(iSrcColumn == iDstColumn) continue;

			if((srcCard->getRank() + 1) == dstCard->getRank())
			{
				validTurns.push_back(std::make_pair(src_it->second, dst_it->second));
				
				int index = validTurns.size() - 1;
				indexMap.push_back(std::make_pair(index, srcCard));				
			}
		}//for(std::map<PlayingCard*, int>::iterator dst_it = dstCards.begin();
	}//for(std::map<PlayingCard*, int>::iterator src_it = srcCards.begin();

	SoundManager& sndManager = SoundManager::getInstance(); 
	if(validTurns.size() > 0)
	{
		std::random_shuffle(indexMap.begin(), indexMap.end());
		int index = indexMap[0].first;
		int iSrcColumn = validTurns[index].first;
		int iDstColumn = validTurns[index].second;
		PlayingCard* srcCard = indexMap[0].second;
		PlayingCard* dstCard = m_cardColumns[iDstColumn].getTopCard();

		CardStack* stack = m_cardColumns[iSrcColumn].getTopStack();
		CardStack::PlayingCardsStack& cards = stack->getCards();
		CardStack::PlayingCardsStack::iterator find_it = std::find(cards.begin(), cards.end(), srcCard);		
		CardList srcCardList(find_it, cards.end());
				

		sndManager.playSound(k_soundValidTurnExist);		
		m_showValidTurnAnimator.beginAnimation(srcCardList, dstCard);				
	}else
	{
		sndManager.playSound(k_soundValidTurnAbsent);
	}
}