Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
ELSView.cpp
Package: ELS.rar [view]
Upload User: zhengxing
Upload Date: 2016-05-26
Package Size: 53k
Code Size: 20k
Category:
Chess Poker games
Development Platform:
Visual C++
- // ELSView.cpp : implementation of the CELSView class
- //
- #include "stdafx.h"
- #include "ELS.h"
- #include "ELSDoc.h"
- #include "ELSView.h"
- #include "OKDlg.h"
- #include "MemDC.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CELSView
- IMPLEMENT_DYNCREATE(CELSView, CView)
- BEGIN_MESSAGE_MAP(CELSView, CView)
- //{{AFX_MSG_MAP(CELSView)
- ON_COMMAND(ID_GAME_START, OnGameStart)
- ON_COMMAND(ID_GAME_PAUSE, OnGamePause)
- ON_COMMAND(ID_GAME_END, OnGameEnd)
- //ON_WM_PAINT()
- ON_WM_TIMER()
- ON_WM_KEYDOWN()
- ON_COMMAND(ID_PREPARE, OnPrepare)
- ON_UPDATE_COMMAND_UI(ID_GAME_START, OnUpdateGameStart)
- ON_UPDATE_COMMAND_UI(ID_GAME_PAUSE, OnUpdateGamePause)
- ON_UPDATE_COMMAND_UI(ID_GAME_END, OnUpdateGameEnd)
- //}}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()
- /////////////////////////////////////////////////////////////////////////////
- // CELSView construction/destruction
- CELSView::CELSView()
- {
- // TODO: add construction code here
- InitVariable();
- }
- CELSView::~CELSView()
- {
- }
- BOOL CELSView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CELSView drawing
- void CELSView::OnDraw(CDC* pDC)
- {
- CELSDoc* pDoc = GetDocument();
- if (m_nFlag==false)
- {
- //CDC *cDC=GetDC();
- CMemDC m_DC(pDC);
- CBrush *brush=new CBrush(RGB(22,22,22)); //改变背景的颜色,这里主要是黑色
- pDC->SelectObject(brush);
- CRect rect(0,0,500,500); //设置的背景的矩形区域
- GetClientRect(&rect);
- pDC->Rectangle(rect);
- InitGame(); //当窗口生成时就要初始化操作
- COLORREF clrRim = RGB(68, 71, 255); //每一个方块的色彩边框
- COLORREF clrMid = RGB(255,255,255); //每一个方块的色中间色彩,白色
- const UINT wide = 20; //方块的宽
- const UINT hight = 20; //方块的高
- const UINT StartX = 120; //起始绘表格处的位置
- //在离窗口(0,120)处 开始绘20*10个方格,作为游戏区域
- for (int x=0; x<20; x++)
- {
- for (int j=0; j<10; j++)
- {
- m_DC.FillSolidRect(StartX+j*20, x*20, wide, hight, clrMid); //填充图形
- m_DC.Draw3dRect(StartX+j*20, x*20, wide, hight, clrRim, clrMid); //画矩形
- }
- }
- //在(20,150)处,开始绘提示图的背景
- for (x=0; x<4; x++)
- {
- for (int j=0; j<4; j++)
- {
- m_DC.FillSolidRect(20+j*20, 150+x*20, wide, hight, clrMid);
- m_DC.Draw3dRect(20+j*20, 150+x*20, wide, hight, clrRim, clrMid);
- }
- }
- }
- else
- {
- DrawGame();
- }
- m_nFlag=true;
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CELSView printing
- BOOL CELSView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CELSView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CELSView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CELSView diagnostics
- #ifdef _DEBUG
- void CELSView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CELSView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CELSDoc* CELSView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CELSDoc)));
- return (CELSDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CELSView message handlers
- void CELSView::OnRandomRect()
- {
- m_nRectIndex = rand()%7; //生成7个图形中的一个
- //m_RectIndex = 1; //调试图形时用
- //每次新生成图形前,Init it
- for (int i= 0 ; i<4; i++)
- {
- RandomRect.Sqr[i].x=-1;
- RandomRect.Sqr[i].y=-1;
- RandomRect.m_nColor=0;
- RandomRect.Type=-1;
- }
- switch (m_nRectIndex)
- {
- case 0:
- RandomRect.Sqr[0].x = 4;
- RandomRect.Sqr[0].y = 0;
- RandomRect.Sqr[1].x = 5;
- RandomRect.Sqr[1].y = 0;
- RandomRect.Sqr[2].x = 4;
- RandomRect.Sqr[2].y = 1;
- RandomRect.Sqr[3].x = 5;
- RandomRect.Sqr[3].y = 1;
- RandomRect.m_nColor = RGB(204, 153, 255);
- RandomRect.Type = 0;
- break;
- /*图形为{ 色彩:淡紫
- 田
- }
- */
- case 1:
- RandomRect.Sqr[0].x = 6;
- RandomRect.Sqr[0].y = 0;
- RandomRect.Sqr[1].x = 5;
- RandomRect.Sqr[1].y = 0;
- RandomRect.Sqr[2].x = 4;
- RandomRect.Sqr[2].y = 0;
- RandomRect.Sqr[3].x = 3;
- RandomRect.Sqr[3].y = 0;
- RandomRect.m_nColor = RGB(0, 255, 0);
- RandomRect.Type = 1;
- //RandomRect.Flag=1;
- break;
- /*图形为{ 鲜绿
- ----
- }
- */
- case 2:
- RandomRect.Sqr[0].x = 5;
- RandomRect.Sqr[0].y = 0;
- RandomRect.Sqr[1].x = 4;
- RandomRect.Sqr[1].y = 1;
- RandomRect.Sqr[2].x = 5;
- RandomRect.Sqr[2].y = 1;
- RandomRect.Sqr[3].x = 4;
- RandomRect.Sqr[3].y = 2;
- RandomRect.m_nColor = RGB(255, 0, 255);
- RandomRect.Type = 2;
- //RandomRect.Flag=1;
- break;
- /*图形为{ |
- _ _
- |
- 粉红
- }
- */
- case 3:
- RandomRect.Sqr[0].x = 5;
- RandomRect.Sqr[0].y = 0;
- RandomRect.Sqr[1].x = 5;
- RandomRect.Sqr[1].y = 1;
- RandomRect.Sqr[2].x = 4;
- RandomRect.Sqr[2].y = 1;
- RandomRect.Sqr[3].x = 6;
- RandomRect.Sqr[3].y = 1;
- RandomRect.m_nColor = RGB(0,0 ,255);
- RandomRect.Type = 3;
- //RandomRect.Flag=1;
- break;
- /*图形为{ -
- _ _ _
- }蓝色
- */
- case 4:
- RandomRect.Sqr[0].x = 4;
- RandomRect.Sqr[0].y = 0;
- RandomRect.Sqr[1].x = 5;
- RandomRect.Sqr[1].y = 1;
- RandomRect.Sqr[2].x = 4;
- RandomRect.Sqr[2].y = 1;
- RandomRect.Sqr[3].x = 6;
- RandomRect.Sqr[3].y = 1;
- RandomRect.m_nColor = RGB(255, 0, 0);
- RandomRect.Type = 4;
- break;
- /*图形为{ |
- _ _ _
- }红色
- */
- case 5:
- RandomRect.Sqr[0].x = 5;
- RandomRect.Sqr[0].y = 0;
- RandomRect.Sqr[1].x = 4;
- RandomRect.Sqr[1].y = 1;
- RandomRect.Sqr[2].x = 3;
- RandomRect.Sqr[2].y = 1;
- RandomRect.Sqr[3].x = 5;
- RandomRect.Sqr[3].y = 1;
- RandomRect.m_nColor = RGB(0, 204, 255);
- RandomRect.Type = 5;
- break;
- /*图形为{ |
- _ _ _
- }天蓝
- */
- case 6:
- RandomRect.Sqr[0].x = 5;
- RandomRect.Sqr[0].y = 0;
- RandomRect.Sqr[1].x = 5;
- RandomRect.Sqr[1].y = 1;
- RandomRect.Sqr[2].x = 6;
- RandomRect.Sqr[2].y = 1;
- RandomRect.Sqr[3].x = 6;
- RandomRect.Sqr[3].y = 2;
- RandomRect.m_nColor = RGB(255, 204, 0);
- RandomRect.Type = 6;
- break;
- /*图形为{ |
- - -
- |
- }金色
- */
- }
- }
- /*void CELSView::OnPaint()
- {
- CPaintDC cdc(this); // device context for painting
- }*/
- void CELSView::InitGame()
- {
- //表格和相对应色彩表
- for (int i=0; i<10; i++)
- {
- for(int j=0; j<20; j++)
- {
- m_nCor[j][i] = -1; //表格数不可能为-1
- m_nCorcolor[j][i] = RGB(255,255,255);
- }
- }
- //图形初始化
- for (int k=0; k<4; k++)
- {
- RandomRect.Sqr[k].x = -1;
- RandomRect.Sqr[k].y = -1;
- NextRect.Sqr[k].x = -1;
- NextRect.Sqr[k].y = -1;
- OldRect.Sqr[k].x = -1;
- OldRect.Sqr[k].y = -1;
- CurrentRect.Sqr[k].x = -1;
- CurrentRect.Sqr[k].y = -1;
- }
- }
- void CELSView::DrawGame()
- {
- CDC *cDC=GetDC();
- CMemDC pDC(cDC);
- COLORREF clrRim = RGB(68, 71, 140); //每一个方块的色彩边框
- COLORREF clrMid = RGB(255,255,255); //每一个方块的色中间色彩,白色
- const UINT wide = 20; //方块的宽
- const UINT hight = 20; //方块的高
- const UINT StartX = 120; //起始绘表格处的位置
- CString lsStr1,lsStr2,lsStr3;
- lsStr1.Format("总分为:%d ",m_nCount);
- pDC.SetBkColor(RGB(22,22,22));
- pDC.SetTextColor(RGB(255,0,0));
- pDC .TextOut(0, 20,lsStr1);
- lsStr2.Format(" Level:%d",m_nLevel);
- pDC.TextOut(0, 50,lsStr2);
- lsStr2.Format("Time(ms):%d",m_nTime-m_nLevel*150);
- pDC.TextOut(0, 350,lsStr2);
- pDC.TextOut(0,120,"下一个方块:");
- int i,j;
- //把整个表格都绘一次,主游戏区域,包括已经在 底部的 和 空区域 两部分,所以改变以后不能画已经落下的方块了
- for (i=0; i<20; i++)
- {
- for (j=0; j<10; j++)
- {
- if (m_nCor[i][j] != -1)
- {
- pDC.FillSolidRect(StartX+j*20, i*20, wide, hight, m_nCorcolor[i][j]);
- pDC.Draw3dRect(StartX+j*20, i*20, wide, hight, clrRim, m_nCorcolor[i][j]);
- }
- else
- {
- pDC.FillSolidRect(StartX+j*20, i*20, wide, hight, clrMid);
- pDC.Draw3dRect(StartX+j*20, i*20, wide, hight, clrRim, clrMid);
- //continue;
- //return;
- }
- }
- }
- //绘制当前的正在操作的方块
- for (i=0; i<4; i++)
- {
- pDC.FillSolidRect(StartX+CurrentRect.Sqr[i].x*20, CurrentRect.Sqr[i].y*20, wide, hight, m_nCurrentColor);
- pDC.Draw3dRect(StartX+CurrentRect.Sqr[i].x*20, CurrentRect.Sqr[i].y*20, wide, hight, clrRim, m_nCurrentColor);
- }
- if ( true == m_current_next_exchange)
- {
- //提示下一方块 4*4方格的绘制,颜色会和初始化的时候冲突,
- for (int x=0; x<4; x++)
- {
- for (int j=0; j<4; j++)
- {
- pDC.FillSolidRect(20+j*20, 150+x*20, wide, hight, WHITE);
- pDC.Draw3dRect(20+j*20, 150+x*20, wide, hight, clrRim, WHITE);
- }
- }
- //绘制下一个提示方块
- for (i = 0; i<4; i++)
- {
- pDC.FillSolidRect(20+(NextRect.Sqr[i].x-3)*20, 150+NextRect.Sqr[i].y*20, wide, hight, m_nNextColor);
- pDC.Draw3dRect(20+(NextRect.Sqr[i].x-3)*20, 150+NextRect.Sqr[i].y*20, wide, hight, clrRim, m_nNextColor);
- }
- }
- }
- void CELSView::OnGameStart()
- {
- if (m_nFirstStart==true && m_nGamePause==false)
- {
- MakeRect();
- m_nFirstStart = false;
- }
- m_nGamePause = false;
- m_nGameOver = false;
- DrawGame();
- SetTimer(1,m_nTime-m_nLevel*150,NULL); //设置下落时间间隔
- }
- void CELSView::OnGamePause()
- {
- m_nGamePause =true;
- m_nGameOver =true;
- KillTimer(1);
- }
- void CELSView::OnGameEnd()
- {
- //m_nGameOver=true;
- //m_nGamePause = false; //清除游戏暂停状态
- KillTimer(1);
- InitGame(); //清除所有数据
- InitVariable();
- Invalidate();
- //PostQuitMessage(0);
- //AfxGetApp()->Exit();
- //CEApp::ExitInstance();
- //PostQuitMessage(0);
- //exit(0);
- /*if (MessageBox("确定要退出吗?","提示",MB_YESNO|MB_DEFBUTTON2)==IDYES)
- {
- PostQuitMessage(0);
- return;
- //SendMessage(WM_CLOSE); //各个菜单键没有用了
- }*/
- }
- void CELSView::OnTimer(UINT nIDEvent)
- {
- if(false==IsDropBottom())
- DropOneRow();
- else
- BottomOperation();
- //Invalidate();
- DrawGame();
- CView::OnTimer(nIDEvent);
- }
- void CELSView::MakeRect()
- {
- OnRandomRect(); //生成一个图形
- int i;
- //把生成图形拷贝给现在表格上要绘的图
- for (i= 0 ; i<4; i++)
- {
- CurrentRect.Sqr[i].x = RandomRect.Sqr[i].x;
- CurrentRect.Sqr[i].y = RandomRect.Sqr[i].y;
- }
- m_nRectType = RandomRect.Type;
- m_nCurrentColor = RandomRect.m_nColor;
- OnRandomRect(); //再生成一个图形
- //把生成图形拷贝给提示表格上要绘的图
- for (i= 0 ; i<4; i++)
- {
- NextRect.Sqr[i].x = RandomRect.Sqr[i].x;
- NextRect.Sqr[i].y = RandomRect.Sqr[i].y;
- }
- //m_nRectType = RandomRect.Type;
- m_nNextColor = RandomRect.m_nColor;
- }
- void CELSView::DropOneRow()
- {
- //图形改变
- SaveRect();
- //CDC *pDC=GetDC();
- //图形的四个方块都下降一行
- for (int i=0; i<4; i++)
- CurrentRect.Sqr[i].y++;
- //CRect rect(CurrentRect.Sqr.x+CurrentRect.Sqr.x*)
- }
- void CELSView::BottomOperation()
- {
- //到了底后要将图形拷贝到表格上去
- m_nDrawBeginRow = -1;
- for (int i=0; i<4; i++)
- {
- m_nCor[CurrentRect.Sqr[i].y][CurrentRect.Sqr[i].x] = 1; //将图形所在位置贴到表格上去
- m_nCorcolor[CurrentRect.Sqr[i].y][CurrentRect.Sqr[i].x] = m_nCurrentColor; //色彩拷贝上去
- if (m_nDrawBeginRow < CurrentRect.Sqr[i].y)
- {
- m_nDrawBeginRow = CurrentRect.Sqr[i].y; //找落下后的最下面一行位置
- }
- }
- //测试图形落到底后,可以消除几行(最多4行)
- for (i=m_nDrawBeginRow; i>m_nDrawBeginRow-4 && i>0; i--)
- {
- if (true == IsRowFull(i))
- {
- CleanOneRow(i);
- CleanTheRow++;
- i++;
- }
- }
- m_nCount+=CleanTheRow*CleanTheRow*100;
- CleanTheRow=0;
- if (m_nCount>(m_nLevel+1)*1000 && m_nLevel>=0 && m_nLevel<7)
- {
- m_nLevel++;
- KillTimer(1);
- SetTimer(1,m_nTime-m_nLevel*150,NULL);
- }
- if ( IsTableFull() == true )
- {
- //如果表格满,则退出游戏
- KillTimer(1); //结束游戏前停止计时
- //MessageBox("游戏结束"); //发送出游戏结束信息
- COKDlg dlg;
- dlg.DoModal();
- InitGame(); //清除所有数据
- InitVariable();
- Invalidate();
- }
- else
- {
- m_nRectType = RandomRect.Type; //记录当前图形的类型
- //提示图形给当前图形,随机生成的图形给提示图形
- OnRandomRect();
- for (int i=0; i<4; i++)
- {
- //提示图形给当前图形
- CurrentRect.Sqr[i].x = NextRect.Sqr[i].x;
- CurrentRect.Sqr[i].y = NextRect.Sqr[i].y;
- //记下提示图,因下次绘图时,要清除原有图形
- OldRect.Sqr[i].x = NextRect.Sqr[i].x;
- OldRect.Sqr[i].x = NextRect.Sqr[i].y;
- //随机生成的图形给提示图形
- NextRect.Sqr[i].x = RandomRect.Sqr[i].x;
- NextRect.Sqr[i].y = RandomRect.Sqr[i].y;
- }
- //现在色为提示色
- m_nCurrentColor = m_nNextColor;
- //提示色为随机色
- m_nNextColor = RandomRect.m_nColor;
- m_current_next_exchange = true; //因为交换了图形
- }
- }
- void CELSView::SaveRect()
- {
- //记原图形,在绘图时,如果不符合要求以便清除
- for (int k=0; k<4; k++)
- {
- OldRect.Sqr[k].x = CurrentRect.Sqr[k].x;
- OldRect.Sqr[k].y = CurrentRect.Sqr[k].y;
- }
- }
- bool CELSView::IsDropBottom()
- {
- for (int i=0; i<4; i++)
- {
- //表示图形下一行有数据(主要是方格的标志为1)或下一行为HIHG-1,表示到了底
- if (-1 != m_nCor[ CurrentRect.Sqr[i].y+1][ CurrentRect.Sqr[i].x] || (CurrentRect.Sqr[i].y >= 19) )
- {
- return true;
- }
- }
- return false; //测试完没到HIGH-1或是下一行没有数据表示没有到底
- }
- bool CELSView::IsRowFull(int Row)
- {
- for (int i=0; i<WIDTH; i++)
- {
- if (m_nCor[Row][i] == -1)
- {
- return false; //如果一行中有一个格子没有数据,表示行没满
- }
- }
- return true; //检测完一行那么表示满
- }
- bool CELSView::IsTableFull()
- {
- for (int i=0; i<WIDTH; i++)
- {
- if (m_nCor[0][i] != -1) //只要检测第一行就可以判断
- return true;
- }
- return false;
- }
- void CELSView::CleanOneRow(int Place)
- {
- bool moveData; //标志数移完没有
- m_nTableChangeFlag = true;
- //清除此行
- for (int k=0; k<10; k++ )
- {
- m_nCor[Place][k] = -1;
- m_nCorcolor[Place][k] = 0;
- }
- //向下移动数据
- for ( int i = Place; i>0; i--)
- {
- moveData = false;
- for (int j=0; j<10; j++)
- {
- if (m_nCor[i-1][j] != -1) //只有不是空的才会向下传递
- {
- moveData = true;
- //将上行数据拷贝下来
- m_nCor[i][j] = 1;
- m_nCorcolor[i][j] = m_nCorcolor[i-1][j];
- //将上一行数据清除
- m_nCor[i-1][j] = -1;
- m_nCorcolor[i-1][j] = 0;
- }
- }
- //如果有一行没有移动数据,表示上面的数据都不变;
- if (moveData == false)
- {
- break;
- }
- }
- }
- void CELSView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- if (m_nGamePause==false)
- {
- switch(nChar)
- {
- case VK_LEFT:
- {
- if (IsOutSide(LEFT) == false )//如果没有溢则图形左移一格
- {
- SaveRect();
- for (int i=0; i<4; i++)
- CurrentRect.Sqr[i].x--;
- }
- }
- break;
- case VK_RIGHT:
- {
- if (IsOutSide(RIGHT) == false )//如果没有溢则图形右移一格
- {
- SaveRect();
- for (int i=0; i<4; i++)
- CurrentRect.Sqr[i].x++;
- }
- }
- break;
- case VK_UP:
- {
- RoundRect();
- }
- break;
- case VK_DOWN:
- {
- DirectDropBottom();
- }
- break;
- }
- DrawGame();
- }
- CView::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- bool CELSView::IsOutSide(int dir)
- {
- //如果是右边,测试有没有出界
- if (dir == RIGHT)
- {
- for (int i=0; i<4; i++)
- {
- if ( CurrentRect.Sqr[i].x >= 9
- || (m_nCor[CurrentRect.Sqr[i].y][CurrentRect.Sqr[i].x+1] == 1))//右边方格以已经填充
- {
- return true; //如果下一次会超出,刚返回true
- }
- }
- }
- //如果是左边,测试有没有出界
- if (dir == LEFT)
- {
- for (int i=0; i<4; i++)
- {
- if (CurrentRect.Sqr[i].x <= 0
- || (m_nCor[CurrentRect.Sqr[i].y][CurrentRect.Sqr[i].x-1] == 1) )//左边方格已经填充
- {
- return true; //如果下一次会超出,刚返回true
- }
- }
- }
- return false;
- }
- void CELSView::RoundRect()
- {
- int tempx = 0, tempy = 0, index = 0;
- int rect_y = 0, rect_x = 0;
- //记忆原图形
- SaveRect();
- //判断图形的索引号
- if (m_nRectType != 0)
- {
- rect_x = CurrentRect.Sqr[1].x;
- rect_y = CurrentRect.Sqr[1].y;
- index = 1;
- }
- //根据index来判断哪些方块要移动,达到变形效果
- for (int i=0; i<4; i++)
- {
- if (i != index && m_nRectType != 0)
- {
- tempx = CurrentRect.Sqr[i].x - rect_x; //得到相对坐标x
- tempy = CurrentRect.Sqr[i].y - rect_y; //得到相对坐标y
- //逆时针旋转90°
- CurrentRect.Sqr[i].x = tempy + rect_x;
- CurrentRect.Sqr[i].y = -tempx + rect_y;
- if ( m_nCor[CurrentRect.Sqr[i].y][CurrentRect.Sqr[i].x] != -1
- || (CurrentRect.Sqr[i].x>9) || (CurrentRect.Sqr[i].x<0)
- || (CurrentRect.Sqr[i].y>19) || (CurrentRect.Sqr[i].y<0)
- )
- {
- //如果变形后图超出表格范围,则恢复原图形
- for (int j=0; j<4; j++)
- {
- CurrentRect.Sqr[j].y = OldRect.Sqr[j].y;
- CurrentRect.Sqr[j].x = OldRect.Sqr[j].x;
- }
- return;
- }
- }
- }
- return;
- }
- void CELSView::DirectDropBottom()
- {
- while ((m_nCor[CurrentRect.Sqr[0].y+1][CurrentRect.Sqr[0].x] == -1) && (CurrentRect.Sqr[0].y+1 < 20)
- && (m_nCor[CurrentRect.Sqr[1].y+1][CurrentRect.Sqr[1].x] == -1) && (CurrentRect.Sqr[1].y+1 < 20)
- && (m_nCor[CurrentRect.Sqr[2].y+1][CurrentRect.Sqr[2].x] == -1) && (CurrentRect.Sqr[2].y+1 < 20)
- && (m_nCor[CurrentRect.Sqr[3].y+1][CurrentRect.Sqr[3].x] == -1) && (CurrentRect.Sqr[3].y+1 < 20) )
- {
- for (int i=0; i<4; i++)
- {
- CurrentRect.Sqr[i].y++;
- }
- }
- DrawGame();
- //Invalidate();
- }
- void CELSView::OnPrepare()
- {
- /*CDC *cDC=GetDC();
- CMemDC pDC(cDC);
- CBrush *brush=new CBrush(RGB(22,22,22)); //改变背景的颜色,这里主要是黑色
- pDC->SelectObject(brush);
- CRect rect(0,0,500,500); //设置的背景的矩形区域
- GetClientRect(&rect);
- pDC->Rectangle(rect);
- InitGame(); //当窗口生成时就要初始化操作
- COLORREF clrRim = RGB(68, 71, 255); //每一个方块的色彩边框
- COLORREF clrMid = RGB(255,255,255); //每一个方块的色中间色彩,白色
- const UINT wide = 20; //方块的宽
- const UINT hight = 20; //方块的高
- const UINT StartX = 120; //起始绘表格处的位置
- //在离窗口(0,120)处 开始绘20*10个方格,作为游戏区域
- for (int x=0; x<20; x++)
- {
- for (int j=0; j<10; j++)
- {
- pDC->FillSolidRect(StartX+j*20, x*20, wide, hight, clrMid); //填充图形
- pDC->Draw3dRect(StartX+j*20, x*20, wide, hight, clrRim, clrMid); //画矩形
- }
- }
- //在(20,150)处,开始绘提示图的背景
- for (x=0; x<4; x++)
- {
- for (int j=0; j<4; j++)
- {
- pDC->FillSolidRect(20+j*20, 150+x*20, wide, hight, clrMid);
- pDC->Draw3dRect(20+j*20, 150+x*20, wide, hight, clrRim, clrMid);
- }
- }*/
- }
- void CELSView::OnUpdateGameStart(CCmdUI* pCmdUI)
- {
- if(m_nGamePause || m_nGameOver)
- pCmdUI->Enable(true);
- else
- pCmdUI->Enable(false);
- }
- void CELSView::OnUpdateGamePause(CCmdUI* pCmdUI)
- {
- if(!m_nGameOver)
- pCmdUI->Enable(true);
- else
- pCmdUI->Enable(false);
- }
- void CELSView::OnUpdateGameEnd(CCmdUI* pCmdUI)
- {
- if(m_nGameOver)
- pCmdUI->Enable(true);
- else
- pCmdUI->Enable(false);
- }
- void CELSView::InitVariable()
- {
- m_nCount = 0;
- m_current_next_exchange = true; //交换图形
- m_nGameOver = true; //缺省状态是结束的
- m_nGamePause = false; //缺省不是暂停
- m_nTableChangeFlag = false; //表格改变标志
- m_nFlag = false;
- m_nFirstStart = true; //第一次ture
- m_nTime = 1100; //时间间隔计数
- m_nDrawBeginRow = -1; //绘图开始位置
- m_nDrawEndRow = -1; //绘图结束位置
- m_nCurrentColor = 0;
- CleanTheRow = 0;
- m_nLevel = 0;
- m_nRectType = -1;
- }