重做斗地主View.cpp
资源名称:DouDiZhu.rar [点击查看]
上传用户:xyf7799
上传日期:2022-08-01
资源大小:2008k
文件大小:47k
源码类别:
棋牌游戏
开发平台:
Visual C++
- // 重做斗地主View.cpp : implementation of the CMyView class
- //
- #include "stdafx.h"
- #include "重做斗地主.h"
- #include "重做斗地主Doc.h"
- #include "重做斗地主View.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMyView
- IMPLEMENT_DYNCREATE(CMyView, CView)
- BEGIN_MESSAGE_MAP(CMyView, CView)
- //{{AFX_MSG_MAP(CMyView)
- ON_WM_LBUTTONDOWN()
- ON_WM_RBUTTONDOWN()
- ON_COMMAND(IDM_BAN_START, OnBanStart)
- ON_WM_KEYDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyView construction/destruction
- CMyView::CMyView()
- {
- // TODO: add construction code here
- //位图的引入
- for(int i=0;i<54;i++)
- {
- bmpPai[i].LoadBitmap(IDB_BITMAP1+i);
- }
- bmpTable.LoadBitmap(IDB_BITMAP55);
- bmpCusor.LoadBitmap(IDB_BITMAP56);
- bmpNull.LoadBitmap(IDB_BITMAP57);
- bmpZheDang.LoadBitmap(IDB_BITMAP61);
- for(i=0;i<3;i++)
- {
- bmpTurn[i].LoadBitmap(IDB_BITMAP58+i);
- }
- //初始化所有的牌组
- for(i=0;i<20;i++)
- {
- P[i].z=0;
- C1[i].z=0;
- C2[i].z=0;
- L[i].z=0;
- nCusor[i]=0;
- F[i].z=0;
- }
- //定义地主是谁
- srand(GetTickCount());
- nIsDiZhu=rand()%3;
- nIsWho=nIsDiZhu;
- nLastFormWho=2;
- for(i=0;i<3;i++)
- {
- nZongZiJin[i]=1000;
- }
- //发牌
- srand(GetTickCount());
- i=0;
- int j=0;
- int DiZhuPai[3];
- int temp;
- BOOL isChongFu=FALSE;
- for(i=0;i<3;i++)
- {
- DiZhuPai[i]=0;
- }
- //先定义三张地主牌
- i=0;
- while(i<3)
- {
- temp=rand()%54+1;
- for(j=0;j<3;j++)
- {
- if(DiZhuPai[j]==temp)
- isChongFu=TRUE;
- break;
- }
- if(isChongFu==FALSE)
- {
- DiZhuPai[i]=temp;
- i++;
- }
- isChongFu=FALSE;
- }
- switch(nIsDiZhu)
- {
- case 0:
- C1[19].z=DiZhuPai[2];
- C1[18].z=DiZhuPai[1];
- C1[17].z=DiZhuPai[0];
- break;
- case 1:
- C2[19].z=DiZhuPai[2];
- C2[18].z=DiZhuPai[1];
- C2[17].z=DiZhuPai[0];
- break;
- case 2:
- P[19].z=DiZhuPai[2];
- P[18].z=DiZhuPai[1];
- P[17].z=DiZhuPai[0];
- break;
- default:
- break;
- }
- //下面是定义剩下的牌
- i=1;
- int a=0;
- int b=0;
- int c=0;
- while(i<=54)
- {
- if(i==DiZhuPai[0]||i==DiZhuPai[1]||i==DiZhuPai[2])
- {
- i++;
- }
- else
- {
- j=rand()%3;
- switch(j)
- {
- case 0:
- if(a<17)
- {
- C1[a].z=i;
- a++;
- i++;
- }
- break;
- case 1:
- if(b<17)
- {
- C2[b].z=i;
- b++;
- i++;
- }
- break;
- case 2:
- if(c<17)
- {
- P[c].z=i;
- c++;
- i++;
- }
- break;
- default:
- break;
- }
- }
- }
- PaiXu(0);
- PaiXu(1);
- PaiXu(2);
- }
- CMyView::~CMyView()
- {
- }
- BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyView drawing
- void CMyView::OnDraw(CDC* pDC)
- {
- CMyDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- //牌桌和牌的显示
- CDC dc;
- dc.CreateCompatibleDC(pDC);
- dc.SelectObject(bmpTable);
- pDC->StretchBlt(0,0,640,410,&dc,0,0,640,410,SRCCOPY);
- for(int i=0;i<20;i++)
- {
- if(C1[i].z!=0)
- {
- TransparentBitmap(pDC->GetSafeHdc(),bmpPai[C1[i].z-1],i*32,150,0,0,RGB(0,0,255));
- }
- else
- {
- TransparentBitmap(pDC->GetSafeHdc(),bmpNull,i*32,150,0,0,RGB(255,255,255));
- }
- }
- for(i=0;i<20;i++)
- {
- if(C2[i].z!=0)
- {
- TransparentBitmap(pDC->GetSafeHdc(),bmpPai[C2[i].z-1],i*32,214,0,0,RGB(0,0,255));
- }
- else
- {
- TransparentBitmap(pDC->GetSafeHdc(),bmpNull,i*32,214,0,0,RGB(255,255,255));
- }
- }
- for(i=0;i<20;i++)
- {
- if(P[i].z!=0)
- {
- TransparentBitmap(pDC->GetSafeHdc(),bmpPai[P[i].z-1],i*32,278,0,0,RGB(0,0,255));
- }
- else
- {
- TransparentBitmap(pDC->GetSafeHdc(),bmpNull,i*32,278,0,0,RGB(255,255,255));
- }
- }
- for(i=0;i<20;i++)
- {
- if(L[i].z!=0)
- {
- TransparentBitmap(pDC->GetSafeHdc(),bmpPai[L[i].z-1],i*32,342,0,0,RGB(0,0,255));
- }
- else
- {
- TransparentBitmap(pDC->GetSafeHdc(),bmpNull,i*32,342,0,0,RGB(255,255,255));
- }
- }
- //光标和轮到谁的显示
- switch(nIsWho)
- {
- case 0:
- TransparentBitmap(pDC->GetSafeHdc(),bmpTurn[0],0,0,0,0,RGB(0,0,255));
- for(i=0;i<20;i++)
- {
- if(nCusor[i]==1)
- TransparentBitmap(pDC->GetSafeHdc(),bmpCusor,i*32,150,0,0,RGB(255,255,255));
- }
- break;
- case 1:
- TransparentBitmap(pDC->GetSafeHdc(),bmpTurn[1],0,0,0,0,RGB(0,0,255));
- for(i=0;i<20;i++)
- {
- if(nCusor[i]==1)
- TransparentBitmap(pDC->GetSafeHdc(),bmpCusor,i*32,214,0,0,RGB(255,255,255));
- }
- break;
- case 2:
- TransparentBitmap(pDC->GetSafeHdc(),bmpTurn[2],0,0,0,0,RGB(0,0,255));
- for(i=0;i<20;i++)
- {
- if(nCusor[i]==1)
- TransparentBitmap(pDC->GetSafeHdc(),bmpCusor,i*32,278,0,0,RGB(255,255,255));
- }
- break;
- default:
- break;
- }
- //积分的显示
- CString str;
- pDC->SetBkColor(RGB(0,128,0));
- str.Format("%d",nZongZiJin[0]);
- pDC->TextOut(108,134,str);
- str.Format("%d",nZongZiJin[1]);
- pDC->TextOut(108,198,str);
- str.Format("%d",nZongZiJin[2]);
- pDC->TextOut(108,262,str);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyView diagnostics
- #ifdef _DEBUG
- void CMyView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CMyView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CMyDoc* CMyView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
- return (CMyDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMyView message handlers
- void CMyView::TransparentBitmap(HDC hdc, HBITMAP hBitmap,short xStart, short yStart,
- short xadd,short yadd, COLORREF cTransparentColor)
- {
- BITMAP m_bm;
- COLORREF cColor;
- // 创建临时DC
- HDC hMem, hBack, hObject, hTemp, hSave;
- hBack = CreateCompatibleDC(hdc);
- hObject = CreateCompatibleDC(hdc);
- hMem = CreateCompatibleDC(hdc);
- hSave = CreateCompatibleDC(hdc);
- hTemp = CreateCompatibleDC(hdc);
- // 选入位图
- SelectObject(hTemp, hBitmap);
- GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&m_bm);
- //显示位图宽高
- POINT ptSize;
- // 取得位图的宽度
- ptSize.x = m_bm.bmWidth;
- // 取得位图的该度
- ptSize.y = m_bm.bmHeight;
- // 转换为逻辑点值
- DPtoLP(hTemp, &ptSize, 1);
- // 创建临时位图
- HBITMAP bmBack, bmObject, bmMem, bmSave;
- // 单色位图
- bmBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
- bmObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
- // 与设备兼容位图
- bmMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
- bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
- // 将创建的临时位图选入临时DC中
- HBITMAP OldbmBack, OldbmObject, OldbmMem, OldbmSave;
- OldbmBack = (HBITMAP)SelectObject(hBack, bmBack);
- OldbmObject = (HBITMAP)SelectObject(hObject, bmObject);
- OldbmMem = (HBITMAP)SelectObject(hMem, bmMem);
- OldbmSave = (HBITMAP)SelectObject(hSave, bmSave);
- // 设置映射模式
- SetMapMode(hTemp, GetMapMode(hdc));
- // 先保留原始位图
- BitBlt(hSave, 0, 0, ptSize.x, ptSize.y, hTemp, 0, 0, SRCCOPY);
- // 将背景颜色设置为需透明的颜色
- cColor = SetBkColor(hTemp, cTransparentColor);
- // 创建目标屏蔽码
- BitBlt(hObject, 0, 0, ptSize.x, ptSize.y, hTemp, 0, 0, SRCCOPY);
- // 恢复源DC的原始背景色
- SetBkColor(hTemp, cColor);
- // 创建反转的目标屏蔽码
- BitBlt(hBack, 0, 0, ptSize.x, ptSize.y, hObject, 0, 0, NOTSRCCOPY);
- // 拷贝主DC的背景到目标DC
- BitBlt(hMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart, SRCCOPY);
- // 屏蔽位图的显示区
- BitBlt(hMem, 0, 0, ptSize.x, ptSize.y, hObject, 0, 0, SRCAND);
- // 屏蔽位图中的透明色
- BitBlt(hTemp, 0, 0, ptSize.x, ptSize.y, hBack, 0, 0, SRCAND);
- // 将位图与目标DC的背景左异或操作
- BitBlt(hMem, 0, 0, ptSize.x, ptSize.y, hTemp, 0, 0, SRCPAINT);
- // 拷贝目标到屏幕上
- StretchBlt(hdc, xStart, yStart, ptSize.x+xadd, ptSize.y+yadd, hMem, 0, 0, ptSize.x, ptSize.y,SRCCOPY);
- // 恢复原始位图
- BitBlt(hTemp, 0, 0, ptSize.x, ptSize.y, hSave, 0, 0, SRCCOPY);
- // 删除临时内存位图
- DeleteObject(SelectObject(hBack, OldbmBack));
- DeleteObject(SelectObject(hObject, OldbmObject));
- DeleteObject(SelectObject(hMem, OldbmMem));
- DeleteObject(SelectObject(hSave, OldbmSave));
- // 删除临时内存DC
- DeleteDC(hMem);
- DeleteDC(hBack);
- DeleteDC(hObject);
- DeleteDC(hSave);
- DeleteDC(hTemp);
- }
- void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- int i=point.x/32;
- switch(nIsWho)
- {
- case 0:
- if(point.y<150||point.y>182)
- return;
- if(nCusor[i]==0)
- {
- if(C1[i].z!=0)
- nCusor[i]=1;
- }
- else
- {
- if(C1[i].z!=0)
- nCusor[i]=0;
- }
- InvalidateRect(CRect(i*32,150,i*32+32,182));
- break;
- case 1:
- if(point.y<214||point.y>246)
- return;
- if(nCusor[i]==0)
- {
- if(C2[i].z!=0)
- nCusor[i]=1;
- }
- else
- {
- if(C2[i].z!=0)
- nCusor[i]=0;
- }
- InvalidateRect(CRect(i*32,214,i*32+32,246));
- break;
- case 2:
- if(point.y<278||point.y>310)
- return;
- if(nCusor[i]==1)
- {
- if(P[i].z!=0)
- nCusor[i]=0;
- }
- else
- {
- if(P[i].z!=0)
- nCusor[i]=1;
- }
- InvalidateRect(CRect(i*32,278,i*32+32,310));
- break;
- }
- CView::OnLButtonDown(nFlags, point);
- }
- void CMyView::OnRButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- int i=0;
- int cusorNum=0;
- for(i=0;i<20;i++)
- {
- if(nCusor[i]==1)
- cusorNum++;
- }
- switch(nIsWho)
- {
- case 0:
- if(cusorNum==0)
- return;
- for(i=0;i<20;i++)
- {
- F[i].z=0;
- if(nCusor[i]==1)
- F[i].z=C1[i].z;
- }
- PaiXu(4);
- if(ChuPaiRule()==FALSE)
- {
- MessageBox("不符合出牌规则!");
- return;
- }
- //////////////////////////////////////////////
- for(i=0;i<20;i++)
- {
- L[i].z=0;
- }
- for(i=0;i<20;i++)
- {
- if(nCusor[i]==1)
- {
- L[i].z=C1[i].z;
- C1[i].z=0;
- }
- }
- for(i=0;i<20;i++)
- {
- nCusor[i]=0;
- }
- //////////////////////////////////////////////
- PaiXu(0);
- PaiXu(3);
- InvalidateRect(CRect(0,150,640,182));
- InvalidateRect(CRect(0,342,640,374));
- nIsWho=++nIsWho%3;
- nLastFormWho=2;
- break;
- case 1:
- if(cusorNum==0)
- return;
- for(i=0;i<20;i++)
- {
- F[i].z=0;
- if(nCusor[i]==1)
- F[i].z=C2[i].z;
- }
- PaiXu(4);
- if(ChuPaiRule()==FALSE)
- {
- MessageBox("不符合出牌规则!");
- return;
- }
- //////////////////////////////////////////////
- for(i=0;i<20;i++)
- {
- L[i].z=0;
- }
- for(i=0;i<20;i++)
- {
- if(nCusor[i]==1)
- {
- L[i].z=C2[i].z;
- C2[i].z=0;
- }
- }
- for(i=0;i<20;i++)
- {
- nCusor[i]=0;
- }
- //////////////////////////////////////////////
- PaiXu(1);
- PaiXu(3);
- InvalidateRect(CRect(0,214,640,246));
- InvalidateRect(CRect(0,342,640,374));
- nIsWho=++nIsWho%3;
- nLastFormWho=2;
- break;
- case 2:
- if(cusorNum==0)
- return;
- for(i=0;i<20;i++)
- {
- F[i].z=0;
- if(nCusor[i]==1)
- F[i].z=P[i].z;
- }
- PaiXu(4);
- if(ChuPaiRule()==FALSE)
- {
- MessageBox("不符合出牌规则!");
- return;
- }
- //////////////////////////////////////////////
- for(i=0;i<20;i++)
- {
- L[i].z=0;
- }
- for(i=0;i<20;i++)
- {
- if(nCusor[i]==1)
- {
- L[i].z=P[i].z;
- P[i].z=0;
- }
- }
- for(i=0;i<20;i++)
- {
- nCusor[i]=0;
- }
- //////////////////////////////////////////////
- PaiXu(2);
- PaiXu(3);
- InvalidateRect(CRect(0,278,640,310));
- InvalidateRect(CRect(0,342,640,374));
- nIsWho=++nIsWho%3;
- nLastFormWho=2;
- break;
- }
- InvalidateRect(CRect(0,0,72,16));
- //关于胜利的判断
- int jiShu=0;
- for(i=0;i<20;i++)
- {
- if(C1[i].z!=0)
- jiShu++;
- else
- break;
- }
- if(jiShu==0)
- {
- MessageBox("电脑1胜!");
- MessageBox("进入下轮");
- if(nIsDiZhu==0)
- {
- nZongZiJin[0]+=200;
- nZongZiJin[1]-=100;
- nZongZiJin[2]-=100;
- }
- else if(nIsDiZhu==1)
- {
- nZongZiJin[0]+=100;
- nZongZiJin[1]-=200;
- nZongZiJin[2]+=100;
- }
- else if(nIsDiZhu==2)
- {
- nZongZiJin[0]+=100;
- nZongZiJin[1]+=100;
- nZongZiJin[2]-=200;
- }
- nIsDiZhu=0;
- nIsWho=0;
- AllQingKong();
- OnBanStart();
- }
- else
- {
- jiShu=0;
- for(i=0;i<20;i++)
- {
- if(C2[i].z!=0)
- jiShu++;
- else
- break;
- }
- if(jiShu==0)
- {
- MessageBox("电脑2胜!");
- MessageBox("进入下轮");
- if(nIsDiZhu==0)
- {
- nZongZiJin[0]-=200;
- nZongZiJin[1]+=100;
- nZongZiJin[2]+=100;
- }
- else if(nIsDiZhu==1)
- {
- nZongZiJin[0]-=100;
- nZongZiJin[1]+=200;
- nZongZiJin[2]-=100;
- }
- else if(nIsDiZhu==2)
- {
- nZongZiJin[0]+=100;
- nZongZiJin[1]+=100;
- nZongZiJin[2]-=200;
- }
- nIsDiZhu=1;
- nIsWho=1;
- AllQingKong();
- OnBanStart();
- }
- else
- {
- jiShu=0;
- for(i=0;i<20;i++)
- {
- if(P[i].z!=0)
- jiShu++;
- else
- break;
- }
- if(jiShu==0)
- {
- MessageBox("玩家胜!");
- MessageBox("进入下轮");
- if(nIsDiZhu==0)
- {
- nZongZiJin[0]-=200;
- nZongZiJin[1]+=100;
- nZongZiJin[2]+=100;
- }
- else if(nIsDiZhu==1)
- {
- nZongZiJin[0]+=100;
- nZongZiJin[1]-=200;
- nZongZiJin[2]+=100;
- }
- else if(nIsDiZhu==2)
- {
- nZongZiJin[0]-=100;
- nZongZiJin[1]-=100;
- nZongZiJin[2]+=200;
- }
- nIsDiZhu=2;
- nIsWho=2;
- AllQingKong();
- OnBanStart();
- }
- }
- }
- CView::OnRButtonDown(nFlags, point);
- }
- void CMyView::PaiXu(int nTurn)
- {
- int i=0;
- int nTemp[20];
- for(i=0;i<20;i++)
- {
- nTemp[i]=0;
- }
- int j=0;
- int z=0;
- int zz=0;
- int zzz=0;
- switch(nTurn)
- {
- case 0:
- for(z=3;z<=13;z++)
- {
- zz=z;
- for(zzz=0;zzz<4;zzz++)
- {
- for(i=0;i<20;i++)
- {
- if(C1[i].z==zz)
- {
- nTemp[j]=zz;
- j++;
- }
- }
- zz+=13;
- }
- }
- for(z=1;z<=2;z++)
- {
- zz=z;
- for(zzz=0;zzz<4;zzz++)
- {
- for(i=0;i<20;i++)
- {
- if(C1[i].z==zz)
- {
- nTemp[j]=zz;
- j++;
- }
- }
- zz+=13;
- }
- }
- for(i=0;i<20;i++)
- {
- if(C1[i].z==53)
- {
- nTemp[j]=53;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- if(C1[i].z==54)
- {
- nTemp[j]=54;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- if(C1[i].z==0)
- {
- nTemp[j]=0;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- C1[i].z=nTemp[i];
- }
- break;
- case 1:
- for(z=3;z<=13;z++)
- {
- zz=z;
- for(zzz=0;zzz<4;zzz++)
- {
- for(i=0;i<20;i++)
- {
- if(C2[i].z==zz)
- {
- nTemp[j]=zz;
- j++;
- }
- }
- zz+=13;
- }
- }
- for(z=1;z<=2;z++)
- {
- zz=z;
- for(zzz=0;zzz<4;zzz++)
- {
- for(i=0;i<20;i++)
- {
- if(C2[i].z==zz)
- {
- nTemp[j]=zz;
- j++;
- }
- }
- zz+=13;
- }
- }
- for(i=0;i<20;i++)
- {
- if(C2[i].z==53)
- {
- nTemp[j]=53;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- if(C2[i].z==54)
- {
- nTemp[j]=54;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- if(C2[i].z==0)
- {
- nTemp[j]=0;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- C2[i].z=nTemp[i];
- }
- break;
- case 2:
- for(z=3;z<=13;z++)
- {
- zz=z;
- for(zzz=0;zzz<4;zzz++)
- {
- for(i=0;i<20;i++)
- {
- if(P[i].z==zz)
- {
- nTemp[j]=zz;
- j++;
- }
- }
- zz+=13;
- }
- }
- for(z=1;z<=2;z++)
- {
- zz=z;
- for(zzz=0;zzz<4;zzz++)
- {
- for(i=0;i<20;i++)
- {
- if(P[i].z==zz)
- {
- nTemp[j]=zz;
- j++;
- }
- }
- zz+=13;
- }
- }
- for(i=0;i<20;i++)
- {
- if(P[i].z==53)
- {
- nTemp[j]=53;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- if(P[i].z==54)
- {
- nTemp[j]=54;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- if(P[i].z==0)
- {
- nTemp[j]=0;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- P[i].z=nTemp[i];
- }
- break;
- case 3:
- for(z=3;z<=13;z++)
- {
- zz=z;
- for(zzz=0;zzz<4;zzz++)
- {
- for(i=0;i<20;i++)
- {
- if(L[i].z==zz)
- {
- nTemp[j]=zz;
- j++;
- }
- }
- zz+=13;
- }
- }
- for(z=1;z<=2;z++)
- {
- zz=z;
- for(zzz=0;zzz<4;zzz++)
- {
- for(i=0;i<20;i++)
- {
- if(L[i].z==zz)
- {
- nTemp[j]=zz;
- j++;
- }
- }
- zz+=13;
- }
- }
- for(i=0;i<20;i++)
- {
- if(L[i].z==53)
- {
- nTemp[j]=53;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- if(L[i].z==54)
- {
- nTemp[j]=54;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- if(L[i].z==0)
- {
- nTemp[j]=0;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- L[i].z=nTemp[i];
- }
- break;
- case 4:
- for(z=3;z<=13;z++)
- {
- zz=z;
- for(zzz=0;zzz<4;zzz++)
- {
- for(i=0;i<20;i++)
- {
- if(F[i].z==zz)
- {
- nTemp[j]=zz;
- j++;
- }
- }
- zz+=13;
- }
- }
- for(z=1;z<=2;z++)
- {
- zz=z;
- for(zzz=0;zzz<4;zzz++)
- {
- for(i=0;i<20;i++)
- {
- if(F[i].z==zz)
- {
- nTemp[j]=zz;
- j++;
- }
- }
- zz+=13;
- }
- }
- for(i=0;i<20;i++)
- {
- if(F[i].z==53)
- {
- nTemp[j]=53;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- if(F[i].z==54)
- {
- nTemp[j]=54;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- if(F[i].z==0)
- {
- nTemp[j]=0;
- j++;
- }
- }
- for(i=0;i<20;i++)
- {
- F[i].z=nTemp[i];
- }
- break;
- default:
- break;
- }
- }
- void CMyView::OnBanStart()
- {
- // TODO: Add your command handler code here
- srand(GetTickCount());
- int i=0;
- int j=0;
- int DiZhuPai[3];
- int temp;
- BOOL isChongFu=FALSE;
- for(i=0;i<3;i++)
- {
- DiZhuPai[i]=0;
- }
- //先定义三张地主牌
- i=0;
- while(i<3)
- {
- temp=rand()%54+1;
- for(j=0;j<3;j++)
- {
- if(DiZhuPai[j]==temp)
- isChongFu=TRUE;
- break;
- }
- if(isChongFu==FALSE)
- {
- DiZhuPai[i]=temp;
- i++;
- }
- isChongFu=FALSE;
- }
- switch(nIsDiZhu)
- {
- case 0:
- C1[19].z=DiZhuPai[2];
- C1[18].z=DiZhuPai[1];
- C1[17].z=DiZhuPai[0];
- break;
- case 1:
- C2[19].z=DiZhuPai[2];
- C2[18].z=DiZhuPai[1];
- C2[17].z=DiZhuPai[0];
- break;
- case 2:
- P[19].z=DiZhuPai[2];
- P[18].z=DiZhuPai[1];
- P[17].z=DiZhuPai[0];
- break;
- default:
- break;
- }
- //下面是定义剩下的牌
- i=1;
- int a=0;
- int b=0;
- int c=0;
- while(i<=54)
- {
- if(i==DiZhuPai[0]||i==DiZhuPai[1]||i==DiZhuPai[2])
- {
- i++;
- }
- else
- {
- j=rand()%3;
- switch(j)
- {
- case 0:
- if(a<17)
- {
- C1[a].z=i;
- a++;
- i++;
- }
- break;
- case 1:
- if(b<17)
- {
- C2[b].z=i;
- b++;
- i++;
- }
- break;
- case 2:
- if(c<17)
- {
- P[c].z=i;
- c++;
- i++;
- }
- break;
- default:
- break;
- }
- }
- }
- PaiXu(0);
- PaiXu(1);
- PaiXu(2);
- Invalidate();
- }
- int CMyView::FoundationCompile(int x)
- {
- switch(x)
- {
- case 54:
- x=17;
- break;
- case 53:
- x=16;
- break;
- case 2:
- case 15:
- case 28:
- case 41:
- x=15;
- break;
- case 1:
- case 14:
- case 27:
- case 40:
- x=14;
- break;
- case 13:
- case 26:
- case 39:
- case 52:
- x=13;
- break;
- default:
- x=x%13;
- break;
- }
- return x;
- }
- BOOL CMyView::ChuPaiRule()
- {
- int i=0;
- int LNum=0;
- int FNum=0;
- for(i=0;i<20;i++)
- {
- if(L[i].z!=0)
- {
- LNum+=1;
- }
- }
- for(i=0;i<20;i++)
- {
- if(F[i].z!=0)
- {
- FNum+=1;
- }
- }
- switch(LNum)
- {
- case 0:
- switch(FNum)
- {
- case 1:
- return TRUE;
- case 2:
- if(F[0].z%13==F[1].z%13)
- return TRUE;
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- return FALSE;
- case 3:
- if(F[0].z%13==F[1].z%13&&F[1].z%13==F[2].z%13)
- return TRUE;
- return FALSE;
- case 4:
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- return TRUE;
- if(MagicF(4)==6)
- return TRUE;
- return FALSE;
- case 5:
- //三带二
- if(MagicF(5)==12)
- return TRUE;
- //五连
- if(MagicF(5)==20)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z)) )
- return TRUE;
- return FALSE;
- case 6:
- //123456
- if(MagicF(6)==30)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+5==FoundationCompile(F[5].z)) )
- return TRUE;
- //112233
- if(MagicF(6)==24)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[4].z)) )
- return TRUE;
- //111222
- if(MagicF(6)==18)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[3].z)) )
- return TRUE;
- return TRUE;
- case 7:
- //1234567
- if(MagicF(7)==42)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+5==FoundationCompile(F[5].z))&&
- (FoundationCompile(F[0].z)+6==FoundationCompile(F[6].z)) )
- return TRUE;
- case 8:
- //12345678
- if(MagicF(8)==56)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+5==FoundationCompile(F[5].z))&&
- (FoundationCompile(F[0].z)+6==FoundationCompile(F[6].z))&&
- (FoundationCompile(F[0].z)+7==FoundationCompile(F[7].z)) )
- return TRUE;
- //11223344
- if(MagicF(8)==48)
- return TRUE;
- case 9:
- //12345678
- if(MagicF(9)==72)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+5==FoundationCompile(F[5].z))&&
- (FoundationCompile(F[0].z)+6==FoundationCompile(F[6].z))&&
- (FoundationCompile(F[0].z)+7==FoundationCompile(F[7].z))&&
- (FoundationCompile(F[0].z)+8==FoundationCompile(F[8].z)) )
- return TRUE;
- //111222333
- if(MagicF(9)==54)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[6].z)) )
- return TRUE;
- case 10:
- //1234567890
- if(MagicF(10)==90)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+5==FoundationCompile(F[5].z))&&
- (FoundationCompile(F[0].z)+6==FoundationCompile(F[6].z))&&
- (FoundationCompile(F[0].z)+7==FoundationCompile(F[7].z))&&
- (FoundationCompile(F[0].z)+8==FoundationCompile(F[8].z))&&
- (FoundationCompile(F[0].z)+9==FoundationCompile(F[9].z)) )
- return TRUE;
- //飞机
- if(MagicF(10)==74)
- {
- int F_3_1=-1;
- int F_3_2=-1;
- int F_2_1=-1;
- int F_2_2=-1;
- int j=0;
- int jiShu=0;
- for(i=0;i<10;i++)
- {
- for(j=0;j<10;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- {
- jiShu++;
- }
- }
- if(jiShu==7)
- {
- if(F_3_1==-1)
- F_3_1=F[i].z;
- else
- F_3_2=F[i].z;
- }
- else
- jiShu=0;
- }
- jiShu=0;
- for(i=0;i<10;i++)
- {
- for(j=0;j<10;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- {
- jiShu++;
- }
- }
- if(jiShu==8)
- {
- if(F_2_1==-1)
- F_2_1=F[i].z;
- else
- F_2_2=F[i].z;
- }
- else
- jiShu=0;
- }
- if((FoundationCompile(F_3_1)+1==FoundationCompile(F_3_2))&&
- (FoundationCompile(F_2_1)+1==FoundationCompile(F_2_2)))
- return TRUE;
- }
- //1122334455
- if(MagicF(10)==80)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[6].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[8].z)) )
- return TRUE;
- return FALSE;
- case 11:
- //12345678901
- if(MagicF(11)==110)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+5==FoundationCompile(F[5].z))&&
- (FoundationCompile(F[0].z)+6==FoundationCompile(F[6].z))&&
- (FoundationCompile(F[0].z)+7==FoundationCompile(F[7].z))&&
- (FoundationCompile(F[0].z)+8==FoundationCompile(F[8].z))&&
- (FoundationCompile(F[0].z)+9==FoundationCompile(F[9].z))&&
- (FoundationCompile(F[0].z)+10==FoundationCompile(F[10].z)) )
- return TRUE;
- case 12:
- //123456789012
- if(MagicF(12)==132)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+5==FoundationCompile(F[5].z))&&
- (FoundationCompile(F[0].z)+6==FoundationCompile(F[6].z))&&
- (FoundationCompile(F[0].z)+7==FoundationCompile(F[7].z))&&
- (FoundationCompile(F[0].z)+8==FoundationCompile(F[8].z))&&
- (FoundationCompile(F[0].z)+9==FoundationCompile(F[9].z))&&
- (FoundationCompile(F[0].z)+10==FoundationCompile(F[10].z))&&
- (FoundationCompile(F[0].z)+11==FoundationCompile(F[11].z)) )
- return TRUE;
- default:
- return FALSE;
- }
- case 1:
- //以一打一
- if(FNum==1)
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- //以枪打一
- if(FNum==4)
- if(NoJokerF(4))
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- return TRUE;
- //以王打一
- if(FNum==2)
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- return FALSE;
- case 2:
- //以二打二
- if(FNum==2)
- if(F[0].z%13==F[1].z%13)
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- //以王打二
- if(FNum==2)
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- //以枪打王
- if(FNum==4)
- if(NoJokerF(4))
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- if(L[0].z!=53&&L[1].z!=54)
- return FALSE;
- return FALSE;
- case 3:
- //王打一切
- if(FNum==2)
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- //以三打三
- if(FNum==3)
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13)
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- //以枪打三
- if(FNum==4)
- if(NoJokerF(4))
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- return TRUE;
- //以王打三
- if(FNum==2)
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- return FALSE;
- case 4:
- //以枪打枪
- if(FNum==4)
- if(L[0].z%13==L[1].z%13&&L[0].z%13==L[2].z%13&&L[0].z%13==L[3].z%13)
- if(NoJokerF(4))
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- //王打一切
- if(FNum==2)
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- //枪打三带一
- if(FNum==4)
- if(MagicL(4)==6)
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- return TRUE;
- //三带一打三带一
- if(FNum==4)
- if(MagicL(4)==6)
- if(MagicF(4)==6)
- if(FoundationCompile(YuanShuF(4))>FoundationCompile(YuanShuL(4)))
- return TRUE;
- return FALSE;
- case 5:
- //王打一切
- if(FNum==2)
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- //三带二打三带二
- if(FNum==5)
- if(MagicL(5)==12)
- if(MagicF(5)==12)
- if(FoundationCompile(YuanShuF(5))>FoundationCompile(YuanShuL(5)))
- return TRUE;
- //顺打顺
- if(FNum==5)
- if(MagicL(5)==20)
- if( (FoundationCompile(L[0].z)+1==FoundationCompile(L[1].z))&&
- (FoundationCompile(L[0].z)+2==FoundationCompile(L[2].z))&&
- (FoundationCompile(L[0].z)+3==FoundationCompile(L[3].z))&&
- (FoundationCompile(L[0].z)+4==FoundationCompile(L[4].z)) )
- if(MagicF(5)==20)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z)) )
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- //枪打一切五
- if(FNum==4)
- if(NoJokerF(4))
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- return TRUE;
- return FALSE;
- case 6:
- //王打一切
- if(FNum==2)
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- //枪打六
- if(FNum==4)
- if(NoJokerF(4))
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- return TRUE;
- //六连打六连
- if(FNum==6)
- if(MagicL(6)==30)
- if( (FoundationCompile(L[0].z)+1==FoundationCompile(L[1].z))&&
- (FoundationCompile(L[0].z)+2==FoundationCompile(L[2].z))&&
- (FoundationCompile(L[0].z)+3==FoundationCompile(L[3].z))&&
- (FoundationCompile(L[0].z)+4==FoundationCompile(L[4].z))&&
- (FoundationCompile(L[0].z)+5==FoundationCompile(L[5].z)) )
- if(MagicF(6)==30)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+5==FoundationCompile(F[5].z)) )
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- //112233 vs 112233
- if(FNum==6)
- if(MagicF(6)==24)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[4].z)) )
- if(MagicL(6)==24)
- if( (FoundationCompile(L[0].z)+1==FoundationCompile(L[2].z))&&
- (FoundationCompile(L[0].z)+2==FoundationCompile(L[4].z)) )
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- //111222 VS 111222
- if(FNum==6)
- if(MagicL(6)==18)
- if( (FoundationCompile(L[0].z)+1==FoundationCompile(L[3].z)) )
- if(MagicF(6)==18)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[3].z)) )
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- case 7:
- //1234567 vs 1234567
- if(FNum==7)
- if(MagicL(7)==42)
- if( (FoundationCompile(L[0].z)+1==FoundationCompile(L[1].z))&&
- (FoundationCompile(L[0].z)+2==FoundationCompile(L[2].z))&&
- (FoundationCompile(L[0].z)+3==FoundationCompile(L[3].z))&&
- (FoundationCompile(L[0].z)+4==FoundationCompile(L[4].z))&&
- (FoundationCompile(L[0].z)+5==FoundationCompile(L[5].z))&&
- (FoundationCompile(L[0].z)+6==FoundationCompile(L[6].z)) )
- if(MagicF(7)==42)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+5==FoundationCompile(F[5].z))&&
- (FoundationCompile(F[0].z)+6==FoundationCompile(F[6].z)) )
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- //王打一切
- if(FNum==2)
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- //枪打所有7
- if(NoJokerF(4))
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- return TRUE;
- return FALSE;
- case 8:
- //王打一切
- if(FNum==2)
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- //枪打所有8
- if(NoJokerF(4))
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- return TRUE;
- //12345678 vs 12345678
- if(FNum==8)
- if(MagicL(8)==56)
- if( (FoundationCompile(L[0].z)+1==FoundationCompile(L[1].z))&&
- (FoundationCompile(L[0].z)+2==FoundationCompile(L[2].z))&&
- (FoundationCompile(L[0].z)+3==FoundationCompile(L[3].z))&&
- (FoundationCompile(L[0].z)+4==FoundationCompile(L[4].z))&&
- (FoundationCompile(L[0].z)+5==FoundationCompile(L[5].z))&&
- (FoundationCompile(L[0].z)+6==FoundationCompile(L[6].z))&&
- (FoundationCompile(L[0].z)+7==FoundationCompile(L[7].z)) )
- if(MagicF(8)==56)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+5==FoundationCompile(F[5].z))&&
- (FoundationCompile(F[0].z)+6==FoundationCompile(F[6].z))&&
- (FoundationCompile(F[0].z)+7==FoundationCompile(F[7].z)) )
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- //11223344 vs 11223344
- if(FNum==8)
- if(MagicL(8)==48)
- if(MagicF(8)==48)
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- case 9:
- //王打一切
- if(FNum==2)
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- //枪打所有9
- if(NoJokerF(4))
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- return TRUE;
- //111222333 vs 111222333
- if(MagicF(9)==54)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[6].z)) )
- return TRUE;
- //123456789 vs 123456789
- if(FNum==9)
- if(MagicL(9)==72)
- if( (FoundationCompile(L[0].z)+1==FoundationCompile(L[1].z))&&
- (FoundationCompile(L[0].z)+2==FoundationCompile(L[2].z))&&
- (FoundationCompile(L[0].z)+3==FoundationCompile(L[3].z))&&
- (FoundationCompile(L[0].z)+4==FoundationCompile(L[4].z))&&
- (FoundationCompile(L[0].z)+5==FoundationCompile(L[5].z))&&
- (FoundationCompile(L[0].z)+6==FoundationCompile(L[6].z))&&
- (FoundationCompile(L[0].z)+7==FoundationCompile(L[7].z))&&
- (FoundationCompile(L[0].z)+8==FoundationCompile(L[8].z)) )
- if(MagicF(9)==72)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+5==FoundationCompile(F[5].z))&&
- (FoundationCompile(F[0].z)+6==FoundationCompile(F[6].z))&&
- (FoundationCompile(F[0].z)+7==FoundationCompile(F[7].z))&&
- (FoundationCompile(F[0].z)+8==FoundationCompile(F[8].z)) )
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- case 10:
- //王打一切
- if(FNum==2)
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- //枪打所有10
- if(NoJokerF(4))
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- return TRUE;
- //1234567890 vs 1234567890
- if(FNum==10)
- if(MagicL(10)==90)
- if( (FoundationCompile(L[0].z)+1==FoundationCompile(L[1].z))&&
- (FoundationCompile(L[0].z)+2==FoundationCompile(L[2].z))&&
- (FoundationCompile(L[0].z)+3==FoundationCompile(L[3].z))&&
- (FoundationCompile(L[0].z)+4==FoundationCompile(L[4].z))&&
- (FoundationCompile(L[0].z)+5==FoundationCompile(L[5].z))&&
- (FoundationCompile(L[0].z)+6==FoundationCompile(L[6].z))&&
- (FoundationCompile(L[0].z)+7==FoundationCompile(L[7].z))&&
- (FoundationCompile(L[0].z)+8==FoundationCompile(L[8].z))&&
- (FoundationCompile(L[0].z)+9==FoundationCompile(L[9].z)) )
- if(MagicF(10)==90)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+5==FoundationCompile(F[5].z))&&
- (FoundationCompile(F[0].z)+6==FoundationCompile(F[6].z))&&
- (FoundationCompile(F[0].z)+7==FoundationCompile(F[7].z))&&
- (FoundationCompile(F[0].z)+8==FoundationCompile(F[8].z))&&
- (FoundationCompile(F[0].z)+9==FoundationCompile(F[9].z)) )
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- //飞机打飞机
- if(FNum==10)
- if(MagicF(10)==74)
- {
- int F_3_1=-1;
- int F_3_2=-1;
- int F_2_1=-1;
- int F_2_2=-1;
- int j=0;
- int jiShu=0;
- for(i=0;i<10;i++)
- {
- for(j=0;j<10;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- {
- jiShu++;
- }
- }
- if(jiShu==7)
- {
- if(F_3_1==-1)
- F_3_1=F[i].z;
- else
- F_3_2=F[i].z;
- }
- else
- jiShu=0;
- }
- jiShu=0;
- for(i=0;i<10;i++)
- {
- for(j=0;j<10;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- {
- jiShu++;
- }
- }
- if(jiShu==8)
- {
- if(F_2_1==-1)
- F_2_1=F[i].z;
- else
- F_2_2=F[i].z;
- }
- else
- jiShu=0;
- }
- if((FoundationCompile(F_3_1)+1==FoundationCompile(F_3_2))&&
- (FoundationCompile(F_2_1)+1==FoundationCompile(F_2_2)))
- {
- if(MagicL(10)==74)
- {
- int L_3_1=-1;
- int L_3_2=-1;
- int L_2_1=-1;
- int L_2_2=-1;
- j=0;
- jiShu=0;
- for(i=0;i<10;i++)
- {
- for(j=0;j<10;j++)
- {
- if(L[i].z%13!=L[j].z%13)
- {
- jiShu++;
- }
- }
- if(jiShu==7)
- {
- if(L_3_1==-1)
- L_3_1=L[i].z;
- else
- L_3_2=L[i].z;
- }
- else
- jiShu=0;
- }
- jiShu=0;
- for(i=0;i<10;i++)
- {
- for(j=0;j<10;j++)
- {
- if(L[i].z%13!=L[j].z%13)
- {
- jiShu++;
- }
- }
- if(jiShu==8)
- {
- if(L_2_1==-1)
- L_2_1=L[i].z;
- else
- L_2_2=L[i].z;
- }
- else
- jiShu=0;
- }
- if((FoundationCompile(L_3_1)+1==FoundationCompile(L_3_2))&&
- (FoundationCompile(L_2_1)+1==FoundationCompile(L_2_2)))
- {
- if(FoundationCompile(F_3_1)>FoundationCompile(L_3_1))
- return TRUE;
- }}}}
- //1122334455 VS 1122334455
- if(FNum==10)
- if(MagicF(10)==80)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[6].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[8].z)) )
- if(MagicL(10)==80)
- if( (FoundationCompile(L[0].z)+1==FoundationCompile(L[2].z))&&
- (FoundationCompile(L[0].z)+2==FoundationCompile(L[4].z))&&
- (FoundationCompile(L[0].z)+3==FoundationCompile(L[6].z))&&
- (FoundationCompile(L[0].z)+4==FoundationCompile(L[8].z)) )
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- return FALSE;
- case 11:
- //王打一切
- if(FNum==2)
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- //枪打所有11
- if(NoJokerF(4))
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- return TRUE;
- //12345678901 vs 12345678901
- if(FNum==11)
- if(MagicF(11)==110)
- if( (FoundationCompile(F[0].z)+1==FoundationCompile(F[1].z))&&
- (FoundationCompile(F[0].z)+2==FoundationCompile(F[2].z))&&
- (FoundationCompile(F[0].z)+3==FoundationCompile(F[3].z))&&
- (FoundationCompile(F[0].z)+4==FoundationCompile(F[4].z))&&
- (FoundationCompile(F[0].z)+5==FoundationCompile(F[5].z))&&
- (FoundationCompile(F[0].z)+6==FoundationCompile(F[6].z))&&
- (FoundationCompile(F[0].z)+7==FoundationCompile(F[7].z))&&
- (FoundationCompile(F[0].z)+8==FoundationCompile(F[8].z))&&
- (FoundationCompile(F[0].z)+9==FoundationCompile(F[9].z))&&
- (FoundationCompile(F[0].z)+10==FoundationCompile(F[10].z)) )
- if(MagicL(11)==110)
- if( (FoundationCompile(L[0].z)+1==FoundationCompile(L[1].z))&&
- (FoundationCompile(L[0].z)+2==FoundationCompile(L[2].z))&&
- (FoundationCompile(L[0].z)+3==FoundationCompile(L[3].z))&&
- (FoundationCompile(L[0].z)+4==FoundationCompile(L[4].z))&&
- (FoundationCompile(L[0].z)+5==FoundationCompile(L[5].z))&&
- (FoundationCompile(L[0].z)+6==FoundationCompile(L[6].z))&&
- (FoundationCompile(L[0].z)+7==FoundationCompile(L[7].z))&&
- (FoundationCompile(L[0].z)+8==FoundationCompile(L[8].z))&&
- (FoundationCompile(L[0].z)+9==FoundationCompile(L[9].z))&&
- (FoundationCompile(L[0].z)+10==FoundationCompile(L[10].z)) )
- if(FoundationCompile(F[0].z)>FoundationCompile(L[0].z))
- return TRUE;
- case 12:
- //王打一切
- if(FNum==2)
- if(F[0].z==53&&F[1].z==54)
- return TRUE;
- //枪打所有12
- if(NoJokerF(4))
- if(F[0].z%13==F[1].z%13&&F[0].z%13==F[2].z%13&&F[0].z%13==F[3].z%13)
- return TRUE;
- default:
- return FALSE;
- }
- }
- void CMyView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- int i=0;
- int j=0;
- int yShua=0;
- switch(nChar)
- {
- case VK_SPACE:
- BuYao();
- break;
- }
- CView::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- int CMyView::MagicF(int num)
- {
- int i=0;
- int j=0;
- int jiShu=0;
- switch(num)
- {
- case 4:
- //判断三带一 6
- for(i=0;i<4;i++)
- {
- if(F[i].z==53||F[i].z==54)
- return 1000;
- for(j=0;j<4;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 5:
- //判断三代二 12
- for(i=0;i<5;i++)
- {
- if(F[i].z==53||F[i].z==54)
- return 1000;
- for(j=0;j<5;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 6:
- //123456 30
- //112233 24
- //111222 18
- for(i=0;i<6;i++)
- {
- if(F[i].z==53||F[i].z==54)
- return 1000;
- for(j=0;j<6;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 7:
- for(i=0;i<7;i++)
- {
- if(F[i].z==53||F[i].z==54)
- return 1000;
- for(j=0;j<7;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 8:
- for(i=0;i<8;i++)
- {
- if(F[i].z==53||F[i].z==54)
- return 1000;
- for(j=0;j<8;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 9:
- for(i=0;i<9;i++)
- {
- if(F[i].z==53||F[i].z==54)
- return 1000;
- for(j=0;j<9;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 10:
- for(i=0;i<10;i++)
- {
- if(F[i].z==53||F[i].z==54)
- return 1000;
- for(j=0;j<10;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 11:
- for(i=0;i<11;i++)
- {
- if(F[i].z==53||F[i].z==54)
- return 1000;
- for(j=0;j<11;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 12:
- for(i=0;i<12;i++)
- {
- if(F[i].z==53||F[i].z==54)
- return 1000;
- for(j=0;j<12;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- default:
- break;
- }
- }
- int CMyView::YuanShuF(int num)
- {
- int i=0;
- int j=0;
- int jiShu=0;
- switch(num)
- {
- case 4:
- //完成三带一
- for(i=0;i<4;i++)
- {
- for(j=0;j<4;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- {
- jiShu++;
- }
- }
- if(jiShu==1)
- return F[i].z;
- else
- jiShu=0;
- }
- MessageBox("这里出错了YuanShuF(4)");
- break;
- case 5:
- for(i=0;i<5;i++)
- {
- for(j=0;j<5;j++)
- {
- if(F[i].z%13!=F[j].z%13)
- {
- jiShu++;
- }
- }
- if(jiShu==2)
- return F[i].z;
- else
- jiShu=0;
- }
- MessageBox("这里出错了YuanShuF(5)");
- break;
- default:
- break;
- }
- }
- int CMyView::MagicL(int num)
- {
- int i=0;
- int j=0;
- int jiShu=0;
- switch(num)
- {
- case 4:
- for(i=0;i<4;i++)
- {
- if(L[i].z==53||L[i].z==54)
- return 1000;
- for(j=0;j<4;j++)
- {
- if(L[i].z%13!=L[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 5:
- for(i=0;i<5;i++)
- {
- if(L[i].z==53||L[i].z==54)
- return 1000;
- for(j=0;j<5;j++)
- {
- if(L[i].z%13!=L[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 6:
- for(i=0;i<6;i++)
- {
- if(L[i].z==53||L[i].z==54)
- return 1000;
- for(j=0;j<6;j++)
- {
- if(L[i].z%13!=L[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 7:
- for(i=0;i<7;i++)
- {
- if(L[i].z==53||L[i].z==54)
- return 1000;
- for(j=0;j<7;j++)
- {
- if(L[i].z%13!=L[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 8:
- for(i=0;i<8;i++)
- {
- if(L[i].z==53||L[i].z==54)
- return 1000;
- for(j=0;j<8;j++)
- {
- if(L[i].z%13!=L[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 9:
- for(i=0;i<9;i++)
- {
- if(L[i].z==53||L[i].z==54)
- return 1000;
- for(j=0;j<9;j++)
- {
- if(L[i].z%13!=L[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 10:
- for(i=0;i<10;i++)
- {
- if(L[i].z==53||L[i].z==54)
- return 1000;
- for(j=0;j<10;j++)
- {
- if(L[i].z%13!=L[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 11:
- for(i=0;i<11;i++)
- {
- if(L[i].z==53||L[i].z==54)
- return 1000;
- for(j=0;j<11;j++)
- {
- if(L[i].z%13!=L[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- case 12:
- for(i=0;i<12;i++)
- {
- if(L[i].z==53||L[i].z==54)
- return 1000;
- for(j=0;j<12;j++)
- {
- if(L[i].z%13!=L[j].z%13)
- jiShu++;
- }
- }
- return jiShu;
- default:
- break;
- }
- }
- int CMyView::YuanShuL(int num)
- {
- int i=0;
- int j=0;
- int jiShu=0;
- switch(num)
- {
- case 4:
- for(i=0;i<4;i++)
- {
- for(j=0;j<4;j++)
- {
- if(L[i].z%13!=L[j].z%13)
- {
- jiShu++;
- }
- }
- if(jiShu==1)
- return L[i].z;
- else
- jiShu=0;
- }
- MessageBox("这里出错了YuanShuL(4)");
- break;
- case 5:
- for(i=0;i<5;i++)
- {
- for(j=0;j<5;j++)
- {
- if(L[i].z%13!=L[j].z%13)
- {
- jiShu++;
- }
- }
- if(jiShu==2)
- return L[i].z;
- else
- jiShu=0;
- }
- MessageBox("YuanShuL(5)");
- break;
- default:
- break;
- }
- }
- BOOL CMyView::NoJokerF(int num)
- {
- int i=0;
- switch(num)
- {
- case 4:
- for(i=0;i<4;i++)
- {
- if(F[i].z==54||F[i].z==53)
- return FALSE;
- }
- return TRUE;
- case 5:
- for(i=0;i<5;i++)
- {
- if(F[i].z==54||F[i].z==53)
- return FALSE;
- }
- default:
- break;
- }
- }
- void CMyView::BuYao()
- {
- int i=0;
- int j=0;
- int yShua=0;
- switch(nIsWho)
- {
- case 0:
- yShua=150;
- break;
- case 1:
- yShua=214;
- break;
- case 2:
- yShua=278;
- break;
- }
- for(i=0;i<20;i++)
- {
- nCusor[i]=0;
- InvalidateRect(CRect(i*32,yShua,i*32+32,yShua+32));
- }
- nIsWho=++nIsWho%3;
- InvalidateRect(CRect(0,0,72,16));
- //自己的牌要给自己让路
- nLastFormWho--;
- if(nLastFormWho<=0)
- {
- for(i=0;i<20;i++)
- {
- if(L[i].z!=0)
- {
- L[i].z=0;
- InvalidateRect(CRect(0,342,640,374));
- }
- }
- }
- }
- void CMyView::AllQingKong()
- {
- int i=0;
- for(i=0;i<20;i++)
- {
- C1[i].z=0;
- C2[i].z=0;
- P[i].z=0;
- L[i].z=0;
- F[i].z=0;
- }
- }