(遊戲編程-03)MFC版俄羅斯方塊(奇蹟冬瓜)

由於代碼插入錯位,對不久前發的博文重新發布

(一)運行圖

<1開頭動畫

<2遊戲截圖

(二)前言

       大二下學期了,小編學的是軟件工程專業.學了大量書本後發現根本沒有好的實踐,沒弄出來什麼立體的可感的遊戲,於是乎在學校實驗室花了3到4天的從早到晚的冥思苦想做出來了這個俄羅斯方塊的小遊戲.其中查了大量的資料.當立體呈現的時候,小編髮現了幾個BUG,一是加速下落的鍵盤不靈(⊙o⊙)…!囧.二是控制左右下的鍵有時差額(⊙o⊙)…!三是當按動鍵盤的時候開始和暫停的鍵有閃爍(⊙o⊙)…!四是暫停後還可以左右移動啊!五是還有一些代碼算法有點缺陷!在發放給大量的好友測試後返回的信息還有就是程序開始的過場動畫不能移動框架,一移動就要卡,等動畫結束就好了(⊙o⊙)…!總之經過大量的測試基本功能就有了,但是做完才發現沒有顯示下一塊方塊摸樣的窗口(⊙o⊙)…先截圖再上代碼,再詳細解釋一些函數的用法.

(三)主要部分代碼

// Test_ProgramDlg.cpp : 實現文件
//

#include "stdafx.h"
#include "Test_Program.h"
#include "Test_ProgramDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// 用於應用程序“關於”菜單項的 CAboutDlg 對話框

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// 對話框數據
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 實現
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CTest_ProgramDlg 對話框




CTest_ProgramDlg::CTest_ProgramDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTest_ProgramDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTest_ProgramDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_SHOCKWAVEFLASH1, m_flash);
}

BEGIN_MESSAGE_MAP(CTest_ProgramDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
 //   ON_WM_SYSCOMMAND()
//   ON_WM_NCHITTEST()
	//}}AFX_MSG_MAP
	
	ON_BN_CLICKED(IDC_BUTTON2, &CTest_ProgramDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON1, &CTest_ProgramDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON4, &CTest_ProgramDlg::OnBnClickedButton4)
END_MESSAGE_MAP()


// CTest_ProgramDlg 消息處理程序

BOOL CTest_ProgramDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	
    //pWnd=GetDlgItem(IDC_SHOCKWAVEFLASH1);
	//pWnd->SetWindowPos(-1,0,0,600,600,NULL);
	// 將“關於...”菜單項添加到系統菜單中。
	// IDM_ABOUTBOX 必須在系統命令範圍內。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
	// 設置此對話框的圖標。當應用程序主窗口不是對話框時,框架將自動
	//  執行此操作
	SetIcon(m_hIcon, TRUE);			// 設置大圖標
	SetIcon(m_hIcon, FALSE);		// 設置小圖標
	// TODO: 在此添加額外的初始化代碼
	//Action();

CreateThread(NULL,0,Move,this,0,NULL);

	f=0;
	m_speed=500;
	mark=0;
	score=0;
	down=0;
    d=0;
    stop=0;

	sq[0].arr[0][0]=0;
	sq[0].arr[0][1]=1;
    sq[0].arr[0][2]=0;
	sq[0].arr[0][3]=0;

	sq[0].arr[1][0]=0;
	sq[0].arr[1][1]=1;
    sq[0].arr[1][2]=0;
	sq[0].arr[1][3]=0;

	sq[0].arr[2][0]=0;
	sq[0].arr[2][1]=1;
    sq[0].arr[2][2]=0;
	sq[0].arr[2][3]=0;

	sq[0].arr[3][0]=0;
	sq[0].arr[3][1]=1;
    sq[0].arr[3][2]=0;
	sq[0].arr[3][3]=0;
    //條狀
	sq[1].arr[0][0]=0;
	sq[1].arr[0][1]=1;
    sq[1].arr[0][2]=0;
	sq[1].arr[0][3]=0;
	
	sq[1].arr[1][0]=0;
	sq[1].arr[1][1]=1;
    sq[1].arr[1][2]=0;
	sq[1].arr[1][3]=0;

	sq[1].arr[2][0]=0;
	sq[1].arr[2][1]=1;
    sq[1].arr[2][2]=1;
	sq[1].arr[2][3]=0;

	sq[1].arr[3][0]=0;
	sq[1].arr[3][1]=0;
    sq[1].arr[3][2]=0;
	sq[1].arr[3][3]=0;
	//右倒鉤
	sq[2].arr[0][0]=0;
	sq[2].arr[0][1]=0;
    sq[2].arr[0][2]=1;
	sq[2].arr[0][3]=0;
	
	sq[2].arr[1][0]=0;
	sq[2].arr[1][1]=0;
    sq[2].arr[1][2]=1;
	sq[2].arr[1][3]=0;

	sq[2].arr[2][0]=0;
	sq[2].arr[2][1]=1;
    sq[2].arr[2][2]=1;
	sq[2].arr[2][3]=0;

	sq[2].arr[3][0]=0;
	sq[2].arr[3][1]=0;
    sq[2].arr[3][2]=0;
	sq[2].arr[3][3]=0;
	//左倒鉤
	sq[3].arr[0][0]=0;
	sq[3].arr[0][1]=0;
    sq[3].arr[0][2]=0;
	sq[3].arr[0][3]=0;
	
	sq[3].arr[1][0]=0;
	sq[3].arr[1][1]=1;
    sq[3].arr[1][2]=1;
	sq[3].arr[1][3]=0;

	sq[3].arr[2][0]=0;
	sq[3].arr[2][1]=1;
    sq[3].arr[2][2]=1;
	sq[3].arr[2][3]=0;

	sq[3].arr[3][0]=0;
	sq[3].arr[3][1]=0;
    sq[3].arr[3][2]=0;
	sq[3].arr[3][3]=0;
	//方形
	sq[4].arr[0][0]=0;
	sq[4].arr[0][1]=1;
    sq[4].arr[0][2]=0;
	sq[4].arr[0][3]=0;
	
	sq[4].arr[1][0]=0;
	sq[4].arr[1][1]=1;
    sq[4].arr[1][2]=1;
	sq[4].arr[1][3]=0;

	sq[4].arr[2][0]=0;
	sq[4].arr[2][1]=0;
    sq[4].arr[2][2]=1;
	sq[4].arr[2][3]=0;

	sq[4].arr[3][0]=0;
	sq[4].arr[3][1]=0;
    sq[4].arr[3][2]=0;
	sq[4].arr[3][3]=0;
	//右Z
	sq[5].arr[0][0]=0;
	sq[5].arr[0][1]=0;
    sq[5].arr[0][2]=1;
	sq[5].arr[0][3]=0;
	
	sq[5].arr[1][0]=0;
	sq[5].arr[1][1]=1;
    sq[5].arr[1][2]=1;
	sq[5].arr[1][3]=0;

	sq[5].arr[2][0]=0;
	sq[5].arr[2][1]=1;
    sq[5].arr[2][2]=0;
	sq[5].arr[2][3]=0;

	sq[5].arr[3][0]=0;
	sq[5].arr[3][1]=0;
    sq[5].arr[3][2]=0;
	sq[5].arr[3][3]=0;
	//左z
	sq[6].arr[0][0]=0;
	sq[6].arr[0][1]=0;
    sq[6].arr[0][2]=0;
	sq[6].arr[0][3]=0;
	
	sq[6].arr[1][0]=0;
	sq[6].arr[1][1]=1;
    sq[6].arr[1][2]=0;
	sq[6].arr[1][3]=0;

	sq[6].arr[2][0]=1;
	sq[6].arr[2][1]=1;
    sq[6].arr[2][2]=1;
	sq[6].arr[2][3]=0;

	sq[6].arr[3][0]=0;
	sq[6].arr[3][1]=0;
    sq[6].arr[3][2]=0;
	sq[6].arr[3][3]=0;
	//飛機形
	
	return TRUE;  // 除非將焦點設置到控件,否則返回 TRUE
}

void CTest_ProgramDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
/*
if (nID == SC_MOVE || nID==0xF012)
return;
else
CDialog::OnSysCommand(nID, lParam);
*/
}

// 如果向對話框添加最小化按鈕,則需要下面的代碼
//  來繪製該圖標。對於使用文檔/視圖模型的 MFC 應用程序,
//  這將由框架自動完成。

void CTest_ProgramDlg::OnPaint()
{
	if(1==d)
	{
    CPaintDC dc(this); // 用於繪製的設備上下文				//加載背景位圖
    CBitmap bmp;
    bmp.LoadBitmap(IDB_BITMAP1);
    CDC dcMemory;
    dcMemory.CreateCompatibleDC(&dc);//創建內存DC
    CBitmap *pOldBmp = dcMemory.SelectObject(&bmp);
    CRect rect;
    GetClientRect(rect);
    dc.BitBlt(0, 0, rect.Width(), rect.Height(), &dcMemory, 0, 0, SRCCOPY);
    dcMemory.SelectObject(pOldBmp);

    CWnd *pWnd=GetDlgItem(IDC_STATIC_TEST);
    CDC *pControlDC=pWnd->GetDC();
	CBrush br(RGB(0,0,0));//創建背景色筆刷
	
    pControlDC->SelectObject(&br);        
    pWnd->Invalidate();
    pWnd->UpdateWindow();
	for(int i=0;i<360;i+=20)
	{
		for(int j=0;j<300;j+=20)
		{
			pControlDC->Rectangle(j,i,j+20,i+20);
		}
	}
	}
   
	//::AfxMessageBox("版本號1.0\n作者:奇蹟冬瓜\n版權所有 翻版必究");
}

//當用戶拖動最小化窗口時系統調用此函數取得光標
//顯示。
HCURSOR CTest_ProgramDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CTest_ProgramDlg::OnBnClickedButton2()
{
	
	::exit(1);
	// TODO: 在此添加控件通知處理程序代碼
}
void CTest_ProgramDlg::OnBnClickedButton4()
{
	
	  stop+=1;
	// TODO: 在此添加控件通知處理程序代碼
}
void CTest_ProgramDlg::OnBnClickedButton1()
{
     // play();
	if(0==f)
	{
		f=1;
		CreateThread(NULL,0,play,this,0,NULL);
	}
	// TODO: 在此添加控件通知處理程序代碼
}
void CTest_ProgramDlg::InitBackground(int (*Ba)[15])
{
	for(int i=0;i<18;i++)
	{
		for(int j=0;j<15;j++)
		{
			Ba[i][j]=0;
		}
	}
	//::AfxMessageBox("OK");
}

bool CTest_ProgramDlg::GameOver(int (*Ba)[15])
{
	int flag=0;
	for(int i=0;i<18;i++)
	{
		for(int j=0;j<15;j++)
		{
			if(1==Ba[i][j])
			{
				flag+=1;
				break;
			}
		}
	}
	if(flag>=18)
	{
		//::AfxMessageBox("true");
		return true;
		
	}
	else
	{
		//::AfxMessageBox("flase");
		return false;
		
	}
}

int CTest_ProgramDlg::RandomGenSquare()
{
	srand((unsigned)time(NULL));
	return rand()%7;
	//CString as;
	//as.Format("%d",i);
	//::AfxMessageBox(as);
}

void CTest_ProgramDlg::DrawSquare(Squares s,int (*Ba)[15],CPoint p1,CPoint p2)
{
	int k=0;
	for(int i=p1.y;i<=p2.y;i++,k++)
	{
		for(int j=p1.x,l=0;j<=p2.x;j++,l++)
		{
			if(1==s.arr[k][l]&&0==Ba[i][j])
			{
				Ba[i][j]=1;
			}
		}
	}
}
void CTest_ProgramDlg::DrawBackground(int ID,int (*Ba)[15])
{
	CWnd *pWnd=GetDlgItem(ID);
	CDC *pControlDC=pWnd->GetDC();
   // pWnd->Invalidate();
   // pWnd->UpdateWindow();
	COLORREF clr;
	for(int i=0;i<18;i++)
	{
		for(int j=0;j<15;j++)
		{
			if(0==Ba[i][j])
			{
				clr=RGB(0,0,0);
			}
			else
			{
				clr=RGB(0,255,255);
			}
			CBrush brush(clr);
			pControlDC->SelectObject(&brush);
			pControlDC->Rectangle(j*20,i*20,j*20+20,i*20+20);
			brush.DeleteObject();
		}
	}
	pWnd->ReleaseDC(pControlDC);
}
bool CTest_ProgramDlg::HitBottomJudge(int (*Ba)[15],Squares s,CPoint p1,CPoint p2)
{
	int k=0;
	for(int i=p1.y;i<=p2.y;i++,k++)
	{
		for(int j=p1.x,l=0;j<=p2.x;j++,l++)
		{
			if((1==s.arr[k][l]&&18==i+1)||(1==s.arr[k][l]&&1==Ba[i+1][j]&&1!=s.arr[k+1][l]))
			{
				return true;
			}
		}
	}
	return false;
}

void CTest_ProgramDlg::MoveDown(Squares s,int (*Ba)[15],CPoint *p1,CPoint *p2)
{
	
	for(int i=p1->y;i<=p2->y;i++)
	{
		for(int j=p1->x;j<=p2->x;j++)
		{
			if(1==Ba[i][j])
			{
				Ba[i][j]=0;
			}
		}
	}
	p1->y+=1;
	p2->y+=1;
	if(0==down)
	{
		m_speed=300;
	}
	else
	{
		m_speed=10;
	}
	DrawSquare(s,Ba,*p1,*p2);
	::Sleep(m_speed);
	down=0;
	
}
DWORD WINAPI play(LPVOID lpParam) 
{
	  CTest_ProgramDlg *c=(CTest_ProgramDlg*)lpParam;
     c->score=0;
	 c->InitBackground(c->Background);//初始化背景方塊
	for(int i=0;i<18;i++)
	{
		for(int j=0;j<15;j++)
		{
			c->temp[i][j]=0;
		}
	}
	while(!c->GameOver(c->Background))//判斷是否遊戲結束
	{

		c->i=c->RandomGenSquare();//隨機生成方塊
		c->p1.x=6;
		c->p1.y=-3;
		c->p2.x=9;
		c->p2.y=0;
		c->Copy(c->Background,c->temp);
		c->DrawSquare(c->sq[c->i],c->Background,c->p1,c->p2);
		c->DrawBackground(IDC_STATIC_TEST,c->Background);
		//c->Copy(c->Background,c->temp);
		//判斷方塊是否觸底
		while(!c->HitBottomJudge(c->Background,c->sq[c->i],c->p1,c->p2))
		{
		       while(c->stop%2)
		       {
                    c->Copy(c->temp,c->Background);
			        c->DrawBackground(IDC_STATIC_TEST,c->Background);
				   ::Sleep(1);
		       }
			c->MoveDown(c->sq[c->i],c->Background,&c->p1,&c->p2);//下移方塊一次
			c->Copy(c->temp,c->Background);
			c->DrawBackground(IDC_STATIC_TEST,c->Background);//繪製背景
		}
		c->EliminateSquare();//消除方格
		//c->Copy(c->temp,c->Background);
	   /* for(int i=0;i<18;i++)
	    {
		    for(int j=0;j<15;j++)
		    {
			    c->temp[i][j]=0;
		    }
	    }*/

	    c->Copy(c->Background,c->temp);
		c->DrawBackground(IDC_STATIC_TEST,c->Background);//繪製背景
		//c->InitBackground(c->Background);
		//c->Copy(c->temp,c->Background);
		//::Sleep(10000);
		//c->Copy(c->temp,c->Background);
		//c->Copy(c->Background,c->temp);

	}
	::AfxMessageBox("遊戲結束!");
	  c->f=0;
      return 0;
}
DWORD WINAPI Move(LPVOID lpParam)  
{

CTest_ProgramDlg *c=(CTest_ProgramDlg*)lpParam;
//c->Lock();
 CString Type="swf";
  HRSRC res=FindResource (NULL,MAKEINTRESOURCE(IDR_SWF1),Type);
  HGLOBAL gl=LoadResource (NULL,res);  
  //返回指向資源內存的地址的指針
  LPVOID lp=LockResource(gl);
  //保存的臨時文件名
  CString filename="search.swf";
  
  HANDLE fp= CreateFile(filename,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
  DWORD a;
  //sizeofResource 得到資源文件的大小
  if (!WriteFile (fp,lp,SizeofResource (NULL,res),&a,NULL))
  return 1;
  //關閉句柄
  CloseHandle (fp);
  //釋放內存
  FreeResource (gl);  
 
  //查找flash文件並加載
  TCHAR strCurDrt[500];
  int nLen = ::GetCurrentDirectory(500,strCurDrt);
  if( strCurDrt[nLen]!='\\' )
  {
  strCurDrt[nLen++] = '\\';
  strCurDrt[nLen] = '\0';
  }
    
  CString strFileName = strCurDrt;
  strFileName += "search.swf";
  c->m_flash.LoadMovie(0, strFileName);
  c->m_flash.Stop();
  c->No();
  return true;
}
void CTest_ProgramDlg::No()
{

	::Sleep(30000);
	CWnd *pWnd=GetDlgItem(IDC_SHOCKWAVEFLASH1);
	pWnd->ShowWindow(SW_HIDE);
    pWnd=GetDlgItem(IDC_STATIC_TEST);
	pWnd->SetWindowPos(NULL,80,110,300,360,NULL);
	
	//pWnd=GetDlgItem(IDD_TEST_PROGRAM_DIALOG);
	//pWnd->EnableWindow(TRUE);
    d=1;
	//WS_POPUP
}
/*
void CTest_ProgramDlg::Lock()
{
CWnd *pWnd=GetDlgItem(IDD_TEST_PROGRAM_DIALOG);
pWnd->EnableWindow(FALSE);
}*/
void CTest_ProgramDlg::Copy(int (*Ba)[15], int (*Ca)[15])
{
	for(int i=0;i<18;i++)
	{
		for(int j=0;j<15;j++)
		{
			if(1==Ba[i][j])
			{
				Ca[i][j]=Ba[i][j];
			}
		}
	}
}
void CTest_ProgramDlg::MoveRight(Squares s, int (*Ba)[15], CPoint *p1, CPoint *p2)
{
	       Copy(temp,Background);
	      for(int i=p1->y;i<=p2->y;i++)
	      {
		        for(int j=p1->x;j<=p2->x;j++)
		        {
			         if(1==Ba[i][j])
			        {
				        Ba[i][j]=0;
			        }
		        }
	      }
		  p1->x+=1;
		  p2->x+=1;
		  Copy(temp,Background);
		  DrawSquare(s,Ba,*p1,*p2);
		 // ::Sleep(10);
		//  Copy(temp,Background);
}
void CTest_ProgramDlg::MoveLeft(Squares s, int (*Ba)[15], CPoint *p1, CPoint *p2)
{
	       Copy(temp,Background);
	      for(int i=p1->y;i<=p2->y;i++)
	      {
		        for(int j=p1->x;j<=p2->x;j++)
		        {
			         if(1==Ba[i][j])
			        {
				        Ba[i][j]=0;
			        }
		        }
	      }
		  p1->x-=1;
		  p2->x-=1;
		  Copy(temp,Background);
		  DrawSquare(s,Ba,*p1,*p2);
		//  Copy(temp,Background);
		 // ::Sleep(10);
}

bool CTest_ProgramDlg::RightJudge(int (*Ba)[15],Squares s,CPoint p1,CPoint p2)
{
    int k=0;
	for(int i=p1.y;i<=p2.y;i++,k++)
	{
		for(int j=p1.x,l=0;j<=p2.x;j++,l++)
		{
			if((1==s.arr[k][l]&&15==j+1)||(1==s.arr[k][l]&&1==Ba[i][j+1]&&1!=s.arr[k][l+1]))
			{
				return true;
			}
		}
	}
	return false;
}
bool CTest_ProgramDlg::LeftJudge(int (*Ba)[15],Squares s,CPoint p1,CPoint p2)
{
    int k=0;
	for(int i=p1.y;i<=p2.y;i++,k++)
	{
		for(int j=p1.x,l=0;j<=p2.x;j++,l++)
		{
			if((1==s.arr[k][l]&&-1==j-1)||(1==s.arr[k][l]&&1==Ba[i][j-1]&&1!=s.arr[k][l-1]))
			{
				return true;
			}
		}
	}
	return false;
}

void CTest_ProgramDlg::EliminateSquare()
{
 	int flag=0,a[18],k=0,te;
	for(int i=0;i<18;i++)
	{
		int markNum=0;
		for(int j=0;j<15;j++)
		{
			if(1==Background[i][j])
			{
				markNum++;
			}
		}
		if(15==markNum)
		{
			a[k++]=i;
			flag++;
			score+=100;
			ShowScores(IDC_STATIC_SCORE,score);
		}
	}
	te=k;
	k=0;
	while(k<te)
	{
		for(int i=a[k];i>0;i--)
		{
			for(int j=0;j<15;j++)
			{
				Background[i][j]=Background[i-1][j];
			}
		}
		k++;
	}
	for(int i=0;i<18;i++)
	{
		for(int j=0;j<15;j++)
		{
			temp[i][j]=0;
		}
	}
	Copy(Background,temp);
/*
	while(flag)
	{
	for(int i=17;i>=1;i--)
	{
		for(int j=0;j<15;j++)
		{
			Background[i][j]=Background[i-1][j];

		}	
	}
	for(int i=0,j=0;j<15;j++)
	{
		Background[i][j]=0;
	}
	flag--;
	//c->EliminateSquare();
	}
*/
	//DrawBackground(IDC_STATIC_TEST,Background);

	//Copy(Background,temp);
	//DrawBackground(IDC_STATIC_TEST,Background);
}

void CTest_ProgramDlg::ShowScores(int ID, long score)
{
	CString as;
	as.Format("%d",score);
	GetDlgItem(ID)->SetWindowText(as);
}

BOOL CTest_ProgramDlg::PreTranslateMessage(MSG* pMsg)
{		      
	if (pMsg-> message == WM_KEYDOWN)
	 {
		 if(pMsg-> wParam== VK_UP)//
		 {
				if(!LeftJudge(Background,sq[CTest_ProgramDlg::i],p1,p2)&&!RightJudge(Background,sq[CTest_ProgramDlg::i],p1,p2)&&!HitBottomJudge(Background,sq[CTest_ProgramDlg::i],p1,p2))
				{
				int temp[4][4];
	            for(int i=0;i<4;i++)
	            {
		              for(int j=0;j<4;j++)
		              {
			             temp[i][j]=sq[CTest_ProgramDlg::i].arr[j][3-i];
		              }
	             }
	             for(int i=0;i<4;i++)
	             {
		           for(int j=0;j<4;j++)
		          {
			          sq[CTest_ProgramDlg::i].arr[i][j]=temp[i][j];
		           }
	             }
	             for(int i=p1.y;i<=p2.y;i++)
	             {
		                for(int j=p1.x;j<=p2.x;j++)
		                {
			                  if(1==Background[i][j])
			                  {
				                    Background[i][j]=0;
			                   }
		                }
	              }
	             DrawSquare(sq[CTest_ProgramDlg::i],Background,p1,p2);
				 Copy(CTest_ProgramDlg::temp,Background);
			
			}
		 }

		  if(pMsg-> wParam== VK_DOWN)//
		  {
			down=1;
		  }
		  if(pMsg-> wParam== VK_LEFT)//
		 {
			 Copy(CTest_ProgramDlg::temp,Background);
			if(!LeftJudge(Background,sq[CTest_ProgramDlg::i],p1,p2))
	         {
              MoveLeft(sq[i],Background,&p1,&p2);
              Copy(CTest_ProgramDlg::temp,Background);
			  DrawBackground(IDC_STATIC_TEST,Background);//繪製背景
			}
		 }
		    if(pMsg-> wParam== VK_RIGHT)//
		 {
			 Copy(CTest_ProgramDlg::temp,Background);
			 if(!RightJudge(Background,sq[CTest_ProgramDlg::i],p1,p2))
			 {
			  MoveRight(sq[i],Background,&p1,&p2);
			  Copy(CTest_ProgramDlg::temp,Background);
			  DrawBackground(IDC_STATIC_TEST,Background);
			 }
		 }

	 }
return CDialog::PreTranslateMessage(pMsg);
}
/*
UINT CTest_ProgramDlg::OnNcHitTest(CPoint point)
{
    int ret = CDialog::OnNcHitTest(point);

    if( HTCAPTION == ret)
        return HTCLIENT;

    return ret;
}
*/
/*
void CTest_ProgramDlg::OnSysCommand(UINT nID, LPARAM lParam)
{

}
*/


 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章