// enum CARD_SUIT { // CARD_SUIT_SPADES, // CARD_SUIT_HEARTS, // CARD_SUIT_CLUBS, // CARD_SUIT_DIAMONDS }; struct SCard { CARD_SUIT Suit;// long Value;// bool Visible;//true- } sCard_Box[13][53];// 52
//---------------------------------------------------------------------------------------------------- // s d //---------------------------------------------------------------------------------------------------- bool CWnd_Main::MoveCard(long s,long d) { long n; long s_end=0; long d_end=0; // for(n=0;n<53;n++) { s_end=n; if (sCard_Box[s][n].Value<0) break; } for(n=0;n<53;n++) { d_end=n; if (sCard_Box[d][n].Value<0) break; } if (s_end==0) return(false);// // sCard_Box[d][d_end]=sCard_Box[s][s_end-1]; sCard_Box[s][s_end-1].Value=-1;// return(true); }
//---------------------------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------------------------- void CWnd_Main::RotatePool(void) { bool r=MoveCard(0,1);// if (r==false)// { // while(MoveCard(1,0)==true); } }
//---------------------------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------------------------- void CWnd_Main::InitGame(void) { TimerMode=TIMER_MODE_NONE; long value=sCursor.Number[0]+10*sCursor.Number[1]+100*sCursor.Number[2]+1000*sCursor.Number[3]+10000*sCursor.Number[4]; srand(value); long n,m,s; // for(s=0;s<13;s++) for(n=0;n<53;n++) sCard_Box[s][n].Value=-1; // long index=0; CARD_SUIT suit[4]={CARD_SUIT_SPADES,CARD_SUIT_HEARTS,CARD_SUIT_CLUBS,CARD_SUIT_DIAMONDS}; for(s=0;s<4;s++) { for(n=0;n<13;n++,index++) { sCard_Box[0][index].Value=n;// sCard_Box[0][index].Suit=suit[s]; sCard_Box[0][index].Visible=true; } } // for(n=0;n<7;n++) { for(m=0;m<=n;m++) { long change=RND(100); for(s=0;s<=change;s++) RotatePool();// // if (MoveCard(0,n+2)==false)// 0 - { m--; continue; } long amount=GetCardInBox(n+2); if (amount>0) sCard_Box[n+2][amount-1].Visible=false;// } } // while(1) { if (GetCardInBox(1)==0) break;// 1 RotatePool();// } }
//---------------------------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------------------------- long CWnd_Main::GetCardInBox(long box) { long n; long amount=0; for(n=0;n<53;n++) { if (sCard_Box[box][n].Value<0) break; amount++; } return(amount); }
//---------------------------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------------------------- void CWnd_Main::OnVisibleCard(void) { long n; for(n=2;n<9;n++) { long amount=GetCardInBox(n); if (amount>0) sCard_Box[n][amount-1].Visible=true; } }
//---------------------------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------------------------- void CWnd_Main::ChangeBox(long s_box,long s_index,long d_box) { long n; long d_end=0; // for(n=0;n<52;n++) { d_end=n; if (sCard_Box[d_box][n].Value<0) break; } // for(n=s_index;n<52;n++,d_end++) { if (sCard_Box[s_box][n].Value<0) break; sCard_Box[d_box][d_end]=sCard_Box[s_box][n]; sCard_Box[s_box][n].Value=-1;// } }
//---------------------------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------------------------- void CWnd_Main::ChangeCard(long s_box,long s_index,long d_box,long d_index) { if (d_box>=2 && d_box<9)// { // , if (d_index<0) { if (sCard_Box[s_box][s_index].Value==12) ChangeBox(s_box,s_index,d_box);// - , return; } //, if (sCard_Box[d_box][d_index].Value<=sCard_Box[s_box][s_index].Value) return;// , , if (sCard_Box[d_box][d_index].Value>sCard_Box[s_box][s_index].Value+1) return;// , 1 CARD_SUIT md=sCard_Box[d_box][d_index].Suit; CARD_SUIT ms=sCard_Box[s_box][s_index].Suit; if ((md==CARD_SUIT_SPADES || md==CARD_SUIT_CLUBS) && (ms==CARD_SUIT_SPADES || ms==CARD_SUIT_CLUBS)) return;// if ((md==CARD_SUIT_HEARTS || md==CARD_SUIT_DIAMONDS) && (ms==CARD_SUIT_HEARTS || ms==CARD_SUIT_DIAMONDS)) return;// ChangeBox(s_box,s_index,d_box);// return; } if (d_box>=9 && d_box<13)// { // , - if (GetCardInBox(s_box)>s_index+1) return; // , if (d_index<0) { if (sCard_Box[s_box][s_index].Value==0)// - , { DrawMoveCard(s_box,s_index,d_box); } return; } //, if (sCard_Box[d_box][d_index].Value>sCard_Box[s_box][s_index].Value) return;// , , if (sCard_Box[d_box][d_index].Value+1<sCard_Box[s_box][s_index].Value) return;// , 1 CARD_SUIT md=sCard_Box[d_box][d_index].Suit; CARD_SUIT ms=sCard_Box[s_box][s_index].Suit; if (ms!=md) return;// DrawMoveCard(s_box,s_index,d_box); return; } }
//---------------------------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------------------------- bool CWnd_Main::CheckFinish(void) { long n; for(n=9;n<13;n++) { if (GetCardInBox(n)!=13) return(false); } return(true); }
// long BoxXPos[13][53]; long BoxYPos[13][53];
// X #define BOX_WIDTH 30 // 0 2 X Y #define BOX_0_1_OFFSET_X 5 #define BOX_0_1_OFFSET_Y 5 // 2 8 X Y #define BOX_2_8_OFFSET_X 5 #define BOX_2_8_OFFSET_Y 45 // 9 12 X Y #define BOX_9_12_OFFSET_X 95 #define BOX_9_12_OFFSET_Y 5 // #define CARD_DX_OFFSET 10 // PSP #define SIZE_SCALE 2 for(n=0;n<13;n++) { long xl=0; long yl=0; long dx=0; long dy=0; if (n<2) { xl=BOX_0_1_OFFSET_X+BOX_WIDTH*n; yl=BOX_0_1_OFFSET_Y; xl*=SIZE_SCALE; yl*=SIZE_SCALE; dx=0; dy=0; } if (n>=2 && n<9) { xl=BOX_2_8_OFFSET_X+BOX_WIDTH*(n-2); yl=BOX_2_8_OFFSET_Y; xl*=SIZE_SCALE; yl*=SIZE_SCALE; dx=0; dy=CARD_DX_OFFSET*SIZE_SCALE; } if (n>=9 && n<13) { xl=BOX_9_12_OFFSET_X+(n-9)*BOX_WIDTH; yl=BOX_9_12_OFFSET_Y; xl*=SIZE_SCALE; yl*=SIZE_SCALE; dx=0; dy=0; } for(m=0;m<53;m++) { BoxXPos[n][m]=xl+dx*m; BoxYPos[n][m]=yl+dy*m; } }
// X #define CARD_WIDTH 27 // Y #define CARD_HEIGHT 37 //---------------------------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------------------------- bool CWnd_Main::GetSelectBoxParam(long x,long y,long *box,long *index) { *box=-1; *index=-1; long n,m; // "" for(n=0;n<13;n++) { long amount; amount=GetCardInBox(n); for(m=0;m<=amount;m++)// m<=amount 53- ( ) { long xl=BoxXPos[n][m]; long yl=BoxYPos[n][m]; long xr=xl+CARD_WIDTH*SIZE_SCALE; long yr=yl+CARD_HEIGHT*SIZE_SCALE; if (x>=xl && x<=xr && y>=yl && y<=yr) { *box=n; if (m<amount) *index=m; } } } if (*box<0) return(false); return(true); }
Source: https://habr.com/ru/post/330470/
All Articles