Ejemplo n.º 1
0
bool CDeck::ShowTemp(int pRgn)
{
    int const Human = 2;
    pRgn -= TEMPSTART;

    if(TempPile[pRgn]->Empty() || TempPile[pRgn]->Size() < 3)
        return false;

    CCardStack *cs = new CCardStack;
    *cs = *(TempPile[pRgn]->GetCardStack());

    if(VerifySet(cs)) {

        cs->SetCardsFaceUp(true);

        TempPile[pRgn]->Clear();
        Sets[Human][this->GetEmptyStack(Human)] = cs;

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

        return true;
    }
    else {

        delete cs;
        return false;
    }
}
Ejemplo n.º 2
0
Archivo: CGame.cpp Proyecto: 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);
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
void HandleMouseDownEvent(SDL_Event &event)
{
	CCardRegion *srcReg;
	if(event.button.button == SDL_BUTTON_LEFT){
		srcReg = Scorpion.OnMouseDown(event.button.x, event.button.y);
		if(srcReg == NULL) return;
				//clicked on the top of the foundations
		if((srcReg->Id == CRD_TABLEAU) && srcReg->PtOnTop(event.button.x, event.button.y)){
			srcReg->SetCardFaceUp(true, srcReg->Size() - 1);
		}
		//clicked on the tableau or piles for dragging
		if(((srcReg->Id == CRD_TABLEAU) || (srcReg->Id == CRD_FOUNDATION)) && Scorpion.InitDrag(event.button.x, event.button.y)){
			startdrag = true;
			SDL_WM_GrabInput(SDL_GRAB_ON);
		}
		//clicked on the stock pile
		if(srcReg->Id == CRD_STOCK){
			//printf("clicked on stock pile\n");
			CCardStack *cs = new CCardStack;
			for(int i = 0; i < 4; i++){
				*cs = Scorpion[0].Pop(1);
				cs->SetCardsFaceUp(true);
				Scorpion.InitDrag(cs, -1, -1);
				Scorpion.DoDrop(&Scorpion[i]);
			}
		}
	}

	//substitute right-click for double-click event
	if(event.button.button == SDL_BUTTON_RIGHT){
		srcReg = Scorpion.OnMouseDown(event.button.x, event.button.y);
		if(srcReg == NULL) return;
		CCardRegion *cr;
		CCard card =  srcReg->GetCard(srcReg->Size()-1);

		//clicked on the top of the foundations
		if(((srcReg->Id == CRD_FOUNDATION) || (srcReg->Id == CRD_STOCK)) && card.FaceUp() && srcReg->PtOnTop(event.button.x, event.button.y)){
			if((cr = Scorpion.FindDropRegion(CRD_FOUNDATION, card))){
				CCardStack *cs = new CCardStack;
				*cs = srcReg->Pop(1);
				Scorpion.InitDrag(cs, -1 , -1);
				Scorpion.DoDrop(cr);
			}
		}
	}
}
Ejemplo n.º 6
0
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;
    }
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
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;
    }
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
0
bool CDeck::FindValidSet(int const pIdx)
{
    if(PlayerHand[pIdx]->GetNumSelectedCards() > 0)
        return false; //should not select any

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

    int Idx = 0;
    for(VI vi = Stack->begin(); vi != Stack->end(); ++vi) {

        SDL_PumpEvents();
        int Rank = vi->Rank();
        int Suit = vi->Suit();

        int a = PlayerHand[pIdx]->FindCard(Rank + 1, Suit);
        int b = PlayerHand[pIdx]->FindCard(Rank + 2, Suit);
        int c = PlayerHand[pIdx]->FindCard(Rank - 1, Suit);
        int d = PlayerHand[pIdx]->FindCard(Rank - 2, Suit);

        int e[3];	//cards with same suit
        e[0] = PlayerHand[pIdx]->FindMoreSameRank(0, Rank, Suit);
        if(e[0] != -1) {

            e[1] = PlayerHand[pIdx]->FindMoreSameRank(e[0] + 1, Rank, Suit);
            if(e[1] != -1)
                e[2] = PlayerHand[pIdx]->FindMoreSameRank(e[1] + 1, Rank, Suit);
        }

        if(a != -1 && b != -1) {

            PlayerHand[pIdx]->SelectCard(Idx);
            PlayerHand[pIdx]->SelectCard(a);
            PlayerHand[pIdx]->SelectCard(b);
            return true;
        }

        if(a != -1 && c != -1) {

            PlayerHand[pIdx]->SelectCard(Idx);
            PlayerHand[pIdx]->SelectCard(a);
            PlayerHand[pIdx]->SelectCard(c);
            return true;
        }

        if(c != -1 && d != -1) {

            PlayerHand[pIdx]->SelectCard(Idx);
            PlayerHand[pIdx]->SelectCard(c);
            PlayerHand[pIdx]->SelectCard(d);
            return true;
        }

        if(e[0] != -1 && e[1] != -1) {

            PlayerHand[pIdx]->SelectCard(Idx);
            PlayerHand[pIdx]->SelectCard(e[0]);
            PlayerHand[pIdx]->SelectCard(e[1]);
            if(e[2] != -1)
                PlayerHand[pIdx]->SelectCard(e[2]);
            return true;
        }

        Idx++;
    }//end of for loop
    return false;
}
Ejemplo n.º 11
0
Archivo: CGame.cpp Proyecto: ricoz/drac
CCardRegion* CGame::FindDropRegion(int Id, CCard card)
{
	CCardStack stack;
	stack.Push(card);
	return FindDropRegion(Id, stack);
}