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); } } } }
void HandleMouseUpEvent(SDL_Event &event) { if(startdrag){ startdrag = false; Scorpion.DoDrop(); SDL_WM_GrabInput(SDL_GRAB_OFF); } if(Scorpion[0].Empty()){ Scorpion[0].SetSymbol(1); Scorpion.DrawStaticScene(); } //Victory: When we have 4 stacks from King to Ace of the same suit int ordered_stacks = 0; for(int i = 1; i < 8; i++){ if(Scorpion[i].SuitBuilt()){ ordered_stacks++; } if(ordered_stacks == 4){ AnimateCards(); NewGame(); Scorpion.DrawStaticScene(); } } }