📄 zllkview.cpp
字号:
// ZLLKView.cpp : implementation of the CZLLKView class
//
/*
Made by zhouyuhui in 2005.8.25
mail: xuchangyuhui@sohu.com
It was made for my girl friend.
Thank for your download.
2006.09.09
*/
#include "stdafx.h"
#include "ZLLK.h"
#include "ZLLKDoc.h"
#include "ZLLKView.h"
#include "RecordDlg.h"
#include "AddDlg.h"
#include "mmsystem.h"//声音效果
#pragma comment(lib,"WINMM.LIB")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define tilex(y) y*BMP_WIDTH+DRAW_LEFT
#define tiley(x) x*BMP_HEIGHT+DRAW_TOP
extern int g_userlevel;
extern int g_usergate;
extern int g_userscore;
DWORD oldtime=0,newtime; //用来判断连击
/////////////////////////////////////////////////////////////////////////////
// CZLLKView
IMPLEMENT_DYNCREATE(CZLLKView, CView)
BEGIN_MESSAGE_MAP(CZLLKView, CView)
//{{AFX_MSG_MAP(CZLLKView)
ON_COMMAND(ID_MENU_SCORE, OnMenuScore)
ON_COMMAND(ID_MENU_FIRST, OnMenuFirst)
ON_UPDATE_COMMAND_UI(ID_MENU_FIRST, OnUpdateMenuFirst)
ON_COMMAND(ID_MENU_BACK, OnMenuBack)
ON_UPDATE_COMMAND_UI(ID_MENU_BACK, OnUpdateMenuBack)
ON_COMMAND(ID_MENU_EXIT, OnMenuExit)
ON_WM_KEYDOWN()
ON_WM_LBUTTONDOWN()
ON_COMMAND(ID_MENU_INFO, OnMenuInfo)
ON_UPDATE_COMMAND_UI(ID_MENU_INFO, OnUpdateMenuInfo)
ON_COMMAND(ID_MENU_SORT, OnMenuSort)
ON_UPDATE_COMMAND_UI(ID_MENU_SORT, OnUpdateMenuSort)
ON_COMMAND(ID_MENU_STOP, OnMenuStop)
ON_UPDATE_COMMAND_UI(ID_MENU_STOP, OnUpdateMenuStop)
ON_COMMAND(ID_MENU_EFFECT, OnMenuEffect)
ON_UPDATE_COMMAND_UI(ID_MENU_EFFECT, OnUpdateMenuEffect)
ON_COMMAND(ID_MENU_MUSIC, OnMenuMusic)
ON_UPDATE_COMMAND_UI(ID_MENU_MUSIC, OnUpdateMenuMusic)
ON_WM_TIMER()
ON_COMMAND(ID_MENU_HELP, OnMenuHelp)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CZLLKView construction/destruction
CZLLKView::CZLLKView()
{
// TODO: add construction code here
InitMap();
bingame=false; //没有进入游戏
//是否第二次点击
bSecondClicked=false;
//初级
bfirst=false;
bstop=false;
bmusic=true;
//图片坐标
xindex=-1;
yindex=-1;
//初始化有声音
bsoundeffect=true;
//提示次数初始化
m_tishinumber=10;
m_sortnumber=5;
m_dotNumber=0;
}
CZLLKView::~CZLLKView()
{
}
BOOL CZLLKView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
bitmap1.LoadBitmap(IDB_BITMAP_FOREFACE);
bitmap2.LoadBitmap(IDB_BITMAP_FACE);
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CZLLKView drawing
void CZLLKView::OnDraw(CDC* pDC)
{
CZLLKDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
// 渲染客户去
CRect rcBlock;
rcBlock.SetRect(0,0,660,640);
pDC->FillSolidRect(&rcBlock,RGB(100,100,200));
CDC dcMemory1,dcMemory2;
dcMemory1.CreateCompatibleDC(pDC);
dcMemory1.SelectObject(&bitmap1);
dcMemory2.CreateCompatibleDC(pDC);
dcMemory2.SelectObject(&bitmap2);
//输出图形
int i,j;
for(i=1;i<=ROW_NUMBER;i++)
{
for(j=1; j<=LINE_NUMBER;j++)
{
if(llk_map[i][j].PicIndex>0)
{
if(llk_map[i][j].state==0)
pDC->BitBlt(tilex(j),tiley(i),
PIC_WIDTH,PIC_HEIGHT,&dcMemory1,PIC_WIDTH*(llk_map[i][j].PicIndex-1),0 ,SRCCOPY);
else if(llk_map[i][j].state==1)
pDC->BitBlt(tilex(j),tiley(i),
PIC_WIDTH,PIC_HEIGHT,&dcMemory2,PIC_WIDTH*(llk_map[i][j].PicIndex-1),0 ,SRCCOPY);
}
}
}
if(bfirst)
{
DrawRectangleHollow();
DrawInfo(120,20,"剩余时间");
DrawInfo(20,20,"级别:");
DrawInfo(20,40,"关卡:");
DrawInfo(20,60,"重列:");
DrawInfo(20,80,"提示:");
DrawInfo(540,20,"分数:");
DrawInfo2(60,20,g_userlevel);
DrawInfo2(60,40,g_usergate);
DrawInfo2(60,60,m_sortnumber);
DrawInfo2(60,80,m_tishinumber);
DrawInfo2(560,40,g_userscore);
}
}
/////////////////////////////////////////////////////////////////////////////
// CZLLKView printing
BOOL CZLLKView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CZLLKView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CZLLKView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CZLLKView diagnostics
#ifdef _DEBUG
void CZLLKView::AssertValid() const
{
CView::AssertValid();
}
void CZLLKView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CZLLKDoc* CZLLKView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CZLLKDoc)));
return (CZLLKDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CZLLKView message handlers
void CZLLKView::OnMenuScore()
{
// TODO: Add your command handler code here
CRecordDlg recorddlg;
recorddlg.DoModal();
}
void CZLLKView::InitMap()
{
int i,j;
for(i=0;i<VIRTUAL_ROW;i++)
for(j=0;j<VIRTUAL_LINE;j++)
{
llk_map[i][j].PicIndex=0;
llk_map[i][j].state=0;
llk_map[i][j].event=0;
}
//
for(i=0;i<15;i++)
{
pic_number[i]=0;
pic_place[i+1]=NULL;
}
}
void CZLLKView::InitEvent()
{
int i,x=0,y=0,tempx,tempy;
int randevent,randplace;
for(i=0;i<5;i++) //总共5次事件
{
//随机计算 位置
randplace=rand()%(ROW_NUMBER*LINE_NUMBER)+1;
tempy=randplace%LINE_NUMBER;
tempx=randplace/LINE_NUMBER;
if(tempx!=x&&tempy!=y)
{
x=tempx; y=tempy;
//随机事件
randevent=rand()%3+1; //4为 事件总数
llk_map[tempx][tempy].event=randevent;
}
}
}
void CZLLKView::OnMenuFirst()
{
// TODO: Add your command handler code here
int i,j;
int temprand;
CString str;
CRect rect;
//产生随机序列 (但是做得随机性不好)
srand((unsigned)time(NULL));
for(i=1;i<=ROW_NUMBER;i++)
for(j=1;j<=LINE_NUMBER;j++)
{
while(1)
{
temprand=rand()%15; // 产生0-14的随机数
if(pic_number[temprand]<6)
{
pic_number[temprand]++;
llk_map[i][j].state=0;
llk_map[i][j].event=0;
llk_map[i][j].PicIndex=temprand+1; // 1-15
break;
}
}
}
//列出每幅图片所有的位置
ListPicPlace();
//初始化事件
InitEvent();
g_userscore=0;
g_userlevel=1;
g_usergate=1;
//程序控制
bingame=true;
bfirst=true;
DrawRectangleHollow();
m_nUpper=0;
DrawProgress(m_nUpper); // 总共400个时间
m_nSpeed=2;
SetTimer(1,1200,0);
DrawInfo(120,20,"剩余时间");
DrawInfo(20,20,"级别:");
DrawInfo(20,40,"关卡:");
DrawInfo(20,60,"重列:");
DrawInfo(20,80,"提示:");
DrawInfo(540,20,"分数:");
DrawInfo2(60,20,g_userlevel);
DrawInfo2(60,40,g_usergate);
DrawInfo2(60,60,m_sortnumber);
DrawInfo2(60,80,m_tishinumber);
DrawInfo2(560,40,g_userscore);
DrawMap();
//音效
//if(m_soundeffect)
// PlaySound(MAKEINTRESOURCE(IDR_WAVE_NEWGAME),AfxGetResourceHandle(),SND_RESOURCE|SND_ASYNC);
}
void CZLLKView::DrawMap()
{
//输出图形
CDC *pDc;
pDc=GetDC();
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDc);
dcMemory.SelectObject(&bitmap1);
int i,j;
for(i=1;i<=ROW_NUMBER;i++)
{
for(j=1; j<=LINE_NUMBER;j++)
{
if(llk_map[i][j].PicIndex>0)
{
if(llk_map[i][j].state==0)
pDc->BitBlt(tilex(j),tiley(i),
PIC_WIDTH,PIC_HEIGHT,&dcMemory,PIC_WIDTH*(llk_map[i][j].PicIndex-1),0 ,SRCCOPY);
}
}
}
}
void CZLLKView::DrawBlank()
{
CDC *pDc;
pDc=GetDC();
// 渲染客户去
CRect rcBlock;
rcBlock.SetRect(0,0,660,640);
pDc->FillSolidRect(&rcBlock,RGB(100,100,200));
}
void CZLLKView::DrawFace(int xindex,int yindex,int PicIndex,int state)
{
CDC *pDc;
pDc=GetDC();
CDC dcMemory1,dcMemory2;
if(state)
{
dcMemory2.CreateCompatibleDC(pDc);
dcMemory2.SelectObject(&bitmap2);
pDc->BitBlt(tilex(yindex),tiley(xindex),PIC_WIDTH-4,PIC_HEIGHT-4,&dcMemory2,PIC_WIDTH*(PicIndex-1),0,SRCCOPY);
}
else
{
dcMemory1.CreateCompatibleDC(pDc);
dcMemory1.SelectObject(&bitmap1);
pDc->BitBlt(tilex(yindex),tiley(xindex),PIC_WIDTH-4,PIC_HEIGHT-4,&dcMemory1,PIC_WIDTH*(PicIndex-1),0,SRCCOPY);
}
}
void CZLLKView::DrawFaceBlank(int xindex,int yindex)
{
CDC *pDc;
pDc=GetDC();
CRect rect;
if(xindex==9||yindex==10)
{
rect.top=tiley(xindex); rect.bottom=rect.top+PIC_HEIGHT;
rect.left=tilex(yindex); rect.right=rect.left+PIC_WIDTH;
pDc->FillSolidRect(&rect,RGB(100,100,200));
}
else
{
rect.top=tiley(xindex); rect.bottom=rect.top+PIC_HEIGHT-4;
rect.left=tilex(yindex); rect.right=rect.left+PIC_WIDTH-4;
pDc->FillSolidRect(&rect,RGB(100,100,200));
}
}
void CZLLKView::OnUpdateMenuFirst(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(bfirst)
pCmdUI->Enable(false);
else pCmdUI->Enable(true);
}
void CZLLKView::OnMenuBack()
{
// TODO: Add your command handler code here
KillTimer(1);
bingame=false;
bfirst=false;
bSecondClicked=false;
bstop=false;
m_dotNumber=0;
m_tishinumber=10;
m_sortnumber=5;
//图片坐标
xindex=-1;
yindex=-1;
InitMap();
DrawBlank();
}
void CZLLKView::OnUpdateMenuBack(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(bfirst)
pCmdUI->Enable(true);
else pCmdUI->Enable(false);
}
void CZLLKView::OnMenuExit()
{
// TODO: Add your command handler code here
PostQuitMessage(0);
}
void CZLLKView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
switch(nChar) {
case VK_F2:
OnMenuFirst();
break;
case VK_F5:
OnMenuInfo();
break;
case VK_F6:
OnMenuSort();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -