📄 fanview.cpp
字号:
// fanView.cpp : implementation of the CFanView class
//
#include "stdafx.h"
#include "fan.h"
#include "fanDoc.h"
#include "fanView.h"
#include "MainFrm.h"
#include "math.h"
#include "MemDC.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define IDC_TIMER 100
static const double PI = 3.141592654;
/////////////////////////////////////////////////////////////////////////////
// CFanView
IMPLEMENT_DYNCREATE(CFanView, CView)
BEGIN_MESSAGE_MAP(CFanView, CView)
//{{AFX_MSG_MAP(CFanView)
ON_WM_CREATE()
ON_WM_TIMER()
ON_WM_CHAR()
ON_COMMAND(ID_1, On1)
ON_UPDATE_COMMAND_UI(ID_1, OnUpdate1)
ON_COMMAND(ID_2, On2)
ON_UPDATE_COMMAND_UI(ID_2, OnUpdate2)
ON_COMMAND(ID_3, On3)
ON_UPDATE_COMMAND_UI(ID_3, OnUpdate3)
ON_COMMAND(ID_STAR, OnStar)
ON_WM_KEYDOWN()
ON_WM_PAINT()
ON_WM_KILLFOCUS()
ON_WM_SETFOCUS()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFanView construction/destruction
CFanView::CFanView()
{
// TODO: add construction code here
}
CFanView::~CFanView()
{
}
BOOL CFanView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CFanView drawing
/*void CFanView::OnDraw(CDC* pDC)
{
CFanDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CDC pcd1,pcd2;
CBitmap bitmap,bitmap2;
BITMAP bm,bm2;
int wide,hight;
pDC->FillRect(CRect(0,0,50,400),NULL);
bitmap.LoadBitmap(IDB_BITMAP1);
bitmap.GetObject(sizeof(bm),&bm);
bitmap2.LoadBitmap(IDB_BITMAP2);
bitmap2.GetObject(sizeof(bm2),&bm2);
wide=bm.bmWidth;
hight=bm.bmHeight;
pcd1.CreateCompatibleDC(NULL);
pcd1.SelectObject(&bitmap);
pcd2.CreateCompatibleDC(NULL);
pcd2.SelectObject(&bitmap2);
// wait.Restore();
//pDC->Draw3dRect(2,2,200+2,400+2,NULL,NULL);
if(flag)
{
for(int a=0;a<4;a++)
{
cor[aa[a].x][aa[a].y]=1;
}
}
for(int x=0;x<20;x++)
{
for(int j=0;j<10;j++)
{
if(j==0)
{
pDC->BitBlt(100+0,x*20,wide,hight,&pcd2,0,0,SRCCOPY);
}
if(j==9)
{
pDC->BitBlt(100+220,x*20,wide,hight,&pcd2,0,0,SRCCOPY);
}
if(x==19)
{
pDC->BitBlt(100+j*20,x*20+20,wide,hight,&pcd2,0,0,SRCCOPY);
}
if((cor[x][j]==1)||(cor[x][j]==2))
{
// m_pbmpContents->GetBitmapBits(
pDC->BitBlt(100+20+j*20,x*20,wide,hight,&pcd1,0,0,SRCCOPY);
}
}
if(x==19)
{
pDC->BitBlt(100+200,400,wide,hight,&pcd2,0,0,SRCCOPY);
//wait.Restore();
pDC->BitBlt(100+220,400,wide,hight,&pcd2,0,0,SRCCOPY);
//wait.Restore();
}
}
//bitmap[k].DeleteObject();
}*/
/////////////////////////////////////////////////////////////////////////////
// CFanView printing
BOOL CFanView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CFanView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CFanView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CFanView diagnostics
#ifdef _DEBUG
void CFanView::AssertValid() const
{
CView::AssertValid();
}
void CFanView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CFanDoc* CFanView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFanDoc)));
return (CFanDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFanView message handlers
int CFanView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
flag2=0;
/* m_nMaxX=GetSystemMetrics(SM_CXSCREEN);
m_nMaxY=GetSystemMetrics(SM_CYSCREEN);
HDC hdc=::GetDC(m_hWnd);
m_memdc=::CreateCompatibleDC(hdc);
m_hBit=CreateCompatibleBitmap(hdc,m_nMaxX,m_nMaxY);
SelectObject(m_memdc,m_hBit);
m_hBrush=(HBRUSH)GetStockObject(WHITE_BRUSH);
SelectObject(m_memdc,m_hBrush);
PatBlt(m_memdc,0,0,m_nMaxX,m_nMaxY,PATCOPY);*/
k=0;
time=500;
K=0;
Y=0;
for(int i=0;i<20;i++)
{
for(int j=0;j<11;j++)
{
cor[i][j]=0;
}
}
count=0;
R=0;
L=0;
H=0;
index=0;
flag=0;
Star();
SetTimer(IDC_TIMER,time,NULL);
return 0;
}
void CFanView::OnTimer(UINT nIDEvent)
{
Y=1;
if(K)
{
if(Isbottom())
{
flag=1;
clean(0);
R=R+2;
for(int a=0;a<4;a++)
{
aa[a].x++;
}
// clean(1);
// Invalidate();
// OnPaint();
myDraw();
}
else if(K)
{
Isover();
Star();
flag=1;
}
}
Y=0;
CView::OnTimer(nIDEvent);
}
void CFanView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CView::OnChar(nChar, nRepCnt, nFlags);
}
void CFanView::clean(int b)
{
for(int a=0;a<4;a++)
{
cor[aa[a].x][aa[a].y]=0;
dd[a].x=aa[a].x;
dd[a].y=aa[a].y;
}
}
int CFanView::round(int as)
{
int tempx=0,tempy=0,a,d=0,h=0;
int temp2=0,temp1=0;
for(a=0;a<4;a++)
{
bb[a].x=aa[a].x;
bb[a].y=aa[a].y;
}
if(index==1)
{
temp1=aa[2].x;
temp2=aa[2].y;
h=2;
}
else
{
temp1=aa[1].x;
temp2=aa[1].y;
h=1;
}
for(a=0;a<4;a++)
{
if(a!=h)
{
tempx=(aa[a].x-temp1);
tempy=(aa[a].y-temp2);
aa[a].x=tempy+temp1;
aa[a].y=-tempx+temp2;
if((cor[aa[a].x][aa[a].y]==2)||(aa[a].y>9)||(aa[a].y<0)||(aa[a].x>19)||(aa[a].x<0))
{
for(int d=0;d<4;d++)
{
aa[d].x=bb[d].x;
aa[d].y=bb[d].y;
}
return 0;
}
}
}
return 1;
//aa[a].x=tempx*temp1+tempy*temp2+aa[1].x;
// aa[a].y=tempy*temp1-tempx*temp2+aa[1].y;
}
int CFanView::Isout(int w)
{
if(w==2)
{
for(int a=0;a<4;a++)
{
if((aa[a].y>=9)||(cor[aa[a].x][aa[a].y+1]==2))
{
return 1;
}
}
}
if(w==1)
{
for(int a=0;a<4;a++)
{
if((aa[a].y<=0)||(cor[aa[a].x][aa[a].y-1]==2))
{
return 2;
}
}
}
return 3;
}
int CFanView::Isbottom()
{
for(int a=0;a<4;a++)
{
if(aa[a].x==19)
{
for(int c=0;c<4;c++)
{
cor[aa[c].x][aa[c].y]=2;
color[aa[c].x][aa[c].y]=tempcolor;
flag2=1;
}
k=0;
return 0;
}
if(cor[aa[a].x+1][aa[a].y]==2)
{
for(int c=0;c<4;c++)
{
cor[aa[c].x][aa[c].y]=2;
color[aa[c].x][aa[c].y]=tempcolor;
flag2=1;
}
k=0;
return 0;
}
}
return 1;
}
int CFanView::dop()
{
for(int u=0;u<20;u++)
{
for(int a=0;a<4;a++)
{
if(cor[aa[a].x+1][aa[a].y]==2)
{
for(int c=0;c<4;c++)
{
cor[aa[c].x][aa[c].y]=2;
color[aa[c].x][aa[c].y]=tempcolor;
flag2=1;
}
// flag=1;
return 0;
}
}
for(a=0;a<4;a++)
{
if(aa[a].x==19)
{
for(int c=0;c<4;c++)
{
cor[aa[c].x][aa[c].y]=2;
color[aa[c].x][aa[c].y]=tempcolor;
flag2=1;
}
// flag=1;
return 0;
}
}
for(int o=0;o<4;o++)
{
aa[o].x=aa[o].x+1;
}
}
return 1;
}
void CFanView::Isover()
{
int flagover=0,n=0;
for(int a=19;a>=0;a--)
{
flagover=0;
for(int b=0;b<10;b++)
{
if(cor[a][b]==2)
{
flagover++;
}
}
if(flagover==10)
{
count=count+100;
for(b=0;b<10;b++)
{
cor[a][b]=0;
color[a][b]=RGB(255,255,255);
}
for(int t=a;t>0;t--)
{
for(b=0;b<10;b++)
{
if(cor[t-1][b]==2)
{
cor[t][b]=2;
color[t][b]=color[t-1][b];
flag2=1;
cor[t-1][b]=0;
color[t-1][b]=RGB(255,255,255);
}
}
}
a=a+1;
}
}
for(a=0;a<9;a++)
{
if(cor[0][a]==2)
{
KillTimer(IDC_TIMER);
MessageBox("游戏结束");
// clean(1);
count=0;
for(int i=0;i<20;i++)
{
for(int j=0;j<10;j++)
{
cor[i][j]=0;
flag2=1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -