void GameView::MouseUp(BPoint point) { mouselock=false; if(selected==NULL) return; card* card=NULL; short row=0; short stack=0; short saved=-1; bool special=false; for (short i=8;i<200;i++) { BPoint pt(85*(stack+1),40*(row+4)); BRect rect(pt,BPoint(pt.x+80,pt.y+116)); if (board[i]!=NULL) { if (rect.Contains(point)) { saved=i; } } row++; if (row==26) { row=0; stack++; } } BPoint deckPoints[]={ BPoint(-80,4),BPoint(-80,116),BPoint(0,116), BPoint(0,4)}; BPolygon* deck; for (short i=0;i<8;i++) { if (i==4) { for (int j=0;j<4;j++) { deckPoints[j].x+=80+4; } } for (int j=0;j<4;j++) { deckPoints[j].x+=80+4; } deck=new BPolygon(deckPoints,4); if (deck->Frame().Contains(point)) { special=true; saved=i; } } if (special) { if (saved<4) { if (selected->fNextCard==NULL && board[saved]==NULL) { board[saved]=selected; board[selected->oldNumber]=NULL; moves++; } }else{ if (selected->fNextCard==NULL) { if (board[saved]==NULL && selected->fValue==1 ) { goto putCardInStack; } if (board[saved]==NULL) return; if (board[saved]->fValue == selected->fValue-1 && selected->fColor == board[saved]->fColor) { putCardInStack: board[saved]=selected; board[selected->oldNumber]=NULL; moves++; if (board[4]->fValue==13 && board[5]->fValue==13 && board[6]->fValue==13 && board[7]->fValue==13) { BString winText=""; winText << "WIN!!!\n\n"; winText << "Congratulations, you have won"; winText << "SuperFreeCell!!\n\n"; winText << "Moves: " << moves; BAlert* win=new BAlert("Win",winText,"OK"); win->Go(); } } } } Invalidate(); selected=NULL; return; } for (short j=0;j<8;j++) { if (board[j*26+8]==NULL) { BPoint pt(85*(j+1),40*(4)); BRect rect(pt,BPoint(pt.x+80,pt.y+116)); if (rect.Contains(point)) { board[j*26+8]=selected; board[selected->oldNumber]=NULL; moves++; short k=0; while (selected->fNextCard!=NULL) { board[j*26+8+k+1]=selected->fNextCard; k++; struct card* temp_card=selected->fNextCard; selected->fNextCard=NULL; selected=temp_card; board[selected->oldNumber]=NULL; } Invalidate(); selected=NULL; return; } } } if (saved>=0 && saved<200) { if (board[saved+1]==NULL && (board[saved]->fValue -1 == selected->fValue)) { if (this->CheckSuite(selected->fColor,board[saved]->fColor)) { short j=1; board[saved+1]=selected; board[selected->oldNumber]=NULL; moves++; while (selected->fNextCard!=NULL) { board[saved+j+1]=selected->fNextCard; j++; struct card* temp_card=selected->fNextCard; selected->fNextCard=NULL; selected=temp_card; board[selected->oldNumber]=NULL; } } } } Invalidate(); selected=NULL; }
void GameView::Draw(BRect rect) { SetDrawingMode(B_OP_ALPHA); // Draw slots BPoint deckPoints[]={ BPoint(-80,4),BPoint(-80,116),BPoint(0,116), BPoint(0,4)}; BPolygon* deck; for (int i=0;i<8;i++) { if (i==4) { for (int j=0;j<4;j++) { deckPoints[j].x+=80+4; } } for (int j=0;j<4;j++) { deckPoints[j].x+=80+4; } deck=new BPolygon(deckPoints,4); StrokePolygon(deck); if (board[i]!=NULL) { DrawBitmap(board[i]->img,deck->Frame()); } } // Draw cards short row=0; short stack=0; for (short i=8;i<200;i++) { BBitmap* img=NULL; if (board[i]!=NULL) { img=board[i]->img; } BPoint pt(85*(stack+1),40*(row+4)); DrawBitmapAsync(img,pt); row++; if (row==26) { row=0; stack++; } } Sync(); // Draw Points BString movesText=""; movesText << moves; BFont bigFont; bigFont.SetFace(B_BOLD_FACE); bigFont.SetSize(18); BFont smallFont; smallFont.SetSize(12); SetHighColor(255,255,255); SetFont(&bigFont); DrawString(movesText, BPoint((width+10 - bigFont.StringWidth(movesText)) / 2, height-15)); SetFont(&smallFont); DrawString("Moves", BPoint((width+10 - smallFont.StringWidth("Moves")) / 2, height)); }
void GameView::MouseDown(BPoint point) { if(mouselock) return; mouselock=true; card* card=NULL; short row=0; short stack=0; short saved=-1; bool special=false; for (short i=8;i<200;i++) { BPoint pt(85*(stack+1),40*(row+4)); BRect rect(pt,BPoint(pt.x+80,pt.y+116)); if (board[i]!=NULL) { if (rect.Contains(point)) { saved=i; } } row++; if (row==26) { row=0; stack++; } } BPoint deckPoints[]={ BPoint(-80,4),BPoint(-80,116),BPoint(0,116), BPoint(0,4)}; BPolygon* deck; for (short i=0;i<8;i++) { if (i==4) { for (int j=0;j<4;j++) { deckPoints[j].x+=80+4; } } for (int j=0;j<4;j++) { deckPoints[j].x+=80+4; } deck=new BPolygon(deckPoints,4); if (deck->Frame().Contains(point)) { special=true; saved=i; } } if (special) { if (saved<4) { if (board[saved]==NULL) return; selected=board[saved]; selected->oldNumber=saved; DragMessage(new BMessage(B_SIMPLE_DATA),new BBitmap(selected->img), B_OP_BLEND,BPoint(0,0)); } return; } if (saved>=0 && this->CheckStack(saved)) { short j=0; while (board[saved+j+1]!=NULL) { board[saved+j+1]->oldNumber=saved+j+1; board[saved+j]->fNextCard=board[saved+j+1]; j++; } selected=board[saved]; selected->oldNumber=saved; DragMessage(new BMessage(B_SIMPLE_DATA),new BBitmap(selected->img), B_OP_BLEND,BPoint(0,0)); } }