⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 专周view.cpp

📁 打砖块
💻 CPP
字号:
// 专周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_COMMAND(ID_MENUITEkaishi, OnMENUITEkaishi)
	ON_COMMAND(ID_MENUITEMcxkaishi, OnMENUITEMcxkaishi)
	ON_WM_KEYDOWN()
	ON_WM_TIMER()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction

CMyView::CMyView()
{
	// TODO: add construction code here

}

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);

	CRect rect;          //背景颜色
	GetClientRect(&rect);
	CBrush BkgBrush(RGB(100,100,100));
	pDC->FillRect(rect,&BkgBrush);


	pDC->SelectStockObject(BLACK_BRUSH);  //底版的颜色
	pDC->Rectangle(pDoc->m_ndiban);
    CBrush qiuyanse,*qiuhuashua;
	qiuyanse.CreateSolidBrush(RGB(0,100,0));  //球的颜色
	qiuhuashua=pDC->SelectObject(&qiuyanse);
    pDC->Ellipse(pDoc->m_nqiu);
	pDC->SelectObject(qiuyanse);


    int xx;
	CRect rectClienttt;                         //根据当前窗口大小确定位置
	GetClientRect(&rectClienttt);
	
	xx=(rectClienttt.right-rectClienttt.left)/10;
	
	
	CBrush brushNewRed,brushNewBlue,*pbrushOld;  //画刷
    brushNewRed.CreateSolidBrush(RGB(255,0,0));
	brushNewBlue.CreateSolidBrush(RGB(0,0,255));
    pbrushOld=pDC->SelectObject(&brushNewRed);
	
	
	int i,j;
	for(i=0;i<7;i++)
	{
		for (j=0;j<10;j++)
		{
			CRect m_ngezi[MAX_BUBBLE][MAX_BUBBLE];
			int left,top,right,bottom;
			left  = j*xx;
			top   =i*20+50;
			right = (j+1)*xx;
			bottom=(i+1)*20+50;
			
        if(i==0 || i==2 || i==4 || i==6)
		{pDC->SelectObject(&brushNewRed);}
		else
		{pDC->SelectObject(&brushNewBlue);}
          pDoc->m_ngezi[i][j]=CRect(left,top,right,bottom);
         if(pDoc->m_nxx[i*10+j]==0)
		 {pDC->Rectangle(pDoc->m_ngezi[i][j]);}
		 else break;
		} 
		

	}
   
		pDC->SelectObject(pbrushOld);
	



	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CMyView printing

BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// 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::OnMENUITEkaishi() 
{
	// TODO: Add your command handler code here
	CMyDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	if(pDoc->m_ncxkaishi==1)
	{
		Invalidate();
		pDoc->m_ncxkaishi=0;
	}


    CRect rectClient;                                 //根据当前窗口大小确定底版位置
	GetClientRect(&rectClient);
	pDoc->m_nx1=(rectClient.right-rectClient.left)/2-50;
	pDoc->m_ny1=rectClient.bottom-80;
	pDoc->m_nx2=(rectClient.right-rectClient.left)/2+50;
	pDoc->m_ny2=rectClient.bottom-100;
	pDoc->m_ndiban=CRect(pDoc->m_nx1,pDoc->m_ny1,pDoc->m_nx2,pDoc->m_ny2);
	InvalidateRect(pDoc->m_ndiban,FALSE);
	int x1,x2,y1,y2;                                  //根据当前窗口大小确定球位置
	x1=(rectClient.right-rectClient.left)/2-5;
	y1=rectClient.bottom-110;
	x2=(rectClient.right-rectClient.left)/2+5;
	y2=rectClient.bottom-100;
	pDoc->m_nqiu=CRect(x1,y1,x2,y2);
	InvalidateRect(pDoc->m_nqiu,FALSE);
    
    
	

}

void CMyView::OnMENUITEMcxkaishi() 
{
	// TODO: Add your command handler code here
	CMyDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	pDoc->m_ncxkaishi=1;
    
}

void CMyView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	
	CMyDoc* pDoc = GetDocument();         //移动底板
	ASSERT_VALID(pDoc);
	CRect rectClient;
	GetClientRect(&rectClient);
	InvalidateRect(pDoc->m_ndiban,TRUE);
	//InvalidateRect(pDoc->m_nqiu,TRUE);
	switch(nChar)
	{
	case VK_LEFT:
		if(pDoc->m_ndiban.left>rectClient.left)
		{
			pDoc->m_ndiban.left     -=20;
			pDoc->m_ndiban.right  -=20;
		//	pDoc->m_nqiu.left     -=10;
		//	pDoc->m_nqiu.right  -=10;
		}
		break;
	case VK_RIGHT:
		if(pDoc->m_ndiban.right<rectClient.right)
		{
			pDoc->m_ndiban.left   +=20;
			pDoc->m_ndiban.right  +=20;
		//	pDoc->m_nqiu.left   +=10;
		//	pDoc->m_nqiu.right  +=10;
		}
		break;
	case VK_UP:
         pDoc->m_nkaishijieshu=1;    //游戏开始
         SetTimer(1,100,NULL);
		 break;
	case VK_DOWN:
         pDoc->m_nkaishijieshu=0;    //游戏结束
         KillTimer(1);
		 break;
	

	}
	InvalidateRect(pDoc->m_ndiban,FALSE);
	//InvalidateRect(pDoc->m_nqiu,FALSE);


	CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CMyView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	

	CMyDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

    InvalidateRect(pDoc->m_nqiu,TRUE);
	CRect rectClientt;
	GetClientRect(&rectClientt);
	
	if(pDoc->m_nqiu.right>=rectClientt.right || pDoc->m_nqiu.left<=rectClientt.left)
	{pDoc->m_nx=-pDoc->m_nx;}
	else ;

	if(pDoc->m_nqiu.top<=rectClientt.top || pDoc->m_nqiu.left>pDoc->m_ndiban.left && pDoc->m_nqiu.right<pDoc->m_ndiban.right && pDoc->m_nqiu.bottom>pDoc->m_ndiban.top-20)
	{pDoc->m_ny=-pDoc->m_ny;}
    
    pDoc->m_nqiu.left-=pDoc->m_nx;
    pDoc->m_nqiu.right-=pDoc->m_nx;
	pDoc->m_nqiu.top-=pDoc->m_ny;
	pDoc->m_nqiu.bottom-=pDoc->m_ny;

	InvalidateRect(pDoc->m_nqiu,FALSE);


	int i,j;
	for(i=0;i<7;i++)
	{
	   for (j=0;j<10;j++)

	    
	   {if(pDoc->m_nxx[i*10+j]==0)
	         
	   
	   { if(pDoc->m_nqiu.left+5>pDoc->m_ngezi[i][j].left && pDoc->m_nqiu.right<pDoc->m_ngezi[i][j].right && pDoc->m_nqiu.top<pDoc->m_ngezi[i][j].bottom)
	   
	   
		{
			pDoc->m_ny=-pDoc->m_ny;
		    pDoc->m_nxx[i*10+j]=1;
	     	InvalidateRect(pDoc->m_ngezi[i][j],TRUE);
		}
		}
	   }

	}
	
	

	CView::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -