头文件:
#if !defined(AFX_WNDMAIN_H__143E8EA9_9690_4B57_A53F_95071AE2ECB8__INCLUDED_)
#define AFX_WNDMAIN_H__143E8EA9_9690_4B57_A53F_95071AE2ECB8__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// WndMain.h : header file
//
#include "DlgMain.h"
/////////////////////////////////////////////////////////////////////////////
// CWndMain window
class CWndMain : public CWnd
{
// Construction
public:
CWndMain();
// Attributes
public:
//画网格线
void DrawLine(CDC* pDC);
//位图,方块
void DrawSquBmp(CDC* pDC);
//预备方块
void DrawWill();
//游戏开始
void Start();
//移动的方向
bool MoveDir(int direction);
//控制越界
bool Meet(int a[][4], int direction, CPoint p);
//方块变换
bool Change(int a[][4], CPoint p, int b[][100]);
//检查要不要消行
void LineDelete();
//难度级别
void GameLevel(int level);
//显示位图
CBitmap m_bitmap;
//背景画刷
CBrush* BGBrush;
//网格区域画刷
CBrush* GridBrush;
//方格的画刷
CBrush* SquareBrush;
//画笔
CPen* penGrid;
CPen* penSquare;
//状态显示所用的字体
CFont m_font;
//字幕字体描述
LOGFONT m_lf;
//游戏区域左上角坐标
int m_startX;
int m_startY;
int m_col;
int m_row;
//大数组
int Russian[100][100];
//4*4的大方格,小数组
int GameSquare[4][4];
int GameSquWill[4][4];
int GameSquAfter[4][4];
//当前可能出现的图形形状数
int Count;
//开始的标志
BOOL m_Start;
//暂停的标志
BOOL m_Pause;
//游戏结束
BOOL m_End;
//当前图形的左上角位置
CPoint NowPosition;
//级数
int m_Level;
//分数
int m_Score;
//速度
int m_Speed;
int m_nYIndex;
int m_nXIndex;
int nx, ny;
int cx, cy;
int m_nIndex[4][2];
//定时器
int m_nTimer;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CWndMain)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CWndMain();
// Generated message map functions
protected:
//{{AFX_MSG(CWndMain)
afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnDestroy();
afx_msg void OnOptionLevel1();
afx_msg void OnOptionLevel2();
afx_msg void OnOptionLevel3();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
extern CWndMain g_wndMain;
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_WNDMAIN_H__143E8EA9_9690_4B57_A53F_95071AE2ECB8__INCLUDED_)
源文件:
// WndMain.cpp : implementation file
//
#include "stdafx.h"
#include "Russian.h"
#include "WndMain.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CWndMain g_wndMain;
/////////////////////////////////////////////////////////////////////////////
// CWndMain
CWndMain::CWndMain()
{
m_startX = 0;
m_startY = 0;
m_col = 14;
m_row = 20;
Count = 7;
m_Start = FALSE;
m_Pause = FALSE;
// NowPosition.x = 0;
// NowPosition.y = 0;
m_Level = 1;
m_Score = 0;
m_Speed = 20;
m_nYIndex = 0;
m_nXIndex = 0;
m_nTimer = -1;
int i, j;
for (i=0; i<100; i++)
{
for(j=0; j<100; j++)
{
Russian[i][j] = 0;
}
}
//4*4的大方格,数组值初始化为0
for (i=0; i<4; i++)
{
for (j=0; j<4; j++)
{
GameSquare[i][j] = 0;
}
}
for (i=0; i<4; i++)
{
for (j=0; j<4; j++)
{
GameSquWill[i][j] = 0;
}
}
for (i=0; i<4; i++)
{
for (j=0; j<4; j++)
{
GameSquAfter[i][j] = 0;
}
}
for (i=0; i<4; i++)
{
for (j=0; j<2; j++)
{
m_nIndex[i][j] = 0;
}
}
}
CWndMain::~CWndMain()
{
}
BEGIN_MESSAGE_MAP(CWndMain, CWnd)
//{{AFX_MSG_MAP(CWndMain)
ON_WM_PAINT()
ON_WM_ERASEBKGN