📄 俄罗斯方快代码.txt
字号:
// 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 -> SetTextColor(WHITE);
pDC -> TextOut(m_iStartY+320, m_iStartX+180,lsStr);
}
//画下一次将要出现的方块,用于提示用户
if (!m_bGameEnd)
{
pDC -> SetBkColor(BLACK);
pDC -> SetTextColor(WHITE);
pDC -> TextOut(m_iStartY+320, m_iStartX,"下一个方块:");
for (UINT k=0;k<4;k++)
{
i = NextStatus[k][0];
j = NextStatus[k][1];
//划的方块比规定的大小略微小一点
//画小方块边框黑线
pDC -> SelectObject(blackPen);
pDC -> MoveTo(m_iStartY+j*30 +1+320, m_iStartX+i*30 +1+30);
pDC -> LineTo(m_iStartY+j*30 +1+320, m_iStartX+(i+1)*30 -1+30);
pDC -> MoveTo(m_iStartY+j*30 +1+320, m_iStartX+(i+1)*30 -1+30);
pDC -> LineTo(m_iStartY+(j+1)*30 -1+320, m_iStartX+(i+1)*30 -1+30);
//画小方块边框白线
pDC -> SelectObject(whitePen);
pDC -> MoveTo(m_iStartY+j*30 +1+320, m_iStartX+i*30 +1+30);
pDC -> LineTo(m_iStartY+(j+1)*30 -1+320, m_iStartX+i*30 +1+30);
pDC -> MoveTo(m_iStartY+(j+1)*30 -1+320, m_iStartX+i*30 +1+30);
pDC -> LineTo(m_iStartY+(j+1)*30 -1+320, m_iStartX+(i+1)*30 -1+30);
//每个方块填充蓝色的背景
pDC -> Rectangle(m_iStartY+j*30 +2+320,m_iStartX+i*30 +2+30,
m_iStartY+(j+1)*30 -2+320,m_iStartX+(i+1)*30 -2+30);
}
}
// pDC -> SelectObject(oldPen);
// pDC -> SelectObject(oldBrush);
}
/////////////////////////////////////////////////////////////////////////////
// CHWRECTView diagnostics
#ifdef _DEBUG
void CHWRECTView::AssertValid() const
{
CView::AssertValid();
}
void CHWRECTView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CHWRECTDoc* CHWRECTView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHWRECTDoc)));
return (CHWRECTDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHWRECTView message handlers
/* * * * * * * * * * * * * * * * * * * * * * * * *
*
* 名称:OnTimer
*
* 功能:承担所有驱动工作
*
* 最后修改时间:1999.3.22
*
* * * * * * * * * * * * * * * * * * * * * * * * */
void CHWRECTView::OnTimer(UINT nIDEvent)
{
//如果原来的方块已到底或游戏刚开始,则掉下一个新的方块
int i,j,k;
if (m_isBottom)
{
m_icurrentStatus = m_inextStatus;
m_inextStatus = Random(7); //得到下一次的方块样式
if (m_inextStatus==0) m_inextStatus++;
m_currentRect = m_icurrentStatus; //当前落下的方块的形状代码
RectStatusToActiveStatus( m_icurrentStatus );
ActiveStatusToGameStatus();
m_isBottom = FALSE;
ActiveIsBottom();
InvalidateCurrent();
//在屏幕右边显示下一次将会出来的方块的模样
RectStatusToNextStatus( m_inextStatus );
CRect rect(m_iStartY+320, m_iStartX, m_iStartY+440, m_iStartX+160);
InvalidateRect(&rect);
//判断游戏是否已结束: 碰了底,且第1行有小方块
if (m_isBottom)
for (i=0;i<m_iCol;i++)
if (GameStatus[0][i])
{
KillTimer(1);
AfxMessageBox("游戏已结束!");
for (j=0;j<m_iRow;j++)
for (k=0;k<m_iCol;k++)
GameStatus[j][k]=0;
Invalidate();
m_bGameEnd = TRUE;
break;
}
}
else //当前方块下降
{
RectDown();
}
CView::OnTimer(nIDEvent);
}
/* * * * * * * * * * * * * * * * * * * * * *
* 内部函数:产生一个最大值不大于指定值的随机整数(Random)
*
* 参数:MaxNumber : 随机数的上限
*
* 返回值: 产生的随机数
*
* 最后修改日期:1999.1.22
* * * * * * * * * * * * * * * * * * * * * */
int CHWRECTView::Random(int MaxNumber)
{
int currentClock = (int)clock();
srand(currentClock);
return (rand() % MaxNumber);
}
/* * * * * * * * * * * * * * * * * * * * * *
* 内部函数:将当前动态数组中的数据反映到大数组中
*
* 最后修改日期:1999.1.22
* * * * * * * * * * * * * * * * * * * * * */
void CHWRECTView::ActiveStatusToGameStatus()
{
int x1,x2,x3,x4,y1,y2,y3,y4;
x1 = ActiveStatus[0][0];
x2 = ActiveStatus[1][0];
x3 = ActiveStatus[2][0];
x4 = ActiveStatus[3][0];
y1 = ActiveStatus[0][1];
y2 = ActiveStatus[1][1];
y3 = ActiveStatus[2][1];
y4 = ActiveStatus[3][1];
GameStatus[x1][y1]=1;
GameStatus[x2][y2]=1;
GameStatus[x3][y3]=1;
GameStatus[x4][y4]=1;
}
/* * * * * * * * * * * * * * * * * * * * * *
* 内部函数:初始掉落时,将根据方块的样式决定当前动态数组的值
*
* 最后修改日期:1999.1.22
* * * * * * * * * * * * * * * * * * * * * */
void CHWRECTView::RectStatusToActiveStatus(int m_which)
{
switch(m_which)
{
case 1:
ActiveStatus[0][0] = 0; ActiveStatus[0][1] = 5; ActiveStatus[1][0] = 1; ActiveStatus[1][1] = 5;
ActiveStatus[2][0] = 2; ActiveStatus[2][1] = 5; ActiveStatus[3][0] = 3; ActiveStatus[3][1] = 5;
break;
case 2:
ActiveStatus[0][0] = 0; ActiveStatus[0][1] = 5; ActiveStatus[1][0] = 1; ActiveStatus[1][1] = 5;
ActiveStatus[2][0] = 0; ActiveStatus[2][1] = 6; ActiveStatus[3][0] = 1; ActiveStatus[3][1] = 6;
break;
case 3:
ActiveStatus[0][0] = 1; ActiveStatus[0][1] = 4; ActiveStatus[1][0] = 0; ActiveStatus[1][1] = 5;
ActiveStatus[2][0] = 1; ActiveStatus[2][1] = 5; ActiveStatus[3][0] = 1; ActiveStatus[3][1] = 6;
break;
case 4:
ActiveStatus[0][0] = 0; ActiveStatus[0][1] = 5; ActiveStatus[1][0] = 1; ActiveStatus[1][1] = 5;
ActiveStatus[2][0] = 1; ActiveStatus[2][1] = 6; ActiveStatus[3][0] = 2; ActiveStatus[3][1] = 6;
break;
case 5:
ActiveStatus[0][0] = 1; ActiveStatus[0][1] = 5; ActiveStatus[1][0] = 2; ActiveStatus[1][1] = 5;
ActiveStatus[2][0] = 0; ActiveStatus[2][1] = 6; ActiveStatus[3][0] = 1; ActiveStatus[3][1] = 6;
break;
case 6:
ActiveStatus[0][0] = 0; ActiveStatus[0][1] = 5; ActiveStatus[1][0] = 0; ActiveStatus[1][1] = 6;
ActiveStatus[2][0] = 1; ActiveStatus[2][1] = 6; ActiveStatus[3][0] = 2; ActiveStatus[3][1] = 6;
break;
case 7:
ActiveStatus[0][0] = 0; ActiveStatus[0][1] = 5; ActiveStatus[1][0] = 1; ActiveStatus[1][1] = 5;
ActiveStatus[2][0] = 2; ActiveStatus[2][1] = 5; ActiveStatus[3][0] = 0; ActiveStatus[3][1] = 6;
break;
}
}
/* * * * * * * * * * * * * * * * * * * * * *
* 内部函数:初始掉落时,将根据方块的样式决定下一次将要掉下来的动态数组的值
*
* 最后修改日期:1999.1.22
* * * * * * * * * * * * * * * * * * * * * */
void CHWRECTView::RectStatusToNextStatus(int m_which)
{
switch(m_which)
{
case 1:
NextStatus[0][0] = 0; NextStatus[0][1] = 1; NextStatus[1][0] = 1; NextStatus[1][1] = 1;
NextStatus[2][0] = 2; NextStatus[2][1] = 1; NextStatus[3][0] = 3; NextStatus[3][1] = 1;
break;
case 2:
NextStatus[0][0] = 0; NextStatus[0][1] = 1; NextStatus[1][0] = 1; NextStatus[1][1] = 1;
NextStatus[2][0] = 0; NextStatus[2][1] = 2; NextStatus[3][0] = 1; NextStatus[3][1] = 2;
break;
case 3:
NextStatus[0][0] = 1; NextStatus[0][1] = 0; NextStatus[1][0] = 0; NextStatus[1][1] = 1;
NextStatus[2][0] = 1; NextStatus[2][1] = 1; NextStatus[3][0] = 1; NextStatus[3][1] = 2;
break;
case 4:
NextStatus[0][0] = 0; NextStatus[0][1] = 1; NextStatus[1][0] = 1; NextStatus[1][1] = 1;
NextStatus[2][0] = 1; NextStatus[2][1] = 2; NextStatus[3][0] = 2; NextStatus[3][1] = 2;
break;
case 5:
NextStatus[0][0] = 1; NextStatus[0][1] = 1; NextStatus[1][0] = 2; NextStatus[1][1] = 1;
NextStatus[2][0] = 0; NextStatus[2][1] = 2; NextStatus[3][0] = 1; NextStatus[3][1] = 2;
break;
case 6:
NextStatus[0][0] = 0; NextStatus[0][1] = 1; NextStatus[1][0] = 0; NextStatus[1][1] = 2;
NextStatus[2][0] = 1; NextStatus[2][1] = 2; NextStatus[3][0] = 2; NextStatus[3][1] = 2;
break;
case 7:
NextStatus[0][0] = 0; NextStatus[0][1] = 1; NextStatus[1][0] = 1; NextStatus[1][1] = 1;
NextStatus[2][0] = 2; NextStatus[2][1] = 1; NextStatus[3][0] = 0; NextStatus[3][1] = 2;
break;
}
}
/* * * * * * * * * * * * * * * * * * * * * *
* 内部函数:当前方块下降
*
* 最后修改日期:1999.1.22
* * * * * * * * * * * * * * * * * * * * * */
void CHWRECTView::RectDown()
{
ActiveIsBottom();
if (!m_isBottom)
{
//清除以前的方块
int x1,x2,x3,x4,y1,y2,y3,y4;
x1 = ActiveStatus[0][0];
x2 = ActiveStatus[1][0];
x3 = ActiveStatus[2][0];
x4 = ActiveStatus[3][0];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -