예제 #1
0
파일: CDeck.cpp 프로젝트: ricoz/tong-its
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;
    }
}
예제 #2
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;
    }
}
예제 #3
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;
}
예제 #4
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;
}
예제 #5
0
파일: main.cpp 프로젝트: akrutsinger/Cards
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);
			}
		}
	}
}
예제 #6
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;
    }
}
예제 #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;
}