// HWRECTView.cpp : implementation of the CHWRECTView class
//
#include "stdafx.h"
#include "HWRECT.h"
#include "OptionDlg.h"
#include "mmsystem.h"
#include "HWRECTDoc.h"
#include "HWRECTView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHWRECTView
IMPLEMENT_DYNCREATE(CHWRECTView, CView)
BEGIN_MESSAGE_MAP(CHWRECTView, CView)
//{{AFX_MSG_MAP(CHWRECTView)
ON_WM_KEYDOWN()
ON_WM_TIMER()
ON_COMMAND(ID_GAME_START, OnGameStart)
ON_COMMAND(ID_GAME_END, OnGameEnd)
ON_COMMAND(ID_GAME_OPTION, OnGameOption)
ON_UPDATE_COMMAND_UI(ID_GAME_START, OnUpdateGameStart)
ON_UPDATE_COMMAND_UI(ID_GAME_OPTION, OnUpdateGameOption)
ON_UPDATE_COMMAND_UI(ID_GAME_END, OnUpdateGameEnd)
ON_UPDATE_COMMAND_UI(ID_GAME_EXIT, OnUpdateGameExit)
ON_UPDATE_COMMAND_UI(ID_HELP_ABOUT, OnUpdateHelpAbout)
ON_UPDATE_COMMAND_UI(ID_HELP_HELP, OnUpdateHelpHelp)
ON_WM_CREATE()
ON_COMMAND(ID_HELP_HELP, OnHelpHelp)
ON_UPDATE_COMMAND_UI(ID_OPTION_AREA1, OnUpdateOptionArea1)
ON_UPDATE_COMMAND_UI(ID_OPTION_AREA2, OnUpdateOptionArea2)
ON_UPDATE_COMMAND_UI(ID_OPTION_AREA3, OnUpdateOptionArea3)
ON_UPDATE_COMMAND_UI(ID_OPTION_AREA4, OnUpdateOptionArea4)
ON_COMMAND(ID_OPTION_AREA1, OnOptionArea1)
ON_COMMAND(ID_OPTION_AREA2, OnOptionArea2)
ON_COMMAND(ID_OPTION_AREA3, OnOptionArea3)
ON_COMMAND(ID_OPTION_AREA4, OnOptionArea4)
ON_UPDATE_COMMAND_UI(ID_OPTION_LEVEL1, OnUpdateOptionLevel1)
ON_UPDATE_COMMAND_UI(ID_OPTION_LEVEL2, OnUpdateOptionLevel2)
ON_UPDATE_COMMAND_UI(ID_OPTION_LEVEL3, OnUpdateOptionLevel3)
ON_UPDATE_COMMAND_UI(ID_OPTION_LEVEL4, OnUpdateOptionLevel4)
ON_UPDATE_COMMAND_UI(ID_OPTION_LEVEL5, OnUpdateOptionLevel5)
ON_UPDATE_COMMAND_UI(ID_OPTION_LEVEL6, OnUpdateOptionLevel6)
ON_COMMAND(ID_OPTION_LEVEL1, OnOptionLevel1)
ON_COMMAND(ID_OPTION_LEVEL2, OnOptionLevel2)
ON_COMMAND(ID_OPTION_LEVEL3, OnOptionLevel3)
ON_COMMAND(ID_OPTION_LEVEL4, OnOptionLevel4)
ON_COMMAND(ID_OPTION_LEVEL5, OnOptionLevel5)
ON_COMMAND(ID_OPTION_LEVEL6, OnOptionLevel6)
ON_UPDATE_COMMAND_UI(ID_OPTION_GRID, OnUpdateOptionGrid)
ON_COMMAND(ID_OPTION_GRID, OnOptionGrid)
ON_UPDATE_COMMAND_UI(ID_OPTION_MUSIC, OnUpdateOptionMusic)
ON_COMMAND(ID_OPTION_MUSIC, OnOptionMusic)
ON_UPDATE_COMMAND_UI(ID_GAME_PAUSH, OnUpdateGamePaush)
ON_COMMAND(ID_GAME_PAUSH, OnGamePaush)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHWRECTView construction/destruction
/* * * * * * * * * * * * * * * * * * * * * * * * *
*
* 名称:构造函数
*
* 功能:初始化变量
*
* 最后修改时间:1999.3.22
*
* * * * * * * * * * * * * * * * * * * * * * * * */
CHWRECTView::CHWRECTView()
{
//缺省为不是游戏暂停状态
m_bGamePaush = FALSE;
//缺省为不插放背景音乐
m_bMusic = FALSE;
//缺省为画网格线
m_bDrawGrid = TRUE;
//总分值清零
m_iPerformance = 0;
//测试值:为12行,10列
m_iRow = 12;
m_iCol = 10;
//左上角X,Y坐标
m_iStartX = 10;
m_iStartY = 10;
//缺省级别为3级
m_iLevel = 2;
//缺省方块大小为m_iLarge个象素
m_iLarge = 30;
//缺省游戏是结束的
m_bGameEnd = TRUE;
int i,j;
//赋初值
for (i=0;i<100;i++)
for (j=0;j<100;j++)
GameStatus[i][j]=0;
//各种形状方块的接触面数据,参见设计书的接触面表格, 如果某种形状的方块没有4个接触面,则后面的数据填-1
for (i=0;i<74;i++)
for (j=0;j<4;j++)
InterFace[i][j] = -1;
InterFace[1][0] = 3;
InterFace[11][0] = 0; InterFace[11][1] = 1; InterFace[11][2] = 2; InterFace[11][3] = 3;
InterFace[2][0] = 1; InterFace[2][1] = 3;
InterFace[3][0] = 0; InterFace[3][1] = 2; InterFace[3][2] = 3;
InterFace[31][0] = 2; InterFace[31][1] = 3;
InterFace[32][0] = 0; InterFace[32][1] = 2; InterFace[32][2] = 3;
InterFace[33][0] = 0; InterFace[33][1] = 3;
InterFace[4][0] = 1; InterFace[4][1] = 3;
InterFace[41][0] = 0; InterFace[41][1] = 2; InterFace[41][2] = 3;
InterFace[5][0] = 1; InterFace[5][1] = 3;
InterFace[51][0] = 0; InterFace[51][1] = 2; InterFace[51][2] = 3;
InterFace[6][0] = 0; InterFace[6][1] = 3;
InterFace[61][0] = 1; InterFace[61][1] = 2; InterFace[61][2] = 3;
InterFace[62][0] = 2; InterFace[62][1] = 3;
InterFace[63][0] = 0; InterFace[63][1] = 1; InterFace[63][2] = 3;
InterFace[7][0] = 2; InterFace[7][1] = 3;
InterFace[71][0] = 1; InterFace[71][1] = 2; InterFace[71][2] = 3;
InterFace[72][0] = 0; InterFace[72][1] = 3;
InterFace[73][0] = 0; InterFace[73][1] = 1; InterFace[73][2] = 3;
}
/* * * * * * * * * * * * * * * * * * * * * * * * *
*
* 名称:析构函数
*
* 功能:无
*
* 最后修改时间:1999.3.22
*
* * * * * * * * * * * * * * * * * * * * * * * * */
CHWRECTView::~CHWRECTView()
{
}
BOOL CHWRECTView::PreCreateWindow(CREATESTRUCT& cs)
{
return CView::PreCreateWindow(cs);
}
//创建一些设备
int CHWRECTView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
//白色的黑笔
whitePen = new CPen(PS_SOLID,1,WHITE);
//黑色的黑笔
blackPen = new CPen(PS_SOLID,1,BLACK);
//画刷
grayBrush = new CBrush(RGB(0,255,255));
blueBrush = new CBrush(BLUE);
blackBrush = new CBrush(BLACK);
//决定第一次掉下来的方块的样式
m_inextStatus = Random(7);
if (m_inextStatus==0) m_inextStatus++;
return 0;
}
/* * * * * * * * * * * * * * * * * * * * * * * * *
*
* 名称:OnDraw
*
* 功能:承担所有绘制屏幕工作
*
* 最后修改时间:1999.3.22
*
* * * * * * * * * * * * * * * * * * * * * * * * */
void CHWRECTView::OnDraw(CDC* pDC)
{
CHWRECTDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int i,j;
//CBrush *oldBrush =
pDC -> SelectObject(blackBrush);
CRect rect;
GetClientRect(&rect);
pDC -> Rectangle(rect);
pDC -> SelectObject(grayBrush);
pDC -> Rectangle(m_iStartY ,m_iStartX, m_iStartY + 301, m_iStartX + 360);
pDC -> SelectObject(blueBrush);
//CPen *oldPen =
pDC->SelectObject(blackPen);
//画网格线
if (m_bDrawGrid)
{
//画横线
for (i=0;i<m_iRow;i++)
{
pDC->MoveTo(m_iStartY, m_iStartX + i*m_iLarge);
pDC->LineTo(m_iStartY+300, m_iStartX +i*m_iLarge);
}
//画竖线
for (i=0;i<m_iCol;i++)
{
pDC->MoveTo(m_iStartY+i*m_iLarge, m_iStartX);
pDC->LineTo(m_iStartY+i*m_iLarge, m_iStartX+360);
}
}
//画方块
for (i=0;i<m_iRow;i++)
for (j=0;j<m_iCol;j++)
{
if (GameStatus[i][j]==1)
{
//划的方块比规定的大小略微小一点
//画小方块边框黑线
pDC -> SelectObject(blackPen);
pDC -> MoveTo(m_iStartY+j*m_iLarge +1, m_iStartX+i*m_iLarge +1);
pDC -> LineTo(m_iStartY+j*m_iLarge +1, m_iStartX+(i+1)*m_iLarge -1);
pDC -> MoveTo(m_iStartY+j*m_iLarge +1, m_iStartX+(i+1)*m_iLarge -1);
pDC -> LineTo(m_iStartY+(j+1)*m_iLarge -1, m_iStartX+(i+1)*m_iLarge -1);
//画小方块边框白线
pDC -> SelectObject(whitePen);
pDC -> MoveTo(m_iStartY+j*m_iLarge +1, m_iStartX+i*m_iLarge +1);
pDC -> LineTo(m_iStartY+(j+1)*m_iLarge -1,m_iStartX+i*m_iLarge +1);
pDC -> MoveTo(m_iStartY+(j+1)*m_iLarge -1,m_iStartX+i*m_iLarge +1);
pDC -> LineTo(m_iStartY+(j+1)*m_iLarge -1,m_iStartX+(i+1)*m_iLarge -1);
//每个方块填充绿色的背景
pDC -> Rectangle(m_iStartY+j*m_iLarge +2,m_iStartX+i*m_iLarge +2,m_iStartY+(j+1)*m_iLarge -2,m_iStartX+(i+1)*m_iLarge -2);
}
}
//显示游戏区域及游戏级别的汉字描述
if (!m_bGameEnd)
{
pDC -> SetBkColor(BLACK);
pDC -> SetTextColor(WHITE);
pDC -> TextOut(m_iStartY+320, m_iStartX+220, "游戏区域大小:");
pDC -> TextOut(m_iStartY+320, m_iStartX+240,m_strArea);
pDC -> TextOut(m_iStartY+320, m_iStartX+280, "游戏级别:");
pDC -> TextOut(m_iStartY+320, m_iStartX+300,m_strLevel);
}
//显示总分
if (!m_bGameEnd)
{
CString lsStr;
lsStr.Format("总分为:%d 分",m_iPerformance);
pDC -> SetBkColor(BLACK);
pDC -> Se