⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 llkdlg.cpp

📁 一款很不错的evc下运行的游戏
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// llkDlg.cpp : implementation file
//

#include "stdafx.h"
#include "llk.h"
#include "llkDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CLlkDlg dialog

CLlkDlg::CLlkDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLlkDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLlkDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CLlkDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLlkDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CLlkDlg, CDialog)
	//{{AFX_MSG_MAP(CLlkDlg)
	ON_WM_PAINT()
	ON_WM_LBUTTONUP()
	ON_WM_TIMER()
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
	ON_WM_ERASEBKGND()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLlkDlg message handlers

BOOL CLlkDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
	::MoveWindow(this->m_hWnd,g_rect.left,g_rect.top,g_rect.Width(),
		g_rect.Height(),TRUE);
    
	this->SetWindowText(_T("llk"));

	CReg Reg_Language;//读语种键值
	HKEY hResult = NULL;
	Reg_Language.CreateKey(HKEY_CURRENT_USER,LanguagePath, hResult);
	m_nLanguage = Reg_Language.GetdWordValue(hResult,LanguageName);
    
	m_lHighPoint = 0;

	CFile file;
	file.Open(_T("\\record.txt"),CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite,NULL);
	file.Close();
    
	CFile read;
    read.Open(_T("\\record.txt"),CFile::modeRead,NULL);
    read.Read(&m_lHighPoint,sizeof(m_lHighPoint));
    read.Close();

    InitSysVar();
	SetInGame();
	SetLevel();
	StartGame();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

afx_msg BOOL CLlkDlg::OnEraseBkgnd(CDC* pDC)
{
	return TRUE;
}

void CLlkDlg::InitSysVar()//初始化变量
{
	m_bInGame = FALSE;
	m_bPause = FALSE;   
	m_bTip_ok = FALSE;
	m_bOvermusic = FALSE;

	m_bTip = false;
	m_bWash = false;
	m_bSel = false;
    m_bBox = false;

	m_nScore = 0;
	m_nUpper = 155.000; 
	m_nPos = 0.000;
    m_nSpeed = 1.292;

	m_nLevel = 1;
	m_nPrompt = 3;
	m_nShuffle = 3;
	m_nTotal = 42;
	m_nLeft = 42;
	m_strTop = ("");

	m_nTpos = 1;
    m_nTpos_x1 = 0;					
	m_nTpos_x2 = 0;
	m_nTpos_y1 = 0;
    m_nTpos_y2 = 0;

	m_nXIndex = -1;
	m_nYIndex = -1;
	m_bSecClk = FALSE;
	m_bMouse = false;
	m_bMessage = false;
	m_bSele_ok = false;
	m_nButton = 0;
	m_bEffect = true;
	m_nMin = 2;
	m_nSec1 = 0;
	m_nSec2 = 0;
	m_nPane_x = 0;
	m_nPane_y = 0;
	m_nMenu_y = 0;
	m_nPass = 0;
	m_lPoint = 0;
	m_nTimer = 0;
	m_nCycle = 8;

	InitMap();
    SetTimer(1, 1, NULL);
}

void CLlkDlg::OnPaint() 
{   
	CPaintDC dc(this);
    // device context for painting	
	// TODO: Add your message handler code here
	DrawFace(&dc);
	dc.DeleteDC();
	// Do not call CDialog::OnPaint() for painting messages
}

void CLlkDlg::DrawFace(CDC *pDC)//绘主位图
{
	CBitmap bmp;
	GetBmp(&bmp);

	CDC memDC;
	memDC.CreateCompatibleDC(pDC);
	memDC.SelectObject(&bmp);
	pDC->BitBlt(g_rect.left, g_rect.top, g_rect.Width(), g_rect.Height(), &memDC, 0, 0, SRCCOPY);
	
	memDC.DeleteDC();
	bmp.DeleteObject();	
}

void CLlkDlg::GetBmp(CBitmap *pbmpDst)//获取内存位图
{
	CDC memDC;
	memDC.CreateCompatibleDC(NULL);
	CBitmap mainbmp;
	mainbmp.LoadBitmap(IDB_BACK);
	memDC.SelectObject(&mainbmp);

	CDC MyDC;
	CBitmap MyBmp;
	MyDC.CreateCompatibleDC(&memDC);
	MyBmp.CreateCompatibleBitmap(&memDC,g_rect.Width(),g_rect.Height());
	MyDC.SelectObject(&MyBmp);

	MyDC.BitBlt(g_rect.left,g_rect.top,g_rect.Width(),
		g_rect.Height(),&memDC,0,0,SRCCOPY);

	CString str1, str2, str3;
	str1.Format(_T("%d"), m_nMin);
	str2.Format(_T("%d"), m_nSec1);
	str3.Format(_T("%d"), m_nSec2);

	DrawMap(&MyDC);
	DrawMessage(&MyDC);
	DrawTime(&MyDC,str1, str2, str3);
    SelButton(&MyDC);
	WashButton(&MyDC);
	TipButton(&MyDC);
	DrawMenu(&MyDC);
	ShowTop(&MyDC);
	NextLEVEL(&MyDC);	

	CopyBackground(&MyDC,g_rect.left,g_rect.top,g_rect.Width(),g_rect.Height(),pbmpDst);

	MyDC.DeleteDC();
	memDC.DeleteDC();
	MyBmp.DeleteObject();
	mainbmp.DeleteObject();
}

void CLlkDlg::CopyBackground(CDC *pDC, int nXSrc, int nYSrc, int nWidth,int nHeight, CBitmap *pBmDst)
{	
	pBmDst->DeleteObject();
	pBmDst->CreateCompatibleBitmap( pDC, nWidth, nHeight );

	CDC memDC;
	memDC.CreateCompatibleDC( pDC );
	CBitmap *pBmTmp = memDC.SelectObject( pBmDst );
	memDC.BitBlt( 0, 0, nWidth, nHeight, pDC, nXSrc, nYSrc, SRCCOPY );

	memDC.SelectObject( pBmTmp );
	memDC.DeleteDC();
	pBmTmp->DeleteObject();
}

void CLlkDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{	
 	// TODO: Add your message handler code here and/or call default
    m_bMouse = true;											//使用鼠标,绘图中消去选择框
 	int iTop, iLeft, iRight, iBottom;
 	CRect  rect;
 	
 	iTop = DRAW_TOP + BMP_HEIGHT;								//图片区域坐标
 	iBottom = iTop + BMP_HEIGHT * ROW_NUMBER;
    iLeft = DRAW_LEFT + BMP_WIDTH;  
 	iRight = iLeft + BMP_WIDTH * LINE_NUMBER;        
 
 	if (!m_bSele_ok && point.x>418 && point.x<466               //鼠标按下"选项"按扭
 		&& point.y>18 && point.y<43 && m_nPass == 0)
	{  
	   m_nButton = 0;
       m_bSel = true;
       m_bSele_ok = true;
	   SetPause();

	   CDC *pDC = GetDC();
       SelButton(pDC);
	   pDC->DeleteDC();
 	}
 	if (!m_bSele_ok && point.x>298 && point.x<346               //鼠标按下"提示"按扭
 		&& point.y>18 && point.y<43 && m_nPass == 0)
 	{	
 		if (m_nPrompt > 0)
        { 
			m_nButton = 0;
			m_bTip = true;

			if (m_bEffect)
			{
				PlaySound (TEXT("\\NAND\\llk(sound)\\TIP.wav"), NULL, SND_ASYNC | SND_NODEFAULT);  
			}

 			OnOptionPrompt();
			CDC *pDC = GetDC();
            TipButton(pDC);
	        pDC->DeleteDC();
		
 		}
 	}
 	if (!m_bSele_ok && point.x>358 && point.x<406               //鼠标按下"洗牌"按扭
 		&&point.y>18 && point.y<43 && m_nPass==0)
 	{ 		
 		if (m_nShuffle > 0)
		{  
			m_nButton = 0;
			m_bWash = true;	

        	OnOptionShuffle();

			CDC *pDC = GetDC();
			WashButton(pDC);
			pDC->DeleteDC();
			
			if(m_bEffect)
 				PlaySound (TEXT("\\NAND\\llk(sound)\\SHUFF.wav"), NULL, SND_ASYNC | SND_NODEFAULT);	
 		}
 	}    
 	if (GetInGame() && !m_bSele_ok && point.x > iLeft &&                       //鼠标点击图片区域
 		point.x < iRight && point.y > iTop && point.y < iBottom && m_nPass==0)
 	{   	
      	int tempx, tempy;  
 		int xtempindex, ytempindex;
 
 	  	tempy = (point.x+64) / BMP_WIDTH;                         //将鼠标坐标将化为所对应数组坐标
 	  	tempx = (point.y+10) / BMP_HEIGHT;
 		xtempindex = tempx - 1;
        ytempindex = tempy - 2;
 
 		if (GetPicIndex(xtempindex, ytempindex) > 0)
 		{
 			if (m_bSecClk)
 			{	        
 		    	if ((xtempindex == m_nXIndex) && (ytempindex == m_nYIndex))
 				{
 					UpdateClkState(m_nXIndex, m_nYIndex, LS_NOCLK);	
 				}
 		     	else
 				{
			     	if (GetPicIndex(xtempindex, ytempindex) == GetPicIndex(m_nXIndex, m_nYIndex))
 					{         
 			      		
 						if (CheckConn(m_nXIndex, m_nYIndex, xtempindex, ytempindex))  
 						{	
 							UpdateLeft(1);
 							UpdateScore(100);
					        m_nTpos = 1;
 							if (m_bEffect)
							{
								PlaySound (TEXT("\\NAND\\llk(sound)\\OK.wav"), NULL, SND_ASYNC | SND_NODEFAULT);
							}
 					    	ReleasePicPlace(m_nXIndex, m_nYIndex);
                          	ReleasePicPlace(xtempindex, ytempindex);
                               
 							int nEvent1 = GetValue(xtempindex, ytempindex);
 							int nEvent2 = GetValue(m_nXIndex, m_nYIndex);
 							
 							if((nEvent1 & LS_PROMPT) == LS_PROMPT || (nEvent2 & LS_PROMPT) == LS_PROMPT)
 							{
								UpdatePrompt(1);
 								if (m_nLanguage == 0)
 								m_strTop = _T("Award tip+1");
 								if (m_nLanguage == 1)
 								m_strTop = _T("奖励:提示1次");
								if (m_bEffect)
								{
									PlaySound (TEXT("\\NAND\\llk(sound)\\AWARD.wav"), NULL, SND_ASYNC | SND_NODEFAULT);  
								}
 							}
							else if ((nEvent1 & LS_SHUFFLE) == LS_SHUFFLE || (nEvent2 & LS_SHUFFLE) == LS_SHUFFLE)
 							{
 								UpdateShuffle(1);
 								if (m_nLanguage == 0)
 								m_strTop =_T("Award shuffle+1");
 								if (m_nLanguage == 1)
                                m_strTop =_T("奖励:洗牌1次");
								if (m_bEffect)
								{
									PlaySound (TEXT("\\NAND\\llk(sound)\\AWARD.wav"), NULL, SND_ASYNC | SND_NODEFAULT);  
								}
 							}
 							else if ((nEvent1 & LS_SCORE) == LS_SCORE || (nEvent2 & LS_SCORE) == LS_SCORE)
 							{
 								UpdateScore(100);
 								if (m_nLanguage == 0)
 								m_strTop =_T("Award 100 points");
 								if (m_nLanguage == 1)
 								m_strTop =_T("奖励:100 分");
								if (m_bEffect)
								{
									PlaySound (TEXT("\\NAND\\llk(sound)\\AWARD.wav"), NULL, SND_ASYNC | SND_NODEFAULT);  
								}
 							}				
 							SetValue(xtempindex, ytempindex, LS_NONE);
 							SetValue(m_nXIndex, m_nYIndex, LS_NONE);
 
 							MovePic(m_nXIndex, m_nYIndex, xtempindex, ytempindex);
 							
 						}
 				    	else  
 						{
 							UpdateClkState(m_nXIndex, m_nYIndex, LS_NOCLK);
                      
 						}
 					}
 				    else	
					{
 						UpdateClkState(m_nXIndex,  m_nYIndex, LS_NOCLK);
 						
 					}
 
 				}
 
 				m_nXIndex = -1;
 		    	m_nYIndex = -1;
 			
			}
 		    else
 			{
 
 				UpdateClkState(xtempindex, ytempindex, LS_CLICK);
		     	m_nXIndex = xtempindex;
 		    	m_nYIndex = ytempindex;
 			}
 	
 		}
 
 		if (GetPicIndex(xtempindex, ytempindex) <= 0 && m_bSecClk)    //当第二次点击空白处时,使第一次点击图片还原
 		{
             UpdateClkState(m_nXIndex, m_nYIndex, LS_NOCLK);
 		}
 		
 		if (IsPicEmpty())                                      
 		{  
			 if (m_bEffect)
 		    	PlaySound (TEXT("\\NAND\\llk(sound)\\PASS.wav"), NULL, SND_ASYNC | SND_NODEFAULT); 

 			int	nLevel = GetLevel();
 			int nLeftTime = (int)(GetUpper() - GetPos());

			SetPause();
 
 			if (nLevel < 15)
 			{   
 				UpdateScore((nLevel * (nLevel - 1) + 1) * 5 + nLeftTime);
 				if (m_nLanguage == 0)
 				m_strBox = _T("GO TO NEXT LEVEL!");	
 				if (m_nLanguage == 1)
 				m_strBox = _T("进入下一关!");
 				m_nPass = 1;
 			    if (m_nScore > m_lHighPoint)
                WriteFile();
  			}
 			else
			{   
 				if (m_nLanguage == 0)						
 				m_strBox = _T("PASS ALL LEVEL!");
 			    if (m_nLanguage == 1)
 				m_strBox = _T("全部过关!");
 		        m_nPass = 2;
				SetInGame(FALSE);
 				if (m_nScore > m_lHighPoint)
                WriteFile();
 			}
 			m_bMessage = true; 
 		}
 		m_bSecClk = !m_bSecClk;
 	}
 	
 	if (m_bSele_ok && point.x>146 && point.x<274)          //鼠标选择菜单
 	{
		if (point.y>84 && point.y<109)                     //选择"重新开始"
		{   
			if (m_nScore > m_lHighPoint)
			WriteFile();
 			OnGameAbandon(); 
			InitSysVar();
 			SetInGame();
         	SetLevel();
 	        StartGame();
 		    m_bSele_ok = false;
 		 }
 		 if (point.y>109 && point.y<134)                   //选择"最高纪录"
 		 {  
 			m_nPass = 5;	
            ReadFile();
 			m_bMessage = true;
 		    m_bSele_ok = false;
		 }                                                  
 		 if (point.y>134 && point.y<159)				   //选择"返回游戏"
 		 {
 		   m_bSele_ok = false;
		   if (GetInGame())
		   SetPause(false);
 		 }
 		 if (point.y>159&&point.y<184)                     //选择"音乐(开/关)"
 		 {
 		   m_bEffect = !m_bEffect;
 		   m_bSele_ok = false;
		   if (GetInGame())
		   SetPause(false);
	     }
 		 if (point.y>184 && point.y<210)                   //选择"退出游戏"
 		 {	
 			if (m_nScore > m_lHighPoint)
              WriteFile();
 			PostQuitMessage(0);
         }
 	}		
 	if (m_nPass && point.x>182 && point.x<230 && point.y>148 && point.y<173)  //鼠标按下对话框的"确定"按扭
	{                       
 		if (m_nPass == 1)
 		   m_bBox = true;
 		if (m_nPass == 2)
 		   m_bBox = true;
 		if (m_nPass == 5)
 		   m_bBox = true;
		CDC *pDC = GetDC();
		NextLEVEL(pDC);
		pDC->DeleteDC();
 	}
 	CDialog::OnLButtonDown(nFlags, point);
}

void CLlkDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	   m_bTip = false;
	   m_bWash = false;
       m_bSel = false;
    if (m_nPass && point.x>182 && point.x<230 && point.y>148 && point.y<173) //鼠标松开对话框的"确定"按扭
	{
		if (m_nPass == 1)                        //"过关"对话框
		{
			GoToNextLevel();
		}  
		if (m_nPass == 2)						 //"全部过关"对话框
		{
		 	m_bSele_ok = true;
		}
		if (m_nPass == 5)                        //"纪录"对话框
		{
            m_nPass = 0;
			m_bMessage = false;
			if (GetInGame())
            SetPause(false);
		}
		m_bBox = false;
		m_nPass = 0;
		m_bMessage = false;
	}
	CDialog::OnLButtonUp(nFlags, point);
}

void CLlkDlg::DrawMap(CDC *pDC)                   //绘游戏区域位图
{  
	CDC FaceDC;
	FaceDC.CreateCompatibleDC(pDC);
	CBitmap facebmp;
	facebmp.LoadBitmap(IDB_FACE);
	FaceDC.SelectObject(&facebmp);	

	CDC HeadDC;
	HeadDC.CreateCompatibleDC(pDC);
	CBitmap headbmp;
	headbmp.LoadBitmap(IDB_HEAD);
	HeadDC.SelectObject(&headbmp);

	int i, j;
	for (i = 1; i <= ROW_NUMBER; i++)
	{
		for (j = 1; j <= LINE_NUMBER; j++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -