예제 #1
0
파일: CDeck.cpp 프로젝트: ricoz/tong-its
bool CDeck::Show(int const pIdx, int pRgn)
{
    if(PlayerHand[pIdx]->GetNumSelectedCards() < 3)
        return false; //too few selected cards

    if(pRgn != -1) {

        pRgn -= SETSTART;
        if(pIdx != pRgn) return false; //should click on your own sets
    }

    CCardStack *cs = new CCardStack;
    cs->Push(PlayerHand[pIdx]->GetSelectedCards());

    if(VerifySet(cs)) {

        cs->Clear();
        cs->Push(PlayerHand[pIdx]->PopSelectedCards());
        cs->SetCardsFaceUp(true);
        cs->Sort();

        Sets[pIdx][this->GetEmptyStack(pIdx)] = cs;

        mGame.InitDrag(cs, PlayerHand[pIdx], -1 , -1);
        mGame.DoDrop(ValidSet[pIdx]);

        return true;
    }
    else {
        PlayerHand[pIdx]->InitCardCoords();
        return false;
    }
}
예제 #2
0
파일: CDeck.cpp 프로젝트: ricoz/tong-its
bool CDeck::Sapaw(int const pIdx, int pRgn)
{
    if(PlayerHand[pIdx]->GetNumSelectedCards() < 1)
        return false; //too few selected cards

    pRgn -= SETSTART;

    CCardStack *cs = new CCardStack;

    for(int j = 0; j < 6; j++) {

        SDL_PumpEvents();

        if((Sets[pRgn][j] != NULL) && !Sets[pRgn][j]->Empty()) {

            cs->Clear();
            cs->Push(PlayerHand[pIdx]->GetSelectedCards());
            CCardStack set = *Sets[pRgn][j];
            cs->Push(set);

            if(VerifySet(cs)) {

                cs->Clear();
                cs->Push(PlayerHand[pIdx]->PopSelectedCards());
                cs->SetCardsFaceUp(true);

                Sets[pRgn][j]->Push(*cs);
                Sets[pRgn][j]->Sort();

                mGame.InitDrag(cs, PlayerHand[pIdx], -1 , -1);
                mGame.DoDrop(ValidSet[pRgn]);

                ValidSet[pRgn]->Clear();
                ValidSet[pRgn]->Push(ExtractSet(pRgn));
                ValidSet[pRgn]->InitCardCoords();

                mGame.DrawStaticScene();

                if(pRgn != pIdx)
                    Nasapawan[pRgn] = true;//CALL

                return true;
            }
        }
    }

    delete cs;
    return false;
}
예제 #3
0
파일: CGame.cpp 프로젝트: ricoz/drac
// optimization needed
void CGame::DoDrop(CCardRegion *DestRegion)
{
	CCardStack *DestStack;
	CCardRegion *BestRegion;

	if(DestRegion != NULL) BestRegion = DestRegion;
//	else BestRegion = this->GetBestStack(dcard.x, dcard.y, dcard.width, dcard.height, &DragStack);
	else BestRegion = this->GetBestStack(dcard.x, dcard.y, CARDWIDTH, CARDHEIGHT, &DragStack);
	if(BestRegion == NULL) BestRegion = SourceRegion;

	DestStack = BestRegion->GetCardStack();
	DestStack->Push(DragStack);
	BestRegion->InitCardCoords();

	VI vi;
	switch(SourceRegion->GetDragMode())
	{
		case 2:
		case 3:
			vi = DestStack->end() - 1;
			break;
		default: // 1 and 4
			vi = DestStack->end() - DragStack.Size();
	}

	DragStack.Clear();

	//when no movement
	if(dcard.x == vi->x && dcard.y == vi->y)
		return;

	ZoomCard(dcard.x, dcard.y, vi->x, vi->y, dcard.width, dcard.height, background, dragface);
}
예제 #4
0
파일: CDeck.cpp 프로젝트: ricoz/tong-its
CCardStack CDeck::ExtractSet(int const pIdx)
{
    CCardStack set;

    for(int j = 0; j < 6; j++) {

        if(Sets[pIdx][j] != NULL)
            set.Push(*Sets[pIdx][j]);
    }

    return set;
}
예제 #5
0
파일: CDeck.cpp 프로젝트: ricoz/tong-its
bool CDeck::Chow(int const pIdx)
{
    if(PlayerHand[pIdx]->GetNumSelectedCards() < 2)
        return false; //too few selected cards

    if(DumpPile->Empty())
        return false;

    if(!TransferPile->Empty())
        return false;

    CCard thrown = DumpPile->Pop(); //push again if unsuccessful

    CCardStack *cs = new CCardStack;
    cs->Push(thrown);
    cs->Push(PlayerHand[pIdx]->GetSelectedCards());

    if(VerifySet(cs)) {

        cs->Clear();
        cs->Push(thrown);
        cs->Push(PlayerHand[pIdx]->PopSelectedCards());
        cs->SetCardsFaceUp(true);
        cs->Sort();

        Sets[pIdx][this->GetEmptyStack(pIdx)] = cs;

        mGame.InitDrag(cs, PlayerHand[pIdx], -1 , -1);
        mGame.DoDrop(ValidSet[pIdx]);

        return true;
    }
    else {
        DumpPile->Push(thrown);
        DumpPile->InitCardCoords();
        PlayerHand[pIdx]->InitCardCoords();
        return false;
    }
}
예제 #6
0
파일: CDeck.cpp 프로젝트: ricoz/tong-its
bool CDeck::DumpACard(int const pIdx)
{
    if( (PlayerHand[pIdx]->GetNumSelectedCards() > 1) || (PlayerHand[pIdx]->GetNumSelectedCards() < 1) )
        return false; //too many or too few cards to dump

    CCardStack *cs = new CCardStack;
    cs->Push(PlayerHand[pIdx]->PopSelectedCards());
    cs->SetCardsFaceUp(true);

    //Doesn't refresh the card locations for robots so we should manually refresh
    PlayerHand[pIdx]->InitCardCoords();
    mGame.InitDrag(cs, PlayerHand[pIdx], -1 , -1);
    mGame.DoDrop(DumpPile);

    return true;
}
예제 #7
0
파일: CDeck.cpp 프로젝트: ricoz/tong-its
bool CDeck::AutoSapaw(int const pIdx)
{
    //This disables strategy, the player may want to choose where to sapaw
    //in order to inhibit his opponents from 'calling'

    CCardStack *Stack = PlayerHand[pIdx]->GetCardStack();

    int Idx = 0;
    //checks all the cards, performs sapaw until not able to do so
    for(VI vi = Stack->begin(); vi != Stack->end(); ++vi) {

        PlayerHand[pIdx]->SelectCard(Idx);

        CCardStack *cs = new CCardStack;

        for(int i = 0; i < 3; i++) {

            for(int j = 0; j < 6; j++) {

                SDL_PumpEvents();
                if((Sets[i][j] != NULL) && !Sets[i][j]->Empty()) {

                    cs->Clear();
                    cs->Push(PlayerHand[pIdx]->GetSelectedCards());
                    CCardStack set = *Sets[i][j];
                    cs->Push(set);

                    if(VerifySet(cs)) {

                        cs->Clear();
                        cs->Push(PlayerHand[pIdx]->PopSelectedCards());
                        cs->SetCardsFaceUp(true);

                        Sets[i][j]->Push(*cs);
                        Sets[i][j]->Sort();

                        mGame.InitDrag(cs, PlayerHand[pIdx], -1 , -1);
                        mGame.DoDrop(ValidSet[i]);

                        ValidSet[i]->Clear();
                        ValidSet[i]->Push(ExtractSet(i));
                        ValidSet[i]->InitCardCoords();

                        mGame.DrawStaticScene();

                        if(i != pIdx)
                            Nasapawan[i] = true;//CALL

                        return true;
                    }
                }
            }
        }

        PlayerHand[pIdx]->InitCardCoords(); //select a different card
        Idx++;
        delete cs;

    }//end of for loop

    PlayerHand[pIdx]->InitCardCoords();
    return false;
}
예제 #8
0
파일: CGame.cpp 프로젝트: ricoz/drac
CCardRegion* CGame::FindDropRegion(int Id, CCard card)
{
	CCardStack stack;
	stack.Push(card);
	return FindDropRegion(Id, stack);
}